board.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. /*
  2. ChibiOS - Copyright (C) 2006..2017 Giovanni Di Sirio
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. /*
  14. * This file has been automatically generated using ChibiStudio board
  15. * generator plugin. Do not edit manually.
  16. */
  17. #include "hal.h"
  18. #include "stm32_gpio.h"
  19. /*===========================================================================*/
  20. /* Driver local definitions. */
  21. /*===========================================================================*/
  22. /*===========================================================================*/
  23. /* Driver exported variables. */
  24. /*===========================================================================*/
  25. /*===========================================================================*/
  26. /* Driver local variables and types. */
  27. /*===========================================================================*/
  28. /**
  29. * @brief Type of STM32 GPIO port setup.
  30. */
  31. typedef struct {
  32. uint32_t moder;
  33. uint32_t otyper;
  34. uint32_t ospeedr;
  35. uint32_t pupdr;
  36. uint32_t odr;
  37. uint32_t afrl;
  38. uint32_t afrh;
  39. uint32_t ascr;
  40. uint32_t lockr;
  41. } gpio_setup_t;
  42. /**
  43. * @brief Type of STM32 GPIO initialization data.
  44. */
  45. typedef struct {
  46. #if STM32_HAS_GPIOA || defined(__DOXYGEN__)
  47. gpio_setup_t PAData;
  48. #endif
  49. #if STM32_HAS_GPIOB || defined(__DOXYGEN__)
  50. gpio_setup_t PBData;
  51. #endif
  52. #if STM32_HAS_GPIOC || defined(__DOXYGEN__)
  53. gpio_setup_t PCData;
  54. #endif
  55. #if STM32_HAS_GPIOD || defined(__DOXYGEN__)
  56. gpio_setup_t PDData;
  57. #endif
  58. #if STM32_HAS_GPIOE || defined(__DOXYGEN__)
  59. gpio_setup_t PEData;
  60. #endif
  61. #if STM32_HAS_GPIOF || defined(__DOXYGEN__)
  62. gpio_setup_t PFData;
  63. #endif
  64. #if STM32_HAS_GPIOG || defined(__DOXYGEN__)
  65. gpio_setup_t PGData;
  66. #endif
  67. #if STM32_HAS_GPIOH || defined(__DOXYGEN__)
  68. gpio_setup_t PHData;
  69. #endif
  70. #if STM32_HAS_GPIOI || defined(__DOXYGEN__)
  71. gpio_setup_t PIData;
  72. #endif
  73. #if STM32_HAS_GPIOJ || defined(__DOXYGEN__)
  74. gpio_setup_t PJData;
  75. #endif
  76. #if STM32_HAS_GPIOK || defined(__DOXYGEN__)
  77. gpio_setup_t PKData;
  78. #endif
  79. } gpio_config_t;
  80. /**
  81. * @brief STM32 GPIO static initialization data.
  82. */
  83. static const gpio_config_t gpio_default_config = {
  84. #if STM32_HAS_GPIOA
  85. {VAL_GPIOA_MODER, VAL_GPIOA_OTYPER, VAL_GPIOA_OSPEEDR, VAL_GPIOA_PUPDR,
  86. VAL_GPIOA_ODR, VAL_GPIOA_AFRL, VAL_GPIOA_AFRH, VAL_GPIOA_ASCR,
  87. VAL_GPIOA_LOCKR},
  88. #endif
  89. #if STM32_HAS_GPIOB
  90. {VAL_GPIOB_MODER, VAL_GPIOB_OTYPER, VAL_GPIOB_OSPEEDR, VAL_GPIOB_PUPDR,
  91. VAL_GPIOB_ODR, VAL_GPIOB_AFRL, VAL_GPIOB_AFRH, VAL_GPIOB_ASCR,
  92. VAL_GPIOB_LOCKR},
  93. #endif
  94. #if STM32_HAS_GPIOC
  95. {VAL_GPIOC_MODER, VAL_GPIOC_OTYPER, VAL_GPIOC_OSPEEDR, VAL_GPIOC_PUPDR,
  96. VAL_GPIOC_ODR, VAL_GPIOC_AFRL, VAL_GPIOC_AFRH, VAL_GPIOC_ASCR,
  97. VAL_GPIOC_LOCKR},
  98. #endif
  99. #if STM32_HAS_GPIOD
  100. {VAL_GPIOD_MODER, VAL_GPIOD_OTYPER, VAL_GPIOD_OSPEEDR, VAL_GPIOD_PUPDR,
  101. VAL_GPIOD_ODR, VAL_GPIOD_AFRL, VAL_GPIOD_AFRH, VAL_GPIOD_ASCR,
  102. VAL_GPIOD_LOCKR},
  103. #endif
  104. #if STM32_HAS_GPIOE
  105. {VAL_GPIOE_MODER, VAL_GPIOE_OTYPER, VAL_GPIOE_OSPEEDR, VAL_GPIOE_PUPDR,
  106. VAL_GPIOE_ODR, VAL_GPIOE_AFRL, VAL_GPIOE_AFRH, VAL_GPIOE_ASCR,
  107. VAL_GPIOE_LOCKR},
  108. #endif
  109. #if STM32_HAS_GPIOF
  110. {VAL_GPIOF_MODER, VAL_GPIOF_OTYPER, VAL_GPIOF_OSPEEDR, VAL_GPIOF_PUPDR,
  111. VAL_GPIOF_ODR, VAL_GPIOF_AFRL, VAL_GPIOF_AFRH, VAL_GPIOF_ASCR,
  112. VAL_GPIOF_LOCKR},
  113. #endif
  114. #if STM32_HAS_GPIOG
  115. {VAL_GPIOG_MODER, VAL_GPIOG_OTYPER, VAL_GPIOG_OSPEEDR, VAL_GPIOG_PUPDR,
  116. VAL_GPIOG_ODR, VAL_GPIOG_AFRL, VAL_GPIOG_AFRH, VAL_GPIOG_ASCR,
  117. VAL_GPIOG_LOCKR},
  118. #endif
  119. #if STM32_HAS_GPIOH
  120. {VAL_GPIOH_MODER, VAL_GPIOH_OTYPER, VAL_GPIOH_OSPEEDR, VAL_GPIOH_PUPDR,
  121. VAL_GPIOH_ODR, VAL_GPIOH_AFRL, VAL_GPIOH_AFRH, VAL_GPIOH_ASCR,
  122. VAL_GPIOH_LOCKR},
  123. #endif
  124. #if STM32_HAS_GPIOI
  125. {VAL_GPIOI_MODER, VAL_GPIOI_OTYPER, VAL_GPIOI_OSPEEDR, VAL_GPIOI_PUPDR,
  126. VAL_GPIOI_ODR, VAL_GPIOI_AFRL, VAL_GPIOI_AFRH, VAL_GPIOI_ASCR,
  127. VAL_GPIOI_LOCKR},
  128. #endif
  129. #if STM32_HAS_GPIOJ
  130. {VAL_GPIOJ_MODER, VAL_GPIOJ_OTYPER, VAL_GPIOJ_OSPEEDR, VAL_GPIOJ_PUPDR,
  131. VAL_GPIOJ_ODR, VAL_GPIOJ_AFRL, VAL_GPIOJ_AFRH, VAL_GPIOJ_ASCR,
  132. VAL_GPIOJ_LOCKR},
  133. #endif
  134. #if STM32_HAS_GPIOK
  135. {VAL_GPIOK_MODER, VAL_GPIOK_OTYPER, VAL_GPIOK_OSPEEDR, VAL_GPIOK_PUPDR,
  136. VAL_GPIOK_ODR, VAL_GPIOK_AFRL, VAL_GPIOK_AFRH, VAL_GPIOK_ASCR,
  137. VAL_GPIOK_LOCKR}
  138. #endif
  139. };
  140. /*===========================================================================*/
  141. /* Driver local functions. */
  142. /*===========================================================================*/
  143. static void gpio_init(stm32_gpio_t *gpiop, const gpio_setup_t *config) {
  144. gpiop->OTYPER = config->otyper;
  145. gpiop->ASCR = config->ascr;
  146. gpiop->OSPEEDR = config->ospeedr;
  147. gpiop->PUPDR = config->pupdr;
  148. gpiop->ODR = config->odr;
  149. gpiop->AFRL = config->afrl;
  150. gpiop->AFRH = config->afrh;
  151. gpiop->MODER = config->moder;
  152. gpiop->LOCKR = config->lockr;
  153. }
  154. static void stm32_gpio_init(void) {
  155. /* Enabling GPIO-related clocks, the mask comes from the
  156. registry header file.*/
  157. rccResetAHB2(STM32_GPIO_EN_MASK);
  158. rccEnableAHB2(STM32_GPIO_EN_MASK, true);
  159. /* Initializing all the defined GPIO ports.*/
  160. #if STM32_HAS_GPIOA
  161. gpio_init(GPIOA, &gpio_default_config.PAData);
  162. #endif
  163. #if STM32_HAS_GPIOB
  164. gpio_init(GPIOB, &gpio_default_config.PBData);
  165. #endif
  166. #if STM32_HAS_GPIOC
  167. gpio_init(GPIOC, &gpio_default_config.PCData);
  168. #endif
  169. #if STM32_HAS_GPIOD
  170. gpio_init(GPIOD, &gpio_default_config.PDData);
  171. #endif
  172. #if STM32_HAS_GPIOE
  173. gpio_init(GPIOE, &gpio_default_config.PEData);
  174. #endif
  175. #if STM32_HAS_GPIOF
  176. gpio_init(GPIOF, &gpio_default_config.PFData);
  177. #endif
  178. #if STM32_HAS_GPIOG
  179. gpio_init(GPIOG, &gpio_default_config.PGData);
  180. #endif
  181. #if STM32_HAS_GPIOH
  182. gpio_init(GPIOH, &gpio_default_config.PHData);
  183. #endif
  184. #if STM32_HAS_GPIOI
  185. gpio_init(GPIOI, &gpio_default_config.PIData);
  186. #endif
  187. #if STM32_HAS_GPIOJ
  188. gpio_init(GPIOJ, &gpio_default_config.PJData);
  189. #endif
  190. #if STM32_HAS_GPIOK
  191. gpio_init(GPIOK, &gpio_default_config.PKData);
  192. #endif
  193. }
  194. /*===========================================================================*/
  195. /* Driver interrupt handlers. */
  196. /*===========================================================================*/
  197. /*===========================================================================*/
  198. /* Driver exported functions. */
  199. /*===========================================================================*/
  200. /**
  201. * @brief Early initialization code.
  202. * @details GPIO ports and system clocks are initialized before everything
  203. * else.
  204. */
  205. void __early_init(void) {
  206. stm32_gpio_init();
  207. stm32_clock_init();
  208. }
  209. #if HAL_USE_SDC || defined(__DOXYGEN__)
  210. /**
  211. * @brief SDC card detection.
  212. */
  213. bool sdc_lld_is_card_inserted(SDCDriver *sdcp) {
  214. (void)sdcp;
  215. /* TODO: Fill the implementation.*/
  216. return true;
  217. }
  218. /**
  219. * @brief SDC card write protection detection.
  220. */
  221. bool sdc_lld_is_write_protected(SDCDriver *sdcp) {
  222. (void)sdcp;
  223. /* TODO: Fill the implementation.*/
  224. return false;
  225. }
  226. #endif /* HAL_USE_SDC */
  227. #if HAL_USE_MMC_SPI || defined(__DOXYGEN__)
  228. /**
  229. * @brief MMC_SPI card detection.
  230. */
  231. bool mmc_lld_is_card_inserted(MMCDriver *mmcp) {
  232. (void)mmcp;
  233. /* TODO: Fill the implementation.*/
  234. return true;
  235. }
  236. /**
  237. * @brief MMC_SPI card write protection detection.
  238. */
  239. bool mmc_lld_is_write_protected(MMCDriver *mmcp) {
  240. (void)mmcp;
  241. /* TODO: Fill the implementation.*/
  242. return false;
  243. }
  244. #endif
  245. /**
  246. * @brief Board-specific initialization code.
  247. * @todo Add your board-specific code, if any.
  248. */
  249. void boardInit(void) {
  250. }