You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

stm32f4xx_nucleo.h 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_nucleo.h
  4. * @author MCD Application Team
  5. * @brief This file contains definitions for:
  6. * - LEDs and push-button available on STM32F4XX-Nucleo Kit
  7. * from STMicroelectronics
  8. * - LCD, joystick and microSD available on Adafruit 1.8" TFT LCD
  9. * shield (reference ID 802)
  10. ******************************************************************************
  11. * @attention
  12. *
  13. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  14. *
  15. * Redistribution and use in source and binary forms, with or without modification,
  16. * are permitted provided that the following conditions are met:
  17. * 1. Redistributions of source code must retain the above copyright notice,
  18. * this list of conditions and the following disclaimer.
  19. * 2. Redistributions in binary form must reproduce the above copyright notice,
  20. * this list of conditions and the following disclaimer in the documentation
  21. * and/or other materials provided with the distribution.
  22. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  23. * may be used to endorse or promote products derived from this software
  24. * without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  27. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  29. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  30. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  31. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  32. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  33. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  34. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  35. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36. *
  37. ******************************************************************************
  38. */
  39. /* Define to prevent recursive inclusion -------------------------------------*/
  40. #ifndef __STM32F4XX_NUCLEO_H
  41. #define __STM32F4XX_NUCLEO_H
  42. #ifdef __cplusplus
  43. extern "C" {
  44. #endif
  45. /* Includes ------------------------------------------------------------------*/
  46. #include "stm32f4xx_hal.h"
  47. /* To be defined only if the board is provided with the related shield */
  48. /* https://www.adafruit.com/products/802 */
  49. #define ADAFRUIT_TFT_JOY_SD_ID802
  50. /** @addtogroup BSP
  51. * @{
  52. */
  53. /** @addtogroup STM32F4XX_NUCLEO
  54. * @{
  55. */
  56. /** @addtogroup STM32F4XX_NUCLEO_LOW_LEVEL
  57. * @{
  58. */
  59. /** @defgroup STM32F4XX_NUCLEO_LOW_LEVEL_Exported_Types STM32F4XX NUCLEO LOW LEVEL Exported Types
  60. * @{
  61. */
  62. typedef enum
  63. {
  64. LED2 = 0
  65. }Led_TypeDef;
  66. typedef enum
  67. {
  68. BUTTON_USER = 0,
  69. /* Alias */
  70. BUTTON_KEY = BUTTON_USER
  71. } Button_TypeDef;
  72. typedef enum
  73. {
  74. BUTTON_MODE_GPIO = 0,
  75. BUTTON_MODE_EXTI = 1
  76. }ButtonMode_TypeDef;
  77. typedef enum
  78. {
  79. JOY_NONE = 0,
  80. JOY_SEL = 1,
  81. JOY_DOWN = 2,
  82. JOY_LEFT = 3,
  83. JOY_RIGHT = 4,
  84. JOY_UP = 5
  85. }JOYState_TypeDef;
  86. /**
  87. * @}
  88. */
  89. /** @defgroup STM32F4XX_NUCLEO_LOW_LEVEL_Exported_Constants STM32F4XX NUCLEO LOW LEVEL Exported Constants
  90. * @{
  91. */
  92. /**
  93. * @brief Define for STM32F4XX_NUCLEO board
  94. */
  95. #if !defined (USE_STM32F4XX_NUCLEO)
  96. #define USE_STM32F4XX_NUCLEO
  97. #endif
  98. /** @defgroup STM32F4XX_NUCLEO_LOW_LEVEL_LED STM32F4XX NUCLEO LOW LEVEL LED
  99. * @{
  100. */
  101. #define LEDn 1
  102. #define LED2_PIN GPIO_PIN_5
  103. #define LED2_GPIO_PORT GPIOA
  104. #define LED2_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
  105. #define LED2_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
  106. #define LEDx_GPIO_CLK_ENABLE(__INDEX__) LED2_GPIO_CLK_ENABLE()
  107. #define LEDx_GPIO_CLK_DISABLE(__INDEX__) LED2_GPIO_CLK_DISABLE()
  108. /**
  109. * @}
  110. */
  111. /** @defgroup STM32F4XX_NUCLEO_LOW_LEVEL_BUTTON STM32F4XX NUCLEO LOW LEVEL BUTTON
  112. * @{
  113. */
  114. #define BUTTONn 1
  115. /**
  116. * @brief Key push-button
  117. */
  118. #define USER_BUTTON_PIN GPIO_PIN_13
  119. #define USER_BUTTON_GPIO_PORT GPIOC
  120. #define USER_BUTTON_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE()
  121. #define USER_BUTTON_GPIO_CLK_DISABLE() __HAL_RCC_GPIOC_CLK_DISABLE()
  122. #define USER_BUTTON_EXTI_LINE GPIO_PIN_13
  123. #define USER_BUTTON_EXTI_IRQn EXTI15_10_IRQn
  124. #define BUTTONx_GPIO_CLK_ENABLE(__INDEX__) USER_BUTTON_GPIO_CLK_ENABLE()
  125. #define BUTTONx_GPIO_CLK_DISABLE(__INDEX__) USER_BUTTON_GPIO_CLK_DISABLE()
  126. /* Aliases */
  127. #define KEY_BUTTON_PIN USER_BUTTON_PIN
  128. #define KEY_BUTTON_GPIO_PORT USER_BUTTON_GPIO_PORT
  129. #define KEY_BUTTON_GPIO_CLK_ENABLE() USER_BUTTON_GPIO_CLK_ENABLE()
  130. #define KEY_BUTTON_GPIO_CLK_DISABLE() USER_BUTTON_GPIO_CLK_DISABLE()
  131. #define KEY_BUTTON_EXTI_LINE USER_BUTTON_EXTI_LINE
  132. #define KEY_BUTTON_EXTI_IRQn USER_BUTTON_EXTI_IRQn
  133. /**
  134. * @}
  135. */
  136. /** @defgroup STM32F4XX_NUCLEO_LOW_LEVEL_BUS STM32F4XX NUCLEO LOW LEVEL BUS
  137. * @{
  138. */
  139. /*############################### SPI1 #######################################*/
  140. #ifdef HAL_SPI_MODULE_ENABLED
  141. #define NUCLEO_SPIx SPI1
  142. #define NUCLEO_SPIx_CLK_ENABLE() __HAL_RCC_SPI1_CLK_ENABLE()
  143. #define NUCLEO_SPIx_SCK_AF GPIO_AF5_SPI1
  144. #define NUCLEO_SPIx_SCK_GPIO_PORT GPIOA
  145. #define NUCLEO_SPIx_SCK_PIN GPIO_PIN_5
  146. #define NUCLEO_SPIx_SCK_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
  147. #define NUCLEO_SPIx_SCK_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
  148. #define NUCLEO_SPIx_MISO_MOSI_AF GPIO_AF5_SPI1
  149. #define NUCLEO_SPIx_MISO_MOSI_GPIO_PORT GPIOA
  150. #define NUCLEO_SPIx_MISO_MOSI_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
  151. #define NUCLEO_SPIx_MISO_MOSI_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
  152. #define NUCLEO_SPIx_MISO_PIN GPIO_PIN_6
  153. #define NUCLEO_SPIx_MOSI_PIN GPIO_PIN_7
  154. /* Maximum Timeout values for flags waiting loops. These timeouts are not based
  155. on accurate values, they just guarantee that the application will not remain
  156. stuck if the SPI communication is corrupted.
  157. You may modify these timeout values depending on CPU frequency and application
  158. conditions (interrupts routines ...). */
  159. #define NUCLEO_SPIx_TIMEOUT_MAX 1000
  160. /**
  161. * @brief SD Control Lines management
  162. */
  163. #define SD_CS_LOW() HAL_GPIO_WritePin(SD_CS_GPIO_PORT, SD_CS_PIN, GPIO_PIN_RESET)
  164. #define SD_CS_HIGH() HAL_GPIO_WritePin(SD_CS_GPIO_PORT, SD_CS_PIN, GPIO_PIN_SET)
  165. /**
  166. * @brief LCD Control Lines management
  167. */
  168. #define LCD_CS_LOW() HAL_GPIO_WritePin(LCD_CS_GPIO_PORT, LCD_CS_PIN, GPIO_PIN_RESET)
  169. #define LCD_CS_HIGH() HAL_GPIO_WritePin(LCD_CS_GPIO_PORT, LCD_CS_PIN, GPIO_PIN_SET)
  170. #define LCD_DC_LOW() HAL_GPIO_WritePin(LCD_DC_GPIO_PORT, LCD_DC_PIN, GPIO_PIN_RESET)
  171. #define LCD_DC_HIGH() HAL_GPIO_WritePin(LCD_DC_GPIO_PORT, LCD_DC_PIN, GPIO_PIN_SET)
  172. /**
  173. * @brief SD Control Interface pins (shield D4)
  174. */
  175. #define SD_CS_PIN GPIO_PIN_5
  176. #define SD_CS_GPIO_PORT GPIOB
  177. #define SD_CS_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
  178. #define SD_CS_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE()
  179. /**
  180. * @brief LCD Control Interface pins (shield D10)
  181. */
  182. #define LCD_CS_PIN GPIO_PIN_6
  183. #define LCD_CS_GPIO_PORT GPIOB
  184. #define LCD_CS_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
  185. #define LCD_CS_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE()
  186. /**
  187. * @brief LCD Data/Command Interface pins (shield D8)
  188. */
  189. #define LCD_DC_PIN GPIO_PIN_9
  190. #define LCD_DC_GPIO_PORT GPIOA
  191. #define LCD_DC_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
  192. #define LCD_DC_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
  193. #endif /* HAL_SPI_MODULE_ENABLED */
  194. /*################################ ADC1 ######################################*/
  195. /**
  196. * @brief ADC Interface pins
  197. * used to detect motion of Joystick available on Adafruit 1.8" TFT shield
  198. */
  199. #ifdef HAL_ADC_MODULE_ENABLED
  200. #define NUCLEO_ADCx ADC1
  201. #define NUCLEO_ADCx_CLK_ENABLE() __HAL_RCC_ADC1_CLK_ENABLE()
  202. #define NUCLEO_ADCx_CLK_DISABLE() __HAL_RCC_ADC1_CLK_DISABLE()
  203. #define NUCLEO_ADCx_CHANNEL ADC_CHANNEL_8
  204. #define NUCLEO_ADCx_GPIO_PORT GPIOB
  205. #define NUCLEO_ADCx_GPIO_PIN GPIO_PIN_0
  206. #define NUCLEO_ADCx_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
  207. #define NUCLEO_ADCx_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE()
  208. #endif /* HAL_ADC_MODULE_ENABLED */
  209. /**
  210. * @}
  211. */
  212. /**
  213. * @}
  214. */
  215. /** @defgroup STM32F4XX_NUCLEO_LOW_LEVEL_Exported_Macros STM32F4XX NUCLEO LOW LEVEL Exported Macros
  216. * @{
  217. */
  218. /**
  219. * @}
  220. */
  221. /** @defgroup STM32F4XX_NUCLEO_LOW_LEVEL_Exported_Functions STM32F4XX NUCLEO LOW LEVEL Exported Functions
  222. * @{
  223. */
  224. uint32_t BSP_GetVersion(void);
  225. void BSP_LED_Init(Led_TypeDef Led);
  226. void BSP_LED_DeInit(Led_TypeDef Led);
  227. void BSP_LED_On(Led_TypeDef Led);
  228. void BSP_LED_Off(Led_TypeDef Led);
  229. void BSP_LED_Toggle(Led_TypeDef Led);
  230. void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode);
  231. void BSP_PB_DeInit(Button_TypeDef Button);
  232. uint32_t BSP_PB_GetState(Button_TypeDef Button);
  233. #ifdef HAL_ADC_MODULE_ENABLED
  234. uint8_t BSP_JOY_Init(void);
  235. JOYState_TypeDef BSP_JOY_GetState(void);
  236. void BSP_JOY_DeInit(void);
  237. #endif /* HAL_ADC_MODULE_ENABLED */
  238. /**
  239. * @}
  240. */
  241. /**
  242. * @}
  243. */
  244. /**
  245. * @}
  246. */
  247. /**
  248. * @}
  249. */
  250. #ifdef __cplusplus
  251. }
  252. #endif
  253. #endif /* __STM32F4XX_NUCLEO_H */
  254. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/