1 #ifndef __SPI_FLASH_H
2 #define __SPI_FLASH_H
3 
4 #include "stm32f10x.h"
5 
6 #define SPI_FLASH_SPI                           SPI1
7 #define SPI_FLASH_SPI_CLK                       RCC_APB2Periph_SPI1
8 #define SPI_FLASH_SPI_SCK_PIN                   GPIO_Pin_5                  /* PA.05 */
9 #define SPI_FLASH_SPI_SCK_GPIO_PORT             GPIOA                       /* GPIOA */
10 #define SPI_FLASH_SPI_SCK_GPIO_CLK              RCC_APB2Periph_GPIOA
11 #define SPI_FLASH_SPI_MISO_PIN                  GPIO_Pin_6                  /* PA.06 */
12 #define SPI_FLASH_SPI_MISO_GPIO_PORT            GPIOA                       /* GPIOA */
13 #define SPI_FLASH_SPI_MISO_GPIO_CLK             RCC_APB2Periph_GPIOA
14 #define SPI_FLASH_SPI_MOSI_PIN                  GPIO_Pin_7                  /* PA.07 */
15 #define SPI_FLASH_SPI_MOSI_GPIO_PORT            GPIOA                       /* GPIOA */
16 #define SPI_FLASH_SPI_MOSI_GPIO_CLK             RCC_APB2Periph_GPIOA
17 #define SPI_FLASH_CS_PIN                        GPIO_Pin_4                  /* PC.04 */
18 #define SPI_FLASH_CS_GPIO_PORT                  GPIOA                       /* GPIOC */
19 #define SPI_FLASH_CS_GPIO_CLK                   RCC_APB2Periph_GPIOA
20 
21 
22 #define SPI_FLASH_CS_LOW()       GPIO_ResetBits(GPIOA, GPIO_Pin_4)
23 #define SPI_FLASH_CS_HIGH()      GPIO_SetBits(GPIOA, GPIO_Pin_4)
24 
25 
26 void SPI_FLASH_Init(void);
27 void SPI_FLASH_SectorErase(u32 SectorAddr);
28 void SPI_FLASH_BulkErase(void);
29 void SPI_FLASH_PageWrite(u8* pBuffer, u32 WriteAddr, u16 NumByteToWrite);
30 void SPI_FLASH_BufferWrite(u8* pBuffer, u32 WriteAddr, u16 NumByteToWrite);
31 void SPI_FLASH_BufferRead(u8* pBuffer, u32 ReadAddr, u16 NumByteToRead);
32 u32 SPI_FLASH_ReadID(void);
33 u32 SPI_FLASH_ReadDeviceID(void);
34 void SPI_FLASH_StartReadSequence(u32 ReadAddr);
35 void SPI_Flash_PowerDown(void);
36 void SPI_Flash_WAKEUP(void);
37 
38 
39 u8 SPI_FLASH_ReadByte(void);
40 u8 SPI_FLASH_SendByte(u8 byte);
41 u16 SPI_FLASH_SendHalfWord(u16 HalfWord);
42 void SPI_FLASH_WriteEnable(void);
43 void SPI_FLASH_WaitForWriteEnd(void);
44 
45 #endif /* __SPI_FLASH_H */
46 
47