board.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. } gpio_config_t;
  69. /**
  70. * @brief STM32 GPIO static initialization data.
  71. */
  72. static const gpio_config_t gpio_default_config = {
  73. #if STM32_HAS_GPIOA
  74. {VAL_GPIOA_MODER, VAL_GPIOA_OTYPER, VAL_GPIOA_OSPEEDR, VAL_GPIOA_PUPDR,
  75. VAL_GPIOA_ODR, VAL_GPIOA_AFRL, VAL_GPIOA_AFRH},
  76. #endif
  77. #if STM32_HAS_GPIOB
  78. {VAL_GPIOB_MODER, VAL_GPIOB_OTYPER, VAL_GPIOB_OSPEEDR, VAL_GPIOB_PUPDR,
  79. VAL_GPIOB_ODR, VAL_GPIOB_AFRL, VAL_GPIOB_AFRH},
  80. #endif
  81. #if STM32_HAS_GPIOC
  82. {VAL_GPIOC_MODER, VAL_GPIOC_OTYPER, VAL_GPIOC_OSPEEDR, VAL_GPIOC_PUPDR,
  83. VAL_GPIOC_ODR, VAL_GPIOC_AFRL, VAL_GPIOC_AFRH},
  84. #endif
  85. #if STM32_HAS_GPIOD
  86. {VAL_GPIOD_MODER, VAL_GPIOD_OTYPER, VAL_GPIOD_OSPEEDR, VAL_GPIOD_PUPDR,
  87. VAL_GPIOD_ODR, VAL_GPIOD_AFRL, VAL_GPIOD_AFRH},
  88. #endif
  89. #if STM32_HAS_GPIOE
  90. {VAL_GPIOE_MODER, VAL_GPIOE_OTYPER, VAL_GPIOE_OSPEEDR, VAL_GPIOE_PUPDR,
  91. VAL_GPIOE_ODR, VAL_GPIOE_AFRL, VAL_GPIOE_AFRH},
  92. #endif
  93. #if STM32_HAS_GPIOF
  94. {VAL_GPIOF_MODER, VAL_GPIOF_OTYPER, VAL_GPIOF_OSPEEDR, VAL_GPIOF_PUPDR,
  95. VAL_GPIOF_ODR, VAL_GPIOF_AFRL, VAL_GPIOF_AFRH},
  96. #endif
  97. #if STM32_HAS_GPIOG
  98. {VAL_GPIOG_MODER, VAL_GPIOG_OTYPER, VAL_GPIOG_OSPEEDR, VAL_GPIOG_PUPDR,
  99. VAL_GPIOG_ODR, VAL_GPIOG_AFRL, VAL_GPIOG_AFRH},
  100. #endif
  101. #if STM32_HAS_GPIOH
  102. {VAL_GPIOH_MODER, VAL_GPIOH_OTYPER, VAL_GPIOH_OSPEEDR, VAL_GPIOH_PUPDR,
  103. VAL_GPIOH_ODR, VAL_GPIOH_AFRL, VAL_GPIOH_AFRH},
  104. #endif
  105. };
  106. /*===========================================================================*/
  107. /* Driver local functions. */
  108. /*===========================================================================*/
  109. static void gpio_init(stm32_gpio_t *gpiop, const gpio_setup_t *config) {
  110. gpiop->OTYPER = config->otyper;
  111. gpiop->OSPEEDR = config->ospeedr;
  112. gpiop->PUPDR = config->pupdr;
  113. gpiop->ODR = config->odr;
  114. gpiop->AFRL = config->afrl;
  115. gpiop->AFRH = config->afrh;
  116. gpiop->MODER = config->moder;
  117. }
  118. static void stm32_gpio_init(void) {
  119. /* Enabling GPIO-related clocks, the mask comes from the
  120. registry header file.*/
  121. rccResetAHB1(STM32_GPIO_EN_MASK);
  122. rccEnableAHB1(STM32_GPIO_EN_MASK, true);
  123. /* Initializing all the defined GPIO ports.*/
  124. #if STM32_HAS_GPIOA
  125. gpio_init(GPIOA, &gpio_default_config.PAData);
  126. #endif
  127. #if STM32_HAS_GPIOB
  128. gpio_init(GPIOB, &gpio_default_config.PBData);
  129. #endif
  130. #if STM32_HAS_GPIOC
  131. gpio_init(GPIOC, &gpio_default_config.PCData);
  132. #endif
  133. #if STM32_HAS_GPIOD
  134. gpio_init(GPIOD, &gpio_default_config.PDData);
  135. #endif
  136. #if STM32_HAS_GPIOE
  137. gpio_init(GPIOE, &gpio_default_config.PEData);
  138. #endif
  139. #if STM32_HAS_GPIOF
  140. gpio_init(GPIOF, &gpio_default_config.PFData);
  141. #endif
  142. #if STM32_HAS_GPIOG
  143. gpio_init(GPIOG, &gpio_default_config.PGData);
  144. #endif
  145. #if STM32_HAS_GPIOH
  146. gpio_init(GPIOH, &gpio_default_config.PHData);
  147. #endif
  148. }
  149. /*===========================================================================*/
  150. /* Driver interrupt handlers. */
  151. /*===========================================================================*/
  152. /*===========================================================================*/
  153. /* Driver exported functions. */
  154. /*===========================================================================*/
  155. /**
  156. * @brief Early initialization code.
  157. * @details GPIO ports and system clocks are initialized before everything
  158. * else.
  159. */
  160. void __early_init(void) {
  161. stm32_gpio_init();
  162. stm32_clock_init();
  163. }
  164. #if HAL_USE_SDC || defined(__DOXYGEN__)
  165. /**
  166. * @brief SDC card detection.
  167. */
  168. bool sdc_lld_is_card_inserted(SDCDriver *sdcp) {
  169. (void)sdcp;
  170. /* TODO: Fill the implementation.*/
  171. return true;
  172. }
  173. /**
  174. * @brief SDC card write protection detection.
  175. */
  176. bool sdc_lld_is_write_protected(SDCDriver *sdcp) {
  177. (void)sdcp;
  178. /* TODO: Fill the implementation.*/
  179. return false;
  180. }
  181. #endif /* HAL_USE_SDC */
  182. #if HAL_USE_MMC_SPI || defined(__DOXYGEN__)
  183. /**
  184. * @brief MMC_SPI card detection.
  185. */
  186. bool mmc_lld_is_card_inserted(MMCDriver *mmcp) {
  187. (void)mmcp;
  188. /* TODO: Fill the implementation.*/
  189. return true;
  190. }
  191. /**
  192. * @brief MMC_SPI card write protection detection.
  193. */
  194. bool mmc_lld_is_write_protected(MMCDriver *mmcp) {
  195. (void)mmcp;
  196. /* TODO: Fill the implementation.*/
  197. return false;
  198. }
  199. #endif
  200. /**
  201. * @brief Board-specific initialization code.
  202. * @todo Add your board-specific code, if any.
  203. */
  204. void boardInit(void) {
  205. }