board.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. #ifndef _BOARD_H_
  14. #define _BOARD_H_
  15. /*
  16. * Setup for the LeafLabs Maple Mini.
  17. */
  18. /*
  19. * Board identifier.
  20. */
  21. #define BOARD_MAPLEMINI_STM32_F103
  22. #define BOARD_NAME "BluePill"
  23. /*
  24. * Board frequencies.
  25. */
  26. #define STM32_LSECLK 32768
  27. #define STM32_HSECLK 8000000
  28. /*
  29. * MCU type, supported types are defined in ./os/hal/platforms/hal_lld.h.
  30. */
  31. #define STM32F103xB
  32. /*
  33. * IO pins assignments
  34. */
  35. /* on-board */
  36. #define GPIOC_LED 13
  37. #define GPIOA_RELAY 0
  38. #define GPIOA_SSR 1
  39. #define LCD_LED_ON palClearLine(LINE_LCD_DC)
  40. #define LCD_LED_OFF palSetLine(LINE_LCD_DC)
  41. #define LINE_LED PAL_LINE(GPIOC, 13U)
  42. #define LINE_RELAY PAL_LINE(GPIOA, 0U)
  43. #define LINE_SSR PAL_LINE(GPIOA, 1U)
  44. /* Buttons */
  45. #define LINE_BTN_3 PAL_LINE(GPIOA, 8U)
  46. #define LINE_BTN_4 PAL_LINE(GPIOB, 15U)
  47. #define LINE_BTN_1 PAL_LINE(GPIOB, 14U)
  48. #define LINE_BTN_2 PAL_LINE(GPIOB, 13U)
  49. #define LINE_BTN_G PAL_LINE(GPIOB, 12U)
  50. #define BTNS_ON palClearLine(LINE_BTN_G)
  51. #define BTNS_OFF palSetLine(LINE_BTN_G)
  52. /* LCD */
  53. #define LINE_LED PAL_LINE(GPIOC, 13U)
  54. #define LINE_LCD_CS PAL_LINE(GPIOA, 4U)
  55. #define LINE_LCD_DC PAL_LINE(GPIOA, 6U)
  56. #define LCD_DC_CMD palClearLine(LINE_LCD_DC)
  57. #define LCD_DC_DATA palSetLine(LINE_LCD_DC)
  58. #define LCD_CS_RES palClearLine(LINE_LCD_CS)
  59. #define LCD_CS_SET palSetLine(LINE_LCD_CS)
  60. /* J1 connector */
  61. // pin 1: VBAT - Coin Cell 3V
  62. #define GPIOC_TAMPER_RTC 13 // pin 2 on-board LED
  63. #define GPIOC_OSC32_IN 14 // pin 3 on-board crystal 32kHz
  64. #define GPIOC_OSD32_OUT 15 // pin 4 on-board crystal 32kHz
  65. #define GPIOA_USART2_CTS 0 // pin 5 RELAY
  66. #define GPIOA_USART2_RTS 1 // pin 6 SSR
  67. #define GPIOA_PIN2 2 // pin 7 USART2_TX/ADC12_IN2/TIM2_CH3
  68. #define GPIOA_PIN3 3 // pin 8 USART2_RX/ADC12_IN3/TIM2_CH4
  69. #define GPIOA_SPI1_NSS 4 // pin 9 LCD_CS
  70. #define GPIOA_SPI1_SCK 5 // pin 10 LCD_SCL
  71. #define GPIOA_SPI1_MISO 6 // pin 11 LCD_DC
  72. #define GPIOA_SPI1_MOSI 7 // pin 12 LCD_SDA
  73. #define GPIOB_PIN0 0 // pin 13 ADC12_IN8/TIM3_CH3/TIM1_CH2N
  74. #define GPIOB_ADC12_IN9 1 // pin 14 ADC_IN
  75. #define GPIOB_PIN10 10 // pin 15 I2C2_SCL/USART3_TX/TIM2_CH3
  76. #define GPIOB_PIN11 11 // pin 16 I2C2_SDA/USART3_RX/TIM2_CH4
  77. // pin 17: RESET
  78. // pin 18: 3V3
  79. // pin 19: GND
  80. // pin 20: GND
  81. /* J2 connector */
  82. // pin 1: 3V3
  83. // pin 2: GND
  84. // pin 3: 5V
  85. #define GPIOB_PIN9 9 // pin 4 TIM4_CH4/I2C1_SDA/CANTX
  86. #define GPIOB_PIN8 8 // pin 5 TIM4_CH3/I2C1_SCL/CANRX
  87. #define GPIOB_PIN7 7 // pin 6 I2C1_SDA/TIM4_CH2/USART1_RX
  88. #define GPIOB_PIN6 6 // pin 7 I2C1_SCL/TIM4_CH1/USART1_TX
  89. #define GPIOB_PIN5 5 // pin 8 I2C1_SMBA/TIM3_CH2/SPI1_MOSI
  90. #define GPIOB_PIN4 4 // pin 9 TIM3_CH1/PB4/SPI1_MISO/JTRST
  91. #define GPIOB_PIN3 3 // pin 10 TIM2_CH2/PB3/TRACESWO/SPI1_SCK/JTDO
  92. #define GPIOA_PIN15 15 // pin 11 TIM2_CH1_ETR/SPI1_NSS/JTDI
  93. #define GPIOA_USBDP 12 // pin 12 USART1_RTS/CANTX/TIM1_ETR
  94. #define GPIOA_USBDM 11 // pin 13 USART1_CTS/CANRX/TIM1_CH4
  95. #define GPIOA_USART1_RX 10 // pin 14 TIM1_CH3
  96. #define GPIOA_USART1_TX 9 // pin 15 TIM1_CH2
  97. #define GPIOA_USART1_CK 8 // pin 16 BTN_4
  98. #define GPIOB_SPI2_MOSI 15 // pin 17 BTN_3
  99. #define GPIOB_SPI2_MISO 14 // pin 18 BTN_2
  100. #define GPIOB_SPI2_SCK 13 // pin 19 BTN_1
  101. #define GPIOB_SPI2_NSS 12 // pin 20 BTN_GND
  102. /*
  103. * I/O ports initial setup, this configuration is established soon after reset
  104. * in the initialization code.
  105. *
  106. * The digits have the following meaning:
  107. * 0 - Analog input.
  108. * 1 - Push Pull output 10MHz.
  109. * 2 - Push Pull output 2MHz.
  110. * 3 - Push Pull output 50MHz.
  111. * 4 - Digital input.
  112. * 5 - Open Drain output 10MHz.
  113. * 6 - Open Drain output 2MHz.
  114. * 7 - Open Drain output 50MHz.
  115. * 8 - Digital input with PullUp or PullDown resistor depending on ODR.
  116. * 9 - Alternate Push Pull output 10MHz.
  117. * A - Alternate Push Pull output 2MHz.
  118. * B - Alternate Push Pull output 50MHz.
  119. * C - Reserved.
  120. * D - Alternate Open Drain output 10MHz.
  121. * E - Alternate Open Drain output 2MHz.
  122. * F - Alternate Open Drain output 50MHz.
  123. * Please refer to the STM32 Reference Manual for details.
  124. */
  125. /*
  126. * Port A setup.
  127. * Everything input with pull-up except:
  128. * PA0 - Push Pull output (LCD_RELAY).
  129. * PA1 - Push Pull output (LCD_SSR).
  130. * PA4 - Push Pull output (LCD_CS).
  131. * PA5 - Alternate output (LCD_SCL - SPI1 SCK).
  132. * PA6 - Push Pull output (LCD_DC).
  133. * PA7 - Alternate output (LCD_DSA - SPI1 MOSI).
  134. * PA8 - Input with Pull-Up (BTN_1)
  135. */
  136. #define VAL_GPIOACRL 0xB3B38833 /* PA7...PA0 */
  137. #define VAL_GPIOACRH 0x88888888 /* PA15...PA8 */
  138. #define VAL_GPIOAODR 0xFFFFFFFF
  139. /*
  140. * Port B setup.
  141. * Everything input with pull-up except:
  142. * PB1 - Analog Input (ADC_IN)
  143. * PB15 - Input with Pull-Up (BTN_2)
  144. * PB14 - Input with Pull-Up (BTN_3)
  145. * PB13 - Input with Pull-Up (BTN_4)
  146. * PB12 - Push Pull output (BTN_G)
  147. */
  148. #define VAL_GPIOBCRL 0x88888808 /* PB7...PB0 */
  149. #define VAL_GPIOBCRH 0x88838888 /* PB15...PB8 */
  150. #define VAL_GPIOBODR 0xFFFFFFFF
  151. /*
  152. * Port C setup.
  153. * Everything input with pull-up except:
  154. * PC13 - Push Pull output (LED).
  155. */
  156. #define VAL_GPIOCCRL 0x88888888 /* PC7...PC0 */
  157. #define VAL_GPIOCCRH 0x88288888 /* PC15...PC8 */
  158. #define VAL_GPIOCODR 0xFFFFFFFF
  159. /*
  160. * Port D setup.
  161. * Everything input with pull-up except:
  162. * PD0 - Normal input (XTAL).
  163. * PD1 - Normal input (XTAL).
  164. */
  165. #define VAL_GPIODCRL 0x88888844 /* PD7...PD0 */
  166. #define VAL_GPIODCRH 0x88888888 /* PD15...PD8 */
  167. #define VAL_GPIODODR 0xFFFFFFFF
  168. /*
  169. * Port E setup.
  170. * Everything input with pull-up except:
  171. */
  172. #define VAL_GPIOECRL 0x88888888 /* PE7...PE0 */
  173. #define VAL_GPIOECRH 0x88888888 /* PE15...PE8 */
  174. #define VAL_GPIOEODR 0xFFFFFFFF
  175. /*
  176. * USB bus activation macro, required by the USB driver.
  177. */
  178. #define usb_lld_connect_bus(usbp) palClearPad(GPIOB, GPIOB_USB_DISC)
  179. /*
  180. * USB bus de-activation macro, required by the USB driver.
  181. */
  182. #define usb_lld_disconnect_bus(usbp) palSetPad(GPIOB, GPIOB_USB_DISC)
  183. #if !defined(_FROM_ASM_)
  184. #ifdef __cplusplus
  185. extern "C" {
  186. #endif
  187. void boardInit(void);
  188. #ifdef __cplusplus
  189. }
  190. #endif
  191. #endif /* _FROM_ASM_ */
  192. #endif /* _BOARD_H_ */