board.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * board.c
  3. *
  4. * Board-specific setup and management.
  5. *
  6. * Written & released by Keir Fraser <keir.xen@gmail.com>
  7. *
  8. * This is free and unencumbered software released into the public domain.
  9. * See the file COPYING for more details, or visit <http://unlicense.org>.
  10. */
  11. #if STM32F == 1
  12. #define gpio_led gpioc
  13. #define pin_led 13
  14. #elif STM32F == 7
  15. #define gpio_led gpiob
  16. #define pin_led 13
  17. #endif
  18. /* Pull up currently unused and possibly-floating pins. */
  19. static void gpio_pull_up_pins(GPIO gpio, uint16_t mask)
  20. {
  21. unsigned int i;
  22. for (i = 0; i < 16; i++) {
  23. if (mask & 1)
  24. gpio_configure_pin(gpio, i, GPI_pull_up);
  25. mask >>= 1;
  26. }
  27. }
  28. void board_init(void)
  29. {
  30. /* Pull up all unused pins. */
  31. if (STM32F == 1) {
  32. gpio_pull_up_pins(gpioa, 0xe1fe); /* PA1-8,13-15 */
  33. gpio_pull_up_pins(gpiob, 0x0027); /* PB0-2,5 */
  34. gpio_pull_up_pins(gpioc, 0xffff); /* PC0-15 */
  35. } else if (STM32F == 7) {
  36. gpio_pull_up_pins(gpioa, 0x9930); /* PA4-5,8,11-12,15 */
  37. gpio_pull_up_pins(gpiob, 0x23f8); /* PB3-9,13 */
  38. gpio_pull_up_pins(gpioc, 0xffe7); /* PC0-2,5-15 */
  39. }
  40. #ifdef NDEBUG
  41. /* Pull up unused debug pins (A9,A10 = serial console). */
  42. gpio_pull_up_pins(gpioa, (1u<<9) | (1u<<10));
  43. #endif
  44. /* Activity LED is active low. */
  45. gpio_configure_pin(gpio_led, pin_led, GPO_pushpull(IOSPD_LOW, HIGH));
  46. }
  47. /* Set the activity LED status. */
  48. void act_led(bool_t on)
  49. {
  50. gpio_write_pin(gpio_led, pin_led, on ? LOW : HIGH);
  51. }
  52. /*
  53. * Local variables:
  54. * mode: C
  55. * c-file-style: "Linux"
  56. * c-basic-offset: 4
  57. * tab-width: 4
  58. * indent-tabs-mode: nil
  59. * End:
  60. */