stm32_eval_spi_flash.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /**
  2. ******************************************************************************
  3. * @file stm32_eval_spi_flash.h
  4. * @author MCD Application Team
  5. * @version V4.5.0
  6. * @date 07-March-2011
  7. * @brief This file contains all the functions prototypes for the stm32_eval_spi_flash
  8. * firmware driver.
  9. ******************************************************************************
  10. * @attention
  11. *
  12. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  13. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  14. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  15. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  16. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  17. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  18. *
  19. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  20. ******************************************************************************
  21. */
  22. /* Define to prevent recursive inclusion -------------------------------------*/
  23. #ifndef __STM32_EVAL_SPI_FLASH_H
  24. #define __STM32_EVAL_SPI_FLASH_H
  25. #include <stdint.h>
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. /* Includes ------------------------------------------------------------------*/
  30. /** @addtogroup Utilities
  31. * @{
  32. */
  33. /** @addtogroup STM32_EVAL
  34. * @{
  35. */
  36. /** @addtogroup Common
  37. * @{
  38. */
  39. /** @addtogroup STM32_EVAL_SPI_FLASH
  40. * @{
  41. */
  42. /** @defgroup STM32_EVAL_SPI_FLASH_Exported_Types
  43. * @{
  44. */
  45. /**
  46. * @}
  47. */
  48. /** @defgroup STM32_EVAL_SPI_FLASH_Exported_Constants
  49. * @{
  50. */
  51. /**
  52. * @brief M25P FLASH SPI Interface pins
  53. */
  54. #define sFLASH_CS_PIN GPIO_Pin_4 /* PA.04 */
  55. #define sFLASH_CS_GPIO_PORT GPIOA /* GPIOA */
  56. #define sFLASH_CS_GPIO_CLK RCC_APB2Periph_GPIOA
  57. #define sFLASH_SPI SPI1
  58. #define sFLASH_SPI_CLK RCC_APB2Periph_SPI1
  59. #define sFLASH_SPI_SCK_PIN GPIO_Pin_5 /* PA.05 */
  60. #define sFLASH_SPI_SCK_GPIO_PORT GPIOA /* GPIOA */
  61. #define sFLASH_SPI_SCK_GPIO_CLK RCC_APB2Periph_GPIOA
  62. #define sFLASH_SPI_MISO_PIN GPIO_Pin_6 /* PA.06 */
  63. #define sFLASH_SPI_MISO_GPIO_PORT GPIOA /* GPIOA */
  64. #define sFLASH_SPI_MISO_GPIO_CLK RCC_APB2Periph_GPIOA
  65. #define sFLASH_SPI_MOSI_PIN GPIO_Pin_7 /* PA.07 */
  66. #define sFLASH_SPI_MOSI_GPIO_PORT GPIOA /* GPIOA */
  67. #define sFLASH_SPI_MOSI_GPIO_CLK RCC_APB2Periph_GPIOA
  68. /**
  69. * @brief M25P SPI Flash supported commands
  70. */
  71. #define sFLASH_CMD_WRITE 0x02 /*!< Write to Memory instruction */
  72. #define sFLASH_CMD_WRSR 0x01 /*!< Write Status Register instruction */
  73. #define sFLASH_CMD_WREN 0x06 /*!< Write enable instruction */
  74. #define sFLASH_CMD_READ 0x03 /*!< Read from Memory instruction */
  75. #define sFLASH_CMD_RDSR 0x05 /*!< Read Status Register instruction */
  76. #define sFLASH_CMD_RDID 0x9F /*!< Read identification */
  77. #define sFLASH_CMD_SE 0xD8 /*!< Sector Erase instruction */
  78. #define sFLASH_CMD_BE 0xC7 /*!< Bulk Erase instruction */
  79. #define sFLASH_WIP_FLAG 0x01 /*!< Write In Progress (WIP) flag */
  80. #define sFLASH_DUMMY_BYTE 0xA5
  81. #define sFLASH_SPI_PAGESIZE 0x100
  82. #define sFLASH_M25P128_ID 0x202018
  83. #define sFLASH_M25P64_ID 0x202017
  84. /**
  85. * @}
  86. */
  87. /** @defgroup STM32_EVAL_SPI_FLASH_Exported_Macros
  88. * @{
  89. */
  90. /**
  91. * @brief Select sFLASH: Chip Select pin low
  92. */
  93. #define sFLASH_CS_LOW() GPIO_ResetBits(sFLASH_CS_GPIO_PORT, sFLASH_CS_PIN)
  94. /**
  95. * @brief Deselect sFLASH: Chip Select pin high
  96. */
  97. #define sFLASH_CS_HIGH() GPIO_SetBits(sFLASH_CS_GPIO_PORT, sFLASH_CS_PIN)
  98. /**
  99. * @}
  100. */
  101. /** @defgroup STM32_EVAL_SPI_FLASH_Exported_Functions
  102. * @{
  103. */
  104. /**
  105. * @brief High layer functions
  106. */
  107. void sFLASH_DeInit(void);
  108. void sFLASH_Init(void);
  109. void sFLASH_EraseSector(uint32_t SectorAddr);
  110. void sFLASH_EraseBulk(void);
  111. void sFLASH_WritePage(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite);
  112. void sFLASH_WriteBuffer(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite);
  113. void sFLASH_ReadBuffer(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t NumByteToRead);
  114. uint32_t sFLASH_ReadID(void);
  115. void sFLASH_StartReadSequence(uint32_t ReadAddr);
  116. /**
  117. * @brief Low layer functions
  118. */
  119. uint8_t sFLASH_ReadByte(void);
  120. uint8_t sFLASH_SendByte(uint8_t byte);
  121. uint16_t sFLASH_SendHalfWord(uint16_t HalfWord);
  122. void sFLASH_WriteEnable(void);
  123. void sFLASH_WaitForWriteEnd(void);
  124. #ifdef __cplusplus
  125. }
  126. #endif
  127. #endif /* __STM32_EVAL_SPI_FLASH_H */
  128. /**
  129. * @}
  130. */
  131. /**
  132. * @}
  133. */
  134. /**
  135. * @}
  136. */
  137. /**
  138. * @}
  139. */
  140. /**
  141. * @}
  142. */
  143. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/