board.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. ROMCONST PALConfig pal_default_config =
  21. {
  22. {
  23. {VAL_GPIOAODR, 0, VAL_GPIOADDR, VAL_GPIOACR1, VAL_GPIOACR2},
  24. {VAL_GPIOBODR, 0, VAL_GPIOBDDR, VAL_GPIOBCR1, VAL_GPIOBCR2},
  25. {VAL_GPIOCODR, 0, VAL_GPIOCDDR, VAL_GPIOCCR1, VAL_GPIOCCR2},
  26. {VAL_GPIODODR, 0, VAL_GPIODDDR, VAL_GPIODCR1, VAL_GPIODCR2},
  27. {VAL_GPIOEODR, 0, VAL_GPIOEDDR, VAL_GPIOECR1, VAL_GPIOECR2},
  28. {VAL_GPIOFODR, 0, VAL_GPIOFDDR, VAL_GPIOFCR1, VAL_GPIOFCR2},
  29. }
  30. };
  31. #endif
  32. /*
  33. * TIM 2 clock after the prescaler.
  34. */
  35. #define TIM2_CLOCK (SYSCLK / 16)
  36. #define TIM2_ARR ((TIM2_CLOCK / CH_FREQUENCY) - 1)
  37. /*
  38. * Board-specific initialization code.
  39. */
  40. void boardInit(void) {
  41. /*
  42. * TIM2 initialization as system tick.
  43. */
  44. CLK->PCKENR1 |= CLK_PCKENR1_TIM2;
  45. TIM2->PSCR = 4; /* Prescaler divide by 2^4=16.*/
  46. TIM2->ARRH = (uint8_t)(TIM2_ARR >> 8);
  47. TIM2->ARRL = (uint8_t)(TIM2_ARR);
  48. TIM2->CNTRH = 0;
  49. TIM2->CNTRL = 0;
  50. TIM2->SR1 = 0;
  51. TIM2->IER = TIM_IER_UIE;
  52. TIM2->CR1 = TIM_CR1_CEN;
  53. }