stm32l4xx_nucleo.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_nucleo.h
  4. * @author MCD Application Team
  5. * @version V2.1.0
  6. * @date 16-June-2017
  7. * @brief This file contains definitions for:
  8. * - LEDs and push-button available on STM32L4XX-Nucleo Kit
  9. * from STMicroelectronics
  10. * - LCD, joystick and microSD available on Adafruit 1.8" TFT LCD
  11. * shield (reference ID 802)
  12. ******************************************************************************
  13. * @attention
  14. *
  15. * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
  16. *
  17. * Redistribution and use in source and binary forms, with or without modification,
  18. * are permitted provided that the following conditions are met:
  19. * 1. Redistributions of source code must retain the above copyright notice,
  20. * this list of conditions and the following disclaimer.
  21. * 2. Redistributions in binary form must reproduce the above copyright notice,
  22. * this list of conditions and the following disclaimer in the documentation
  23. * and/or other materials provided with the distribution.
  24. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  25. * may be used to endorse or promote products derived from this software
  26. * without specific prior written permission.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  29. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  30. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  32. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  33. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  34. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  35. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  36. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  37. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. ******************************************************************************
  40. */
  41. /* Define to prevent recursive inclusion -------------------------------------*/
  42. #ifndef __STM32L4XX_NUCLEO_H
  43. #define __STM32L4XX_NUCLEO_H
  44. #ifdef __cplusplus
  45. extern "C" {
  46. #endif
  47. /** @addtogroup BSP
  48. * @{
  49. */
  50. /** @addtogroup STM32L4XX_NUCLEO
  51. * @{
  52. */
  53. /* Includes ------------------------------------------------------------------*/
  54. #include "stm32l4xx_hal.h"
  55. /** @defgroup STM32L4XX_NUCLEO_Exported_Types Exported Types
  56. * @{
  57. */
  58. #ifdef USE_STM32L4XX_NUCLEO_64_SMPS
  59. typedef enum
  60. {
  61. LED4 = 0,
  62. LED_GREEN = LED4
  63. } Led_TypeDef;
  64. #else
  65. typedef enum
  66. {
  67. LED2 = 0,
  68. LED_GREEN = LED2
  69. } Led_TypeDef;
  70. #endif
  71. typedef enum
  72. {
  73. BUTTON_USER = 0,
  74. /* Alias */
  75. BUTTON_KEY = BUTTON_USER
  76. } Button_TypeDef;
  77. typedef enum
  78. {
  79. BUTTON_MODE_GPIO = 0,
  80. BUTTON_MODE_EXTI = 1
  81. } ButtonMode_TypeDef;
  82. typedef enum
  83. {
  84. JOY_NONE = 0,
  85. JOY_SEL = 1,
  86. JOY_DOWN = 2,
  87. JOY_LEFT = 3,
  88. JOY_RIGHT = 4,
  89. JOY_UP = 5
  90. } JOYState_TypeDef;
  91. /**
  92. * @}
  93. */
  94. /** @defgroup STM32L4XX_NUCLEO_Exported_Constants Exported Constants
  95. * @{
  96. */
  97. /**
  98. * @brief Define for STM32L4XX_NUCLEO board
  99. */
  100. #if !defined (USE_STM32L4XX_NUCLEO)
  101. #define USE_STM32L4XX_NUCLEO
  102. #endif
  103. /** @defgroup STM32L4XX_NUCLEO_LED LED Constants
  104. * @{
  105. */
  106. #define LEDn 1
  107. #ifdef USE_STM32L4XX_NUCLEO_64_SMPS
  108. #define LED4_PIN GPIO_PIN_13
  109. #define LED4_GPIO_PORT GPIOB
  110. #define LED4_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
  111. #define LED4_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE()
  112. #define LEDx_GPIO_CLK_ENABLE(__LED__) do { if((__LED__) == LED4) { LED4_GPIO_CLK_ENABLE(); } } while(0)
  113. #define LEDx_GPIO_CLK_DISABLE(__LED__) do { if((__LED__) == LED4) { LED4_GPIO_CLK_DISABLE(); } } while(0)
  114. #else
  115. #define LED2_PIN GPIO_PIN_5
  116. #define LED2_GPIO_PORT GPIOA
  117. #define LED2_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
  118. #define LED2_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
  119. #define LEDx_GPIO_CLK_ENABLE(__LED__) do { if((__LED__) == LED2) { LED2_GPIO_CLK_ENABLE(); } } while(0)
  120. #define LEDx_GPIO_CLK_DISABLE(__LED__) do { if((__LED__) == LED2) { LED2_GPIO_CLK_DISABLE(); } } while(0)
  121. #endif
  122. /**
  123. * @}
  124. */
  125. #ifdef USE_STM32L4XX_NUCLEO_64_SMPS
  126. #ifdef USE_ADP5301ACBZ /* ADP5301ACBZ */
  127. /** @addtogroup STM32L4XX_NUCLEO_64_SMPS
  128. * @{
  129. */
  130. #define PWR_AND_CLK_SMPS() do { __HAL_RCC_PWR_CLK_ENABLE(); \
  131. __HAL_RCC_GPIOA_CLK_ENABLE(); } while(0)
  132. /**
  133. * @}
  134. */
  135. #endif /* ADP5301ACBZ */
  136. #endif /* USE_STM32L4XX_NUCLEO_64_SMPS */
  137. /** @defgroup STM32L4XX_NUCLEO_BUTTON BUTTON Constants
  138. * @{
  139. */
  140. #define BUTTONn 1
  141. /**
  142. * @brief Key push-button
  143. */
  144. #define USER_BUTTON_PIN GPIO_PIN_13
  145. #define USER_BUTTON_GPIO_PORT GPIOC
  146. #define USER_BUTTON_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE()
  147. #define USER_BUTTON_GPIO_CLK_DISABLE() __HAL_RCC_GPIOC_CLK_DISABLE()
  148. #define USER_BUTTON_EXTI_LINE GPIO_PIN_13
  149. #define USER_BUTTON_EXTI_IRQn EXTI15_10_IRQn
  150. /* Aliases */
  151. #define KEY_BUTTON_PIN USER_BUTTON_PIN
  152. #define KEY_BUTTON_GPIO_PORT USER_BUTTON_GPIO_PORT
  153. #define KEY_BUTTON_GPIO_CLK_ENABLE() USER_BUTTON_GPIO_CLK_ENABLE()
  154. #define KEY_BUTTON_GPIO_CLK_DISABLE() USER_BUTTON_GPIO_CLK_DISABLE()
  155. #define KEY_BUTTON_EXTI_LINE USER_BUTTON_EXTI_LINE
  156. #define KEY_BUTTON_EXTI_IRQn USER_BUTTON_EXTI_IRQn
  157. #define BUTTONx_GPIO_CLK_ENABLE(__BUTTON__) do { if((__BUTTON__) == BUTTON_USER) { USER_BUTTON_GPIO_CLK_ENABLE(); } } while(0)
  158. #define BUTTONx_GPIO_CLK_DISABLE(__BUTTON__) do { if((__BUTTON__) == BUTTON_USER) { USER_BUTTON_GPIO_CLK_DISABLE(); } } while(0)
  159. /**
  160. * @}
  161. */
  162. /** @addtogroup STM32L4XX_NUCLEO_BUS BUS Constants
  163. * @{
  164. */
  165. /*###################### SPI1 ###################################*/
  166. #define NUCLEO_SPIx SPI1
  167. #define NUCLEO_SPIx_CLK_ENABLE() __HAL_RCC_SPI1_CLK_ENABLE()
  168. #define NUCLEO_SPIx_SCK_AF GPIO_AF5_SPI1
  169. #define NUCLEO_SPIx_SCK_GPIO_PORT GPIOA
  170. #define NUCLEO_SPIx_SCK_PIN GPIO_PIN_5
  171. #define NUCLEO_SPIx_SCK_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
  172. #define NUCLEO_SPIx_SCK_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
  173. #define NUCLEO_SPIx_MISO_MOSI_AF GPIO_AF5_SPI1
  174. #define NUCLEO_SPIx_MISO_MOSI_GPIO_PORT GPIOA
  175. #define NUCLEO_SPIx_MISO_MOSI_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
  176. #define NUCLEO_SPIx_MISO_MOSI_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
  177. #define NUCLEO_SPIx_MISO_PIN GPIO_PIN_6
  178. #define NUCLEO_SPIx_MOSI_PIN GPIO_PIN_7
  179. /* Maximum Timeout values for flags waiting loops. These timeouts are not based
  180. on accurate values, they just guarantee that the application will not remain
  181. stuck if the SPI communication is corrupted.
  182. You may modify these timeout values depending on CPU frequency and application
  183. conditions (interrupts routines ...). */
  184. #define NUCLEO_SPIx_TIMEOUT_MAX 1000
  185. /**
  186. * @brief SD Control Lines management
  187. */
  188. #define SD_CS_LOW() HAL_GPIO_WritePin(SD_CS_GPIO_PORT, SD_CS_PIN, GPIO_PIN_RESET)
  189. #define SD_CS_HIGH() HAL_GPIO_WritePin(SD_CS_GPIO_PORT, SD_CS_PIN, GPIO_PIN_SET)
  190. /**
  191. * @brief LCD Control Lines management
  192. */
  193. #define LCD_CS_LOW() HAL_GPIO_WritePin(LCD_CS_GPIO_PORT, LCD_CS_PIN, GPIO_PIN_RESET)
  194. #define LCD_CS_HIGH() HAL_GPIO_WritePin(LCD_CS_GPIO_PORT, LCD_CS_PIN, GPIO_PIN_SET)
  195. #define LCD_DC_LOW() HAL_GPIO_WritePin(LCD_DC_GPIO_PORT, LCD_DC_PIN, GPIO_PIN_RESET)
  196. #define LCD_DC_HIGH() HAL_GPIO_WritePin(LCD_DC_GPIO_PORT, LCD_DC_PIN, GPIO_PIN_SET)
  197. /**
  198. * @brief SD Control Interface pins
  199. */
  200. #define SD_CS_PIN GPIO_PIN_5
  201. #define SD_CS_GPIO_PORT GPIOB
  202. #define SD_CS_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
  203. #define SD_CS_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE()
  204. /**
  205. * @brief LCD Control Interface pins
  206. */
  207. #define LCD_CS_PIN GPIO_PIN_6
  208. #define LCD_CS_GPIO_PORT GPIOB
  209. #define LCD_CS_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
  210. #define LCD_CS_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE()
  211. /**
  212. * @brief LCD Data/Command Interface pins
  213. */
  214. #define LCD_DC_PIN GPIO_PIN_9
  215. #define LCD_DC_GPIO_PORT GPIOA
  216. #define LCD_DC_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
  217. #define LCD_DC_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
  218. /*##################### ADC1 ###################################*/
  219. /**
  220. * @brief ADC Interface pins
  221. * used to detect motion of Joystick available on Adafruit 1.8" TFT shield
  222. */
  223. #define NUCLEO_ADCx ADC1
  224. #define NUCLEO_ADCx_CLK_ENABLE() __HAL_RCC_ADC_CLK_ENABLE()
  225. #define NUCLEO_ADCx_GPIO_PORT GPIOB
  226. #define NUCLEO_ADCx_GPIO_PIN GPIO_PIN_0
  227. #define NUCLEO_ADCx_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
  228. #define NUCLEO_ADCx_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE()
  229. /*##################### SMPS###################################*/
  230. #ifdef USE_STM32L4XX_NUCLEO_64_SMPS
  231. #ifdef USE_ADP5301ACBZ /* ADP5301ACBZ */
  232. #define PORT_SMPS GPIOA
  233. #define PIN_SMPS_ENABLE GPIO_PIN_4
  234. #define PIN_SMPS_V1 GPIO_PIN_5
  235. #define PIN_SMPS_POWERGOOD GPIO_PIN_6
  236. #define PIN_SMPS_SWITCH_ENABLE GPIO_PIN_7
  237. #define PWR_GPIO_SMPS PWR_GPIO_A
  238. #define PWR_GPIO_ENABLE PWR_GPIO_BIT_4
  239. #define PWR_GPIO_SWITCH_ENABLE PWR_GPIO_BIT_7
  240. #define PWR_PU_REG PUCRA
  241. #define NUCLEO_SMPS_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
  242. #define NUCLEO_SMPS_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
  243. #endif /* ADP5301ACBZ */
  244. #endif /* USE_STM32L4XX_NUCLEO_64_SMPS */
  245. /**
  246. * @}
  247. */
  248. /**
  249. * @}
  250. */
  251. /** @addtogroup STM32L4XX_NUCLEO_Exported_Functions
  252. * @{
  253. */
  254. uint32_t BSP_GetVersion(void);
  255. /** @addtogroup STM32L4XX_NUCLEO_LED_Functions
  256. * @{
  257. */
  258. void BSP_LED_Init(Led_TypeDef Led);
  259. void BSP_LED_On(Led_TypeDef Led);
  260. void BSP_LED_Off(Led_TypeDef Led);
  261. void BSP_LED_Toggle(Led_TypeDef Led);
  262. /**
  263. * @}
  264. */
  265. /** @addtogroup STM32L4XX_NUCLEO_BUTTON_Functions
  266. * @{
  267. */
  268. void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode);
  269. uint32_t BSP_PB_GetState(Button_TypeDef Button);
  270. #ifdef HAL_ADC_MODULE_ENABLED
  271. uint8_t BSP_JOY_Init(void);
  272. JOYState_TypeDef BSP_JOY_GetState(void);
  273. #endif /* HAL_ADC_MODULE_ENABLED */
  274. /**
  275. * @}
  276. */
  277. /**
  278. * @}
  279. */
  280. /**
  281. * @}
  282. */
  283. /**
  284. * @}
  285. */
  286. #ifdef USE_STM32L4XX_NUCLEO_64_SMPS
  287. /**
  288. * @brief SMPS OK-KO
  289. */
  290. #define SMPS_OK 0
  291. #define SMPS_KO 1
  292. uint32_t BSP_SMPS_DeInit(void);
  293. uint32_t BSP_SMPS_Init(uint32_t VoltageRange);
  294. uint32_t BSP_SMPS_Enable(uint32_t Delay, uint32_t Power_Good_Check);
  295. uint32_t BSP_SMPS_Disable(void);
  296. uint32_t BSP_SMPS_Supply_Enable(uint32_t Delay, uint32_t Power_Good_Check);
  297. uint32_t BSP_SMPS_Supply_Disable(void);
  298. #endif /* USE_STM32L4XX_NUCLEO_64_SMPS */
  299. #ifdef __cplusplus
  300. }
  301. #endif
  302. #endif /* __STM32L4XX_NUCLEO_H */
  303. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/