board.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. #include "hal.h"
  14. /**
  15. * @brief PAL setup.
  16. * @details Digital I/O ports static configuration as defined in @p board.h.
  17. * This variable is used by the HAL when initializing the PAL driver.
  18. */
  19. #if HAL_USE_PAL || defined(__DOXYGEN__)
  20. const PALConfig pal_default_config =
  21. {
  22. {VAL_GPIOAODR, VAL_GPIOACRL, VAL_GPIOACRH},
  23. {VAL_GPIOBODR, VAL_GPIOBCRL, VAL_GPIOBCRH},
  24. {VAL_GPIOCODR, VAL_GPIOCCRL, VAL_GPIOCCRH},
  25. {VAL_GPIODODR, VAL_GPIODCRL, VAL_GPIODCRH},
  26. {VAL_GPIOEODR, VAL_GPIOECRL, VAL_GPIOECRH},
  27. };
  28. #endif
  29. /*
  30. * Early initialization code.
  31. * This initialization must be performed just after stack setup and before
  32. * any other initialization.
  33. */
  34. void __early_init(void) {
  35. stm32_clock_init();
  36. }
  37. #if HAL_USE_MMC_SPI
  38. /*
  39. * Card detection through the card internal pull-up on D3.
  40. */
  41. bool mmc_lld_is_card_inserted(MMCDriver *mmcp) {
  42. static bool last_status = FALSE;
  43. (void)mmcp;
  44. if ((palReadLatch(GPIOA) & PAL_PORT_BIT(GPIOA_SPI3_CS_MMC)) == 0)
  45. return last_status;
  46. return last_status = (bool)palReadPad(GPIOA, GPIOA_SPI3_CS_MMC);
  47. }
  48. /*
  49. * Card write protection detection is not possible, the card is always
  50. * reported as not protected.
  51. */
  52. bool mmc_lld_is_write_protected(MMCDriver *mmcp) {
  53. (void)mmcp;
  54. return FALSE;
  55. }
  56. #endif
  57. /*
  58. * Board-specific initialization code.
  59. */
  60. void boardInit(void) {
  61. /*
  62. * Several I/O pins are re-mapped:
  63. * USART3 to the PD8/PD9 pins.
  64. * I2C1 to the PB8/PB9 pins.
  65. * SPI3 to the PC10/PC11/PC12 pins.
  66. */
  67. AFIO->MAPR |= AFIO_MAPR_USART3_REMAP_FULLREMAP |
  68. AFIO_MAPR_I2C1_REMAP |
  69. AFIO_MAPR_SPI3_REMAP;
  70. }