PD Buddy Sink Firmware
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

board.c 8.2KB

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