board.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /*
  2. ChibiOS - Copyright (C) 2006..2018 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. } gpio_setup_t;
  40. /**
  41. * @brief Type of STM32 GPIO initialization data.
  42. */
  43. typedef struct {
  44. #if STM32_HAS_GPIOA || defined(__DOXYGEN__)
  45. gpio_setup_t PAData;
  46. #endif
  47. #if STM32_HAS_GPIOB || defined(__DOXYGEN__)
  48. gpio_setup_t PBData;
  49. #endif
  50. #if STM32_HAS_GPIOC || defined(__DOXYGEN__)
  51. gpio_setup_t PCData;
  52. #endif
  53. #if STM32_HAS_GPIOD || defined(__DOXYGEN__)
  54. gpio_setup_t PDData;
  55. #endif
  56. #if STM32_HAS_GPIOE || defined(__DOXYGEN__)
  57. gpio_setup_t PEData;
  58. #endif
  59. #if STM32_HAS_GPIOF || defined(__DOXYGEN__)
  60. gpio_setup_t PFData;
  61. #endif
  62. #if STM32_HAS_GPIOG || defined(__DOXYGEN__)
  63. gpio_setup_t PGData;
  64. #endif
  65. #if STM32_HAS_GPIOH || defined(__DOXYGEN__)
  66. gpio_setup_t PHData;
  67. #endif
  68. #if STM32_HAS_GPIOI || defined(__DOXYGEN__)
  69. gpio_setup_t PIData;
  70. #endif
  71. #if STM32_HAS_GPIOJ || defined(__DOXYGEN__)
  72. gpio_setup_t PJData;
  73. #endif
  74. #if STM32_HAS_GPIOK || defined(__DOXYGEN__)
  75. gpio_setup_t PKData;
  76. #endif
  77. } gpio_config_t;
  78. /**
  79. * @brief STM32 GPIO static initialization data.
  80. */
  81. static const gpio_config_t gpio_default_config = {
  82. #if STM32_HAS_GPIOA
  83. {VAL_GPIOA_MODER, VAL_GPIOA_OTYPER, VAL_GPIOA_OSPEEDR, VAL_GPIOA_PUPDR,
  84. VAL_GPIOA_ODR, VAL_GPIOA_AFRL, VAL_GPIOA_AFRH},
  85. #endif
  86. #if STM32_HAS_GPIOB
  87. {VAL_GPIOB_MODER, VAL_GPIOB_OTYPER, VAL_GPIOB_OSPEEDR, VAL_GPIOB_PUPDR,
  88. VAL_GPIOB_ODR, VAL_GPIOB_AFRL, VAL_GPIOB_AFRH},
  89. #endif
  90. #if STM32_HAS_GPIOC
  91. {VAL_GPIOC_MODER, VAL_GPIOC_OTYPER, VAL_GPIOC_OSPEEDR, VAL_GPIOC_PUPDR,
  92. VAL_GPIOC_ODR, VAL_GPIOC_AFRL, VAL_GPIOC_AFRH},
  93. #endif
  94. #if STM32_HAS_GPIOD
  95. {VAL_GPIOD_MODER, VAL_GPIOD_OTYPER, VAL_GPIOD_OSPEEDR, VAL_GPIOD_PUPDR,
  96. VAL_GPIOD_ODR, VAL_GPIOD_AFRL, VAL_GPIOD_AFRH},
  97. #endif
  98. #if STM32_HAS_GPIOE
  99. {VAL_GPIOE_MODER, VAL_GPIOE_OTYPER, VAL_GPIOE_OSPEEDR, VAL_GPIOE_PUPDR,
  100. VAL_GPIOE_ODR, VAL_GPIOE_AFRL, VAL_GPIOE_AFRH},
  101. #endif
  102. #if STM32_HAS_GPIOF
  103. {VAL_GPIOF_MODER, VAL_GPIOF_OTYPER, VAL_GPIOF_OSPEEDR, VAL_GPIOF_PUPDR,
  104. VAL_GPIOF_ODR, VAL_GPIOF_AFRL, VAL_GPIOF_AFRH},
  105. #endif
  106. #if STM32_HAS_GPIOG
  107. {VAL_GPIOG_MODER, VAL_GPIOG_OTYPER, VAL_GPIOG_OSPEEDR, VAL_GPIOG_PUPDR,
  108. VAL_GPIOG_ODR, VAL_GPIOG_AFRL, VAL_GPIOG_AFRH},
  109. #endif
  110. #if STM32_HAS_GPIOH
  111. {VAL_GPIOH_MODER, VAL_GPIOH_OTYPER, VAL_GPIOH_OSPEEDR, VAL_GPIOH_PUPDR,
  112. VAL_GPIOH_ODR, VAL_GPIOH_AFRL, VAL_GPIOH_AFRH},
  113. #endif
  114. #if STM32_HAS_GPIOI
  115. {VAL_GPIOI_MODER, VAL_GPIOI_OTYPER, VAL_GPIOI_OSPEEDR, VAL_GPIOI_PUPDR,
  116. VAL_GPIOI_ODR, VAL_GPIOI_AFRL, VAL_GPIOI_AFRH},
  117. #endif
  118. #if STM32_HAS_GPIOJ
  119. {VAL_GPIOJ_MODER, VAL_GPIOJ_OTYPER, VAL_GPIOJ_OSPEEDR, VAL_GPIOJ_PUPDR,
  120. VAL_GPIOJ_ODR, VAL_GPIOJ_AFRL, VAL_GPIOJ_AFRH},
  121. #endif
  122. #if STM32_HAS_GPIOK
  123. {VAL_GPIOK_MODER, VAL_GPIOK_OTYPER, VAL_GPIOK_OSPEEDR, VAL_GPIOK_PUPDR,
  124. VAL_GPIOK_ODR, VAL_GPIOK_AFRL, VAL_GPIOK_AFRH}
  125. #endif
  126. };
  127. /*===========================================================================*/
  128. /* Driver local functions. */
  129. /*===========================================================================*/
  130. static void gpio_init(stm32_gpio_t *gpiop, const gpio_setup_t *config) {
  131. gpiop->OTYPER = config->otyper;
  132. gpiop->OSPEEDR = config->ospeedr;
  133. gpiop->PUPDR = config->pupdr;
  134. gpiop->ODR = config->odr;
  135. gpiop->AFRL = config->afrl;
  136. gpiop->AFRH = config->afrh;
  137. gpiop->MODER = config->moder;
  138. }
  139. static void stm32_gpio_init(void) {
  140. /* Enabling GPIO-related clocks, the mask comes from the
  141. registry header file.*/
  142. rccResetAHB(STM32_GPIO_EN_MASK);
  143. rccEnableAHB(STM32_GPIO_EN_MASK, true);
  144. /* Initializing all the defined GPIO ports.*/
  145. #if STM32_HAS_GPIOA
  146. gpio_init(GPIOA, &gpio_default_config.PAData);
  147. #endif
  148. #if STM32_HAS_GPIOB
  149. gpio_init(GPIOB, &gpio_default_config.PBData);
  150. #endif
  151. #if STM32_HAS_GPIOC
  152. gpio_init(GPIOC, &gpio_default_config.PCData);
  153. #endif
  154. #if STM32_HAS_GPIOD
  155. gpio_init(GPIOD, &gpio_default_config.PDData);
  156. #endif
  157. #if STM32_HAS_GPIOE
  158. gpio_init(GPIOE, &gpio_default_config.PEData);
  159. #endif
  160. #if STM32_HAS_GPIOF
  161. gpio_init(GPIOF, &gpio_default_config.PFData);
  162. #endif
  163. #if STM32_HAS_GPIOG
  164. gpio_init(GPIOG, &gpio_default_config.PGData);
  165. #endif
  166. #if STM32_HAS_GPIOH
  167. gpio_init(GPIOH, &gpio_default_config.PHData);
  168. #endif
  169. #if STM32_HAS_GPIOI
  170. gpio_init(GPIOI, &gpio_default_config.PIData);
  171. #endif
  172. #if STM32_HAS_GPIOJ
  173. gpio_init(GPIOJ, &gpio_default_config.PJData);
  174. #endif
  175. #if STM32_HAS_GPIOK
  176. gpio_init(GPIOK, &gpio_default_config.PKData);
  177. #endif
  178. }
  179. /*===========================================================================*/
  180. /* Driver interrupt handlers. */
  181. /*===========================================================================*/
  182. /*===========================================================================*/
  183. /* Driver exported functions. */
  184. /*===========================================================================*/
  185. /**
  186. * @brief Early initialization code.
  187. * @details GPIO ports and system clocks are initialized before everything
  188. * else.
  189. */
  190. void __early_init(void) {
  191. stm32_gpio_init();
  192. stm32_clock_init();
  193. }
  194. #if HAL_USE_SDC || defined(__DOXYGEN__)
  195. /**
  196. * @brief SDC card detection.
  197. */
  198. bool sdc_lld_is_card_inserted(SDCDriver *sdcp) {
  199. (void)sdcp;
  200. /* TODO: Fill the implementation.*/
  201. return true;
  202. }
  203. /**
  204. * @brief SDC card write protection detection.
  205. */
  206. bool sdc_lld_is_write_protected(SDCDriver *sdcp) {
  207. (void)sdcp;
  208. /* TODO: Fill the implementation.*/
  209. return false;
  210. }
  211. #endif /* HAL_USE_SDC */
  212. #if HAL_USE_MMC_SPI || defined(__DOXYGEN__)
  213. /**
  214. * @brief MMC_SPI card detection.
  215. */
  216. bool mmc_lld_is_card_inserted(MMCDriver *mmcp) {
  217. (void)mmcp;
  218. /* TODO: Fill the implementation.*/
  219. return true;
  220. }
  221. /**
  222. * @brief MMC_SPI card write protection detection.
  223. */
  224. bool mmc_lld_is_write_protected(MMCDriver *mmcp) {
  225. (void)mmcp;
  226. /* TODO: Fill the implementation.*/
  227. return false;
  228. }
  229. #endif
  230. /**
  231. * @brief Board-specific initialization code.
  232. * @todo Add your board-specific code, if any.
  233. */
  234. void boardInit(void) {
  235. }