stm32l0xx_nucleo.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. /**
  2. ******************************************************************************
  3. * @file stm32l0xx_nucleo.h
  4. * @author MCD Application Team
  5. * @brief This file contains definitions for:
  6. * - LEDs and push-button available on STM32L0XX-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. * Copyright (c) 2016 STMicroelectronics.
  14. * All rights reserved.
  15. *
  16. * This software is licensed under terms that can be found in the LICENSE file
  17. * in the root directory of this software component.
  18. * If no LICENSE file comes with this software, it is provided AS-IS.
  19. *
  20. ******************************************************************************
  21. */
  22. /* Define to prevent recursive inclusion -------------------------------------*/
  23. #ifndef __STM32L0XX_NUCLEO_H
  24. #define __STM32L0XX_NUCLEO_H
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. /** @addtogroup BSP
  29. * @{
  30. */
  31. /** @addtogroup STM32L0XX_NUCLEO
  32. * @{
  33. */
  34. /* Includes ------------------------------------------------------------------*/
  35. #include "stm32l0xx_hal.h"
  36. /** @addtogroup STM32L0XX_NUCLEO_LOW_LEVEL
  37. * @{
  38. */
  39. /** @defgroup STM32L0XX_NUCLEO_LOW_LEVEL_Exported_Types Exported Types
  40. * @{
  41. */
  42. typedef enum
  43. {
  44. LED2 = 0,
  45. LED_GREEN = LED2
  46. } Led_TypeDef;
  47. typedef enum
  48. {
  49. BUTTON_USER = 0,
  50. /* Alias */
  51. BUTTON_KEY = BUTTON_USER
  52. } Button_TypeDef;
  53. typedef enum
  54. {
  55. BUTTON_MODE_GPIO = 0,
  56. BUTTON_MODE_EXTI = 1
  57. } ButtonMode_TypeDef;
  58. typedef enum
  59. {
  60. JOY_NONE = 0,
  61. JOY_SEL = 1,
  62. JOY_DOWN = 2,
  63. JOY_LEFT = 3,
  64. JOY_RIGHT = 4,
  65. JOY_UP = 5
  66. } JOYState_TypeDef;
  67. /**
  68. * @}
  69. */
  70. /** @defgroup STM32L0XX_NUCLEO_LOW_LEVEL_Exported_Constants Exported Constants
  71. * @{
  72. */
  73. /**
  74. * @brief Define for STM32L0XX_NUCLEO board
  75. */
  76. #if !defined (USE_STM32L0XX_NUCLEO)
  77. #define USE_STM32L0XX_NUCLEO
  78. #endif
  79. /** @addtogroup STM32L0XX_NUCLEO_LOW_LEVEL_LED
  80. * @{
  81. */
  82. #define LEDn 1
  83. #define LED2_PIN GPIO_PIN_5
  84. #define LED2_GPIO_PORT GPIOA
  85. #define LED2_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
  86. #define LED2_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
  87. #define LEDx_GPIO_CLK_ENABLE(__INDEX__) do { if((__INDEX__) == 0) LED2_GPIO_CLK_ENABLE();} while(0)
  88. #define LEDx_GPIO_CLK_DISABLE(__INDEX__) (((__INDEX__) == 0) ? LED2_GPIO_CLK_DISABLE() : 0)
  89. /**
  90. * @}
  91. */
  92. /** @addtogroup STM32L0XX_NUCLEO_LOW_LEVEL_BUTTON
  93. * @{
  94. */
  95. #define BUTTONn 1
  96. /**
  97. * @brief User push-button
  98. */
  99. #define USER_BUTTON_PIN GPIO_PIN_13
  100. #define USER_BUTTON_GPIO_PORT GPIOC
  101. #define USER_BUTTON_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE()
  102. #define USER_BUTTON_GPIO_CLK_DISABLE() __HAL_RCC_GPIOC_CLK_DISABLE()
  103. #define USER_BUTTON_EXTI_IRQn EXTI4_15_IRQn
  104. /* Aliases */
  105. #define KEY_BUTTON_PIN USER_BUTTON_PIN
  106. #define KEY_BUTTON_GPIO_PORT USER_BUTTON_GPIO_PORT
  107. #define KEY_BUTTON_GPIO_CLK_ENABLE() USER_BUTTON_GPIO_CLK_ENABLE()
  108. #define KEY_BUTTON_GPIO_CLK_DISABLE() USER_BUTTON_GPIO_CLK_DISABLE()
  109. #define KEY_BUTTON_EXTI_IRQn USER_BUTTON_EXTI_IRQn
  110. #define BUTTONx_GPIO_CLK_ENABLE(__INDEX__) do { if((__INDEX__) == 0) USER_BUTTON_GPIO_CLK_ENABLE();} while(0)
  111. #define BUTTONx_GPIO_CLK_DISABLE(__INDEX__) (((__INDEX__) == 0) ? USER_BUTTON_GPIO_CLK_DISABLE() : 0)
  112. /**
  113. * @}
  114. */
  115. /** @addtogroup STM32L0XX_NUCLEO_LOW_LEVEL_BUS
  116. * @{
  117. */
  118. #if defined(HAL_SPI_MODULE_ENABLED)
  119. /*###################### SPI1 ###################################*/
  120. #define NUCLEO_SPIx SPI1
  121. #define NUCLEO_SPIx_CLK_ENABLE() __HAL_RCC_SPI1_CLK_ENABLE()
  122. #define NUCLEO_SPIx_SCK_AF GPIO_AF0_SPI1
  123. #define NUCLEO_SPIx_SCK_GPIO_PORT GPIOA
  124. #define NUCLEO_SPIx_SCK_PIN GPIO_PIN_5
  125. #define NUCLEO_SPIx_SCK_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
  126. #define NUCLEO_SPIx_SCK_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
  127. #define NUCLEO_SPIx_MISO_MOSI_AF GPIO_AF0_SPI1
  128. #define NUCLEO_SPIx_MISO_MOSI_GPIO_PORT GPIOA
  129. #define NUCLEO_SPIx_MISO_MOSI_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
  130. #define NUCLEO_SPIx_MISO_MOSI_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
  131. #define NUCLEO_SPIx_MISO_PIN GPIO_PIN_6
  132. #define NUCLEO_SPIx_MOSI_PIN GPIO_PIN_7
  133. /* Maximum Timeout values for flags waiting loops. These timeouts are not based
  134. on accurate values, they just guarantee that the application will not remain
  135. stuck if the SPI communication is corrupted.
  136. You may modify these timeout values depending on CPU frequency and application
  137. conditions (interrupts routines ...). */
  138. #define NUCLEO_SPIx_TIMEOUT_MAX 1000
  139. #endif /* HAL_SPI_MODULE_ENABLED */
  140. /**
  141. * @}
  142. */
  143. /** @addtogroup STM32L0XX_NUCLEO_LOW_LEVEL_COMPONENT
  144. * @{
  145. */
  146. /**
  147. * @brief SD Control Lines management
  148. */
  149. #define SD_CS_LOW() HAL_GPIO_WritePin(SD_CS_GPIO_PORT, SD_CS_PIN, GPIO_PIN_RESET)
  150. #define SD_CS_HIGH() HAL_GPIO_WritePin(SD_CS_GPIO_PORT, SD_CS_PIN, GPIO_PIN_SET)
  151. /**
  152. * @brief LCD Control Lines management
  153. */
  154. #define LCD_CS_LOW() HAL_GPIO_WritePin(LCD_CS_GPIO_PORT, LCD_CS_PIN, GPIO_PIN_RESET)
  155. #define LCD_CS_HIGH() HAL_GPIO_WritePin(LCD_CS_GPIO_PORT, LCD_CS_PIN, GPIO_PIN_SET)
  156. #define LCD_DC_LOW() HAL_GPIO_WritePin(LCD_DC_GPIO_PORT, LCD_DC_PIN, GPIO_PIN_RESET)
  157. #define LCD_DC_HIGH() HAL_GPIO_WritePin(LCD_DC_GPIO_PORT, LCD_DC_PIN, GPIO_PIN_SET)
  158. /**
  159. * @brief SD Control Interface pins (shield D4)
  160. */
  161. #define SD_CS_PIN GPIO_PIN_5
  162. #define SD_CS_GPIO_PORT GPIOB
  163. #define SD_CS_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
  164. #define SD_CS_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE()
  165. /**
  166. * @brief LCD Control Interface pins (shield D10)
  167. */
  168. #define LCD_CS_PIN GPIO_PIN_6
  169. #define LCD_CS_GPIO_PORT GPIOB
  170. #define LCD_CS_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
  171. #define LCD_CS_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE()
  172. /**
  173. * @brief LCD Data/Command Interface pins
  174. */
  175. #define LCD_DC_PIN GPIO_PIN_9
  176. #define LCD_DC_GPIO_PORT GPIOA
  177. #define LCD_DC_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
  178. #define LCD_DC_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
  179. #if defined(HAL_ADC_MODULE_ENABLED)
  180. /*##################### ADC1 ###################################*/
  181. /**
  182. * @brief ADC Interface pins
  183. * used to detect motion of Joystick available on Adafruit 1.8 TFT shield
  184. */
  185. #define NUCLEO_ADCx ADC1
  186. #define NUCLEO_ADCx_CLK_ENABLE() __HAL_RCC_ADC1_CLK_ENABLE()
  187. #define NUCLEO_ADCx_CLK_DISABLE() __HAL_RCC_ADC1_CLK_DISABLE()
  188. #define NUCLEO_ADCx_GPIO_PORT GPIOB
  189. #define NUCLEO_ADCx_GPIO_PIN GPIO_PIN_0
  190. #define NUCLEO_ADCx_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
  191. #define NUCLEO_ADCx_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE()
  192. #endif /* HAL_ADC_MODULE_ENABLED */
  193. /**
  194. * @}
  195. */
  196. /** @defgroup STM32L0XX_NUCLEO_LOW_LEVEL_Exported_Macros Exported Macros
  197. * @{
  198. */
  199. /**
  200. * @}
  201. */
  202. /** @defgroup STM32L0XX_NUCLEO_LOW_LEVEL_Exported_Functions Exported Functions
  203. * @{
  204. */
  205. uint32_t BSP_GetVersion(void);
  206. void BSP_LED_Init(Led_TypeDef Led);
  207. void BSP_LED_DeInit(Led_TypeDef Led);
  208. void BSP_LED_On(Led_TypeDef Led);
  209. void BSP_LED_Off(Led_TypeDef Led);
  210. void BSP_LED_Toggle(Led_TypeDef Led);
  211. void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode);
  212. void BSP_PB_DeInit(Button_TypeDef Button);
  213. uint32_t BSP_PB_GetState(Button_TypeDef Button);
  214. #if defined(HAL_ADC_MODULE_ENABLED)
  215. uint8_t BSP_JOY_Init(void);
  216. JOYState_TypeDef BSP_JOY_GetState(void);
  217. void BSP_JOY_DeInit(void);
  218. #endif /* HAL_ADC_MODULE_ENABLED */
  219. /**
  220. * @}
  221. */
  222. /**
  223. * @}
  224. */
  225. /**
  226. * @}
  227. */
  228. /**
  229. * @}
  230. */
  231. /**
  232. * @}
  233. */
  234. #ifdef __cplusplus
  235. }
  236. #endif
  237. #endif /* __STM32L0XX_NUCLEO_H */