comparison flash.c @ 8:58d76cf522ff

Split out code into separate files.
author Daniel O'Connor <darius@dons.net.au>
date Sat, 04 Feb 2012 13:29:31 +1030
parents
children bd8e2cf04034
comparison
equal deleted inserted replaced
7:9404b9869c27 8:58d76cf522ff
1 #include <stdint.h>
2
3 #include "stm32f10x.h"
4 #include "spi.h"
5 #include "flash.h"
6
7 #define FL_SELECT() GPIO_ResetBits(GPIOA, GPIO_Pin_4)
8 #define FL_DESELECT() GPIO_SetBits(GPIOA, GPIO_Pin_4)
9
10 uint16_t
11 flashreadid(void) {
12 uint8_t fac, dev;
13
14 FL_SELECT(); /* Select device */
15
16 SPI_WriteByte(FL_RDID); /* Send command */
17 SPI_WriteByte(0x00); /* Send address cycles (ID data starts at 0) */
18 SPI_WriteByte(0x00);
19 SPI_WriteByte(0x00);
20 fac = SPI_WriteByte(0x00); /* Read ID */
21 dev = SPI_WriteByte(0x00);
22
23 FL_DESELECT(); /* De-select device */
24
25 return fac << 8 | dev;
26 }
27
28 uint8_t
29 flashreadstatus(void) {
30 uint8_t status;
31
32 FL_SELECT(); /* Select device */
33
34 SPI_WriteByte(FL_RDSR); /* Send command */
35 SPI_WriteByte(0x00); /* Send dummy byte for address cycle */
36 status = SPI_WriteByte(0x00); /* Read status */
37
38 FL_DESELECT(); /* De-select device */
39
40 return status;
41 }
42
43 void
44 flashwritestatus(uint8_t status) {
45 /* Enable status write */
46 FL_SELECT(); /* Select device */
47 SPI_WriteByte(FL_EWSR); /* Send command */
48 SPI_WriteByte(0x00); /* Send data byte */
49 FL_DESELECT();
50
51 /* Actually write status */
52 FL_SELECT(); /* Re-select device for new command */
53 SPI_WriteByte(FL_WRSR); /* Send command */
54 SPI_WriteByte(status); /* Send data byte */
55 FL_DESELECT(); /* De-select device */
56 }
57