board.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. #define LINE_STAB_OFF PAL_LINE(GPIOA, 2U)
  45. #define LINE_RAZGON_OFF PAL_LINE(GPIOA, 3U)
  46. /* Buttons */
  47. #define LINE_BTN_4 PAL_LINE(GPIOA, 8U)
  48. #define LINE_BTN_3 PAL_LINE(GPIOB, 15U)
  49. #define LINE_BTN_2 PAL_LINE(GPIOB, 14U)
  50. #define LINE_BTN_1 PAL_LINE(GPIOB, 13U)
  51. #define LINE_BTN_G PAL_LINE(GPIOB, 12U)
  52. #define BTNS_ON palClearLine(LINE_BTN_G)
  53. #define BTNS_OFF palSetLine(LINE_BTN_G)
  54. /* LCD */
  55. #define LINE_LED PAL_LINE(GPIOC, 13U)
  56. #define LINE_LCD_CS PAL_LINE(GPIOA, 4U)
  57. #define LINE_LCD_DC PAL_LINE(GPIOA, 6U)
  58. #define LCD_DC_CMD palClearLine(LINE_LCD_DC)
  59. #define LCD_DC_DATA palSetLine(LINE_LCD_DC)
  60. #define LCD_CS_RES palClearLine(LINE_LCD_CS)
  61. #define LCD_CS_SET palSetLine(LINE_LCD_CS)
  62. /* J1 connector */
  63. // pin 1: VBAT - Coin Cell 3V
  64. #define GPIOC_TAMPER_RTC 13 // pin 2
  65. #define GPIOC_OSC32_IN 14 // pin 3
  66. #define GPIOC_OSD32_OUT 15 // pin 4
  67. #define GPIOA_USART2_CTS 0 // pin 5 RELAY
  68. #define GPIOA_USART2_RTS 1 // pin 6 SSR
  69. #define GPIOA_USART2_TX 2 // pin 7 STAB_OFF
  70. #define GPIOA_USART2_RX 3 // pin 8 RAZGON_OFF
  71. #define GPIOA_SPI1_NSS 4 // pin 9 LCD_CS
  72. #define GPIOA_SPI1_SCK 5 // pin 10 LCD_SCL
  73. #define GPIOA_SPI1_MISO 6 // pin 11 LCD_DC
  74. #define GPIOA_SPI1_MOSI 7 // pin 12 LCD_SDA
  75. #define GPIOB_ADC12_IN8 0 // pin 13
  76. #define GPIOB_ADC12_IN9 1 // pin 14 ADC_IN
  77. #define GPIOB_I2C2_SCL 10 // pin 15
  78. #define GPIOB_I2C2_SDA 11 // pin 16
  79. // pin 17: RESET
  80. // pin 18: 3V3
  81. // pin 19: GND
  82. // pin 20: GND
  83. /* J2 connector */
  84. // pin 1: 3V3
  85. // pin 2: GND
  86. // pin 3: 5V
  87. #define GPIOB_PIN9 9 // pin 4 TIM4_CH4/I2C1_SDA/CANTX
  88. #define GPIOB_PIN8 8 // pin 5 TIM4_CH3/I2C1_SCL/CANRX
  89. #define GPIOB_PIN7 7 // pin 6 I2C1_SDA/TIM4_CH2/USART1_RX
  90. #define GPIOB_PIN6 6 // pin 7 I2C1_SCL/TIM4_CH1/USART1_TX
  91. #define GPIOB_PIN5 5 // pin 8 I2C1_SMBA/TIM3_CH2/SPI1_MOSI
  92. #define GPIOB_JTRST 4 // pin 9 TIM3_CH1/PB4/SPI1_MISO
  93. #define GPIOB_JTDO 3 // pin 10 TIM2_CH2/PB3/TRACESWO/SPI1_SCK
  94. #define GPIOA_JTDI 15 // pin 11
  95. #define GPIOA_USBDP 12 // pin 12
  96. #define GPIOA_USBDM 11 // pin 13
  97. #define GPIOA_USART1_RX 10 // pin 14
  98. #define GPIOA_USART1_TX 9 // pin 15
  99. #define GPIOA_USART1_CK 8 // pin 16 BTN_4
  100. #define GPIOB_SPI2_MOSI 15 // pin 17 BTN_3
  101. #define GPIOB_SPI2_MISO 14 // pin 18 BTN_2
  102. #define GPIOB_SPI2_SCK 13 // pin 19 BTN_1
  103. #define GPIOB_SPI2_NSS 12 // pin 20 BTN_GND
  104. /*
  105. * I/O ports initial setup, this configuration is established soon after reset
  106. * in the initialization code.
  107. *
  108. * The digits have the following meaning:
  109. * 0 - Analog input.
  110. * 1 - Push Pull output 10MHz.
  111. * 2 - Push Pull output 2MHz.
  112. * 3 - Push Pull output 50MHz.
  113. * 4 - Digital input.
  114. * 5 - Open Drain output 10MHz.
  115. * 6 - Open Drain output 2MHz.
  116. * 7 - Open Drain output 50MHz.
  117. * 8 - Digital input with PullUp or PullDown resistor depending on ODR.
  118. * 9 - Alternate Push Pull output 10MHz.
  119. * A - Alternate Push Pull output 2MHz.
  120. * B - Alternate Push Pull output 50MHz.
  121. * C - Reserved.
  122. * D - Alternate Open Drain output 10MHz.
  123. * E - Alternate Open Drain output 2MHz.
  124. * F - Alternate Open Drain output 50MHz.
  125. * Please refer to the STM32 Reference Manual for details.
  126. */
  127. /*
  128. * Port A setup.
  129. * Everything input with pull-up except:
  130. * PA0 - Push Pull output (LCD_RELAY).
  131. * PA1 - Push Pull output (LCD_SSR).
  132. * PA2 - Input with Pull-Up (STAB_OFF)
  133. * PA3 - Input with Pull-Up (RAZGON_OFF)
  134. * PA4 - Push Pull output (LCD_CS).
  135. * PA5 - Alternate output (LCD_SCL - SPI1 SCK).
  136. * PA6 - Push Pull output (LCD_DC).
  137. * PA7 - Alternate output (LCD_DSA - SPI1 MOSI).
  138. * PA8 - Input with Pull-Up (BTN_1)
  139. */
  140. #define VAL_GPIOACRL 0xB3B38833 /* PA7...PA0 */
  141. #define VAL_GPIOACRH 0x88888888 /* PA15...PA8 */
  142. #define VAL_GPIOAODR 0xFFFFFFFF
  143. /*
  144. * Port B setup.
  145. * Everything input with pull-up except:
  146. * PB1 - Analog Input (ADC_IN)
  147. * PB15 - Input with Pull-Up (BTN_2)
  148. * PB14 - Input with Pull-Up (BTN_3)
  149. * PB13 - Input with Pull-Up (BTN_4)
  150. * PB12 - Push Pull output (BTN_G)
  151. */
  152. #define VAL_GPIOBCRL 0x88888808 /* PB7...PB0 */
  153. #define VAL_GPIOBCRH 0x88838888 /* PB15...PB8 */
  154. #define VAL_GPIOBODR 0xFFFFFFFF
  155. /*
  156. * Port C setup.
  157. * Everything input with pull-up except:
  158. * PC13 - Push Pull output (LED).
  159. */
  160. #define VAL_GPIOCCRL 0x88888888 /* PC7...PC0 */
  161. #define VAL_GPIOCCRH 0x88288888 /* PC15...PC8 */
  162. #define VAL_GPIOCODR 0xFFFFFFFF
  163. /*
  164. * Port D setup.
  165. * Everything input with pull-up except:
  166. * PD0 - Normal input (XTAL).
  167. * PD1 - Normal input (XTAL).
  168. */
  169. #define VAL_GPIODCRL 0x88888844 /* PD7...PD0 */
  170. #define VAL_GPIODCRH 0x88888888 /* PD15...PD8 */
  171. #define VAL_GPIODODR 0xFFFFFFFF
  172. /*
  173. * Port E setup.
  174. * Everything input with pull-up except:
  175. */
  176. #define VAL_GPIOECRL 0x88888888 /* PE7...PE0 */
  177. #define VAL_GPIOECRH 0x88888888 /* PE15...PE8 */
  178. #define VAL_GPIOEODR 0xFFFFFFFF
  179. /*
  180. * USB bus activation macro, required by the USB driver.
  181. */
  182. #define usb_lld_connect_bus(usbp) palClearPad(GPIOB, GPIOB_USB_DISC)
  183. /*
  184. * USB bus de-activation macro, required by the USB driver.
  185. */
  186. #define usb_lld_disconnect_bus(usbp) palSetPad(GPIOB, GPIOB_USB_DISC)
  187. #if !defined(_FROM_ASM_)
  188. #ifdef __cplusplus
  189. extern "C" {
  190. #endif
  191. void boardInit(void);
  192. #ifdef __cplusplus
  193. }
  194. #endif
  195. #endif /* _FROM_ASM_ */
  196. #endif /* _BOARD_H_ */