board.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. /*
  2. * Copyright (c) 2006-2025, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2025-01-22 RealThread first version
  9. */
  10. #ifndef __BOARD_H__
  11. #define __BOARD_H__
  12. #include <stm32f1xx.h>
  13. #include <drv_common.h>
  14. #ifdef __cplusplus
  15. extern "C"
  16. {
  17. #endif
  18. /*-------------------------- CHIP CONFIG BEGIN --------------------------*/
  19. #define CHIP_FAMILY_STM32
  20. #define CHIP_SERIES_STM32F1
  21. #define CHIP_NAME_STM32F103RE
  22. /*-------------------------- CHIP CONFIG END --------------------------*/
  23. /*-------------------------- ROM/RAM CONFIG BEGIN --------------------------*/
  24. #define ROM_START ((uint32_t)0x08000000)
  25. #define ROM_SIZE (512 * 1024)
  26. #define ROM_END ((uint32_t)(ROM_START + ROM_SIZE))
  27. #define RAM_START (0x20000000)
  28. #define RAM_SIZE (128 * 1024) //stm32 ram=64kb
  29. #define RAM_END (RAM_START + RAM_SIZE)
  30. /*-------------------------- ROM/RAM CONFIG END --------------------------*/
  31. /*-------------------------- CLOCK CONFIG BEGIN --------------------------*/
  32. #define BSP_CLOCK_SOURCE ("HSE")
  33. #define BSP_CLOCK_SOURCE_FREQ_MHZ ((int32_t)8)
  34. #define BSP_CLOCK_SYSTEM_FREQ_MHZ ((int32_t)96)
  35. /*-------------------------- CLOCK CONFIG END --------------------------*/
  36. /*-------------------------- UART CONFIG BEGIN --------------------------*/
  37. /** After configuring corresponding UART or UART DMA, you can use it.
  38. *
  39. * STEP 1, define macro define related to the serial port opening based on the serial port number
  40. * such as #define BSP_USING_UART1
  41. *
  42. * STEP 2, according to the corresponding pin of serial port, define the related serial port information macro
  43. * such as #define BSP_UART1_TX_PIN "PA9"
  44. * #define BSP_UART1_RX_PIN "PA10"
  45. *
  46. * STEP 3, if you want using SERIAL DMA, you must open it in the RT-Thread Settings.
  47. * RT-Thread Setting -> Components -> Device Drivers -> Serial Device Drivers -> Enable Serial DMA Mode
  48. *
  49. * STEP 4, according to serial port number to define serial port tx/rx DMA function in the board.h file
  50. * such as #define BSP_UART1_RX_USING_DMA
  51. *
  52. */
  53. #define BSP_USING_UART1 //调试
  54. #define BSP_UART1_TX_PIN "PA9"
  55. #define BSP_UART1_RX_PIN "PA10"
  56. #define BSP_UART1_RX_BUFSIZE 64
  57. #define BSP_UART1_TX_BUFSIZE 0
  58. #define BSP_USING_UART2 //通讯
  59. #define BSP_UART2_TX_PIN "PA2"
  60. #define BSP_UART2_RX_PIN "PA3"
  61. #define BSP_UART2_RX_BUFSIZE 2000
  62. #define BSP_UART2_TX_BUFSIZE 2000
  63. //#define BSP_USING_UART3 //
  64. //#define BSP_UART3_TX_PIN "PB10"
  65. //#define BSP_UART3_RX_PIN "PB11"
  66. #define BSP_USING_UART4 //屏幕
  67. #define BSP_UART4_TX_PIN "PC10"
  68. #define BSP_UART4_RX_PIN "PC11"
  69. #define BSP_UART4_RX_BUFSIZE 512
  70. #define BSP_UART4_TX_BUFSIZE 1024
  71. #define BSP_USING_UART5 //485
  72. #define BSP_UART5_TX_PIN "PC12"
  73. #define BSP_UART5_RX_PIN "PD2"
  74. #define BSP_UART5_RX_BUFSIZE 128
  75. #define BSP_UART5_TX_BUFSIZE 128
  76. #define BSP_UART4_RX_USING_DMA
  77. #define BSP_UART4_TX_USING_DMA
  78. #define BSP_UART2_RX_USING_DMA
  79. #define BSP_UART2_TX_USING_DMA
  80. /*-------------------------- UART CONFIG END --------------------------*/
  81. /*-------------------------- I2C CONFIG BEGIN --------------------------*/
  82. /** if you want to use i2c bus(soft simulate) you can use the following instructions.
  83. *
  84. * STEP 1, open i2c driver framework(soft simulate) support in the RT-Thread Settings file
  85. *
  86. * STEP 2, define macro related to the i2c bus
  87. * such as #define BSP_USING_I2C1
  88. *
  89. * STEP 3, according to the corresponding pin of i2c port, modify the related i2c port and pin information
  90. * such as #define BSP_I2C1_SCL_PIN GET_PIN(port, pin) -> GET_PIN(C, 11)
  91. * #define BSP_I2C1_SDA_PIN GET_PIN(port, pin) -> GET_PIN(C, 12)
  92. */
  93. /*#define BSP_USING_I2C1*/
  94. #ifdef BSP_USING_I2C1
  95. #define BSP_I2C1_SCL_PIN GET_PIN(port, pin)
  96. #define BSP_I2C1_SDA_PIN GET_PIN(port, pin)
  97. #endif
  98. /*#define BSP_USING_I2C2*/
  99. #ifdef BSP_USING_I2C2
  100. #define BSP_I2C2_SCL_PIN GET_PIN(port, pin)
  101. #define BSP_I2C2_SDA_PIN GET_PIN(port, pin)
  102. #endif
  103. /*-------------------------- I2C CONFIG END --------------------------*/
  104. /*-------------------------- SPI CONFIG BEGIN --------------------------*/
  105. /** if you want to use spi bus you can use the following instructions.
  106. *
  107. * STEP 1, open spi driver framework support in the RT-Thread Settings file
  108. *
  109. * STEP 2, define macro related to the spi bus
  110. * such as #define BSP_USING_SPI1
  111. *
  112. * STEP 3, copy your spi init function from stm32xxxx_hal_msp.c generated by stm32cubemx to the end of board.c file
  113. * such as void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
  114. *
  115. * STEP 4, modify your stm32xxxx_hal_config.h file to support spi peripherals. define macro related to the peripherals
  116. * such as #define HAL_SPI_MODULE_ENABLED
  117. */
  118. #define BSP_USING_SPI1
  119. /*#define BSP_USING_SPI2*/
  120. /*#define BSP_USING_SPI3*/
  121. /*-------------------------- SPI CONFIG END --------------------------*/
  122. /*-------------------------- QSPI CONFIG BEGIN --------------------------*/
  123. /** if you want to use qspi you can use the following instructions.
  124. *
  125. * STEP 1, open qspi driver framework support in the RT-Thread Settings file
  126. *
  127. * STEP 2, define macro related to the qspi
  128. * such as #define BSP_USING_QSPI
  129. *
  130. * STEP 3, copy your qspi init function from stm32xxxx_hal_msp.c generated by stm32cubemx to the end of board.c file
  131. * such as void HAL_QSPI_MspInit(QSPI_HandleTypeDef* hqspi)
  132. *
  133. * STEP 4, modify your stm32xxxx_hal_config.h file to support qspi peripherals. define macro related to the peripherals
  134. * such as #define HAL_QSPI_MODULE_ENABLED
  135. *
  136. */
  137. /*#define BSP_USING_QSPI*/
  138. /*-------------------------- QSPI CONFIG END --------------------------*/
  139. /*-------------------------- PWM CONFIG BEGIN --------------------------*/
  140. /** if you want to use pwm you can use the following instructions.
  141. *
  142. * STEP 1, open pwm driver framework support in the RT-Thread Settings file
  143. *
  144. * STEP 2, define macro related to the pwm
  145. * such as #define BSP_USING_PWM1
  146. *
  147. * STEP 3, copy your pwm timer init function from stm32xxxx_hal_msp.c generated by stm32cubemx to the end if board.c file
  148. * such as void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base) and
  149. * void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
  150. *
  151. * STEP 4, modify your stm32xxxx_hal_config.h file to support pwm peripherals. define macro related to the peripherals
  152. * such as #define HAL_TIM_MODULE_ENABLED
  153. *
  154. */
  155. /*#define BSP_USING_PWM1*/
  156. /*#define BSP_USING_PWM2*/
  157. #define BSP_USING_PWM3
  158. #define BSP_USING_PWM8
  159. /* ★ 必须同时声明通道, 否则 drv_pwm.c 的 pwm_get_channel() 得到 channel = 0,
  160. stm32_hw_pwm_init() 里 4 个 if(device->channel & 0x0x) 全不成立,
  161. HAL_TIM_PWM_ConfigChannel() 一次都不会被调用 —— PWM 输出只能靠 board.c 里
  162. MX_TIM3_Init()/MX_TIM8_Init() 的残留配置, 属于隐式耦合。
  163. 下面的通道号与实际用点严格对应:
  164. TIM3(设备 "pwm3"): CH1 蜂鸣器/步进脉冲(beep.h BEEP_PWM_CH=1)
  165. CH2 清扫左电机(control.c pwm_on(2,...))
  166. CH3 清扫右电机(control.c pwm_on(3,...))
  167. CH4 PB1 清洁刷电机(control.h PB1_TIM3_CH=4)
  168. TIM8(设备 "pwm8"): CH2 PC7 / CH3 PC8(control.h PC7_TIM3_CH/PC8_TIM3_CH) */
  169. #define BSP_USING_PWM3_CH1
  170. #define BSP_USING_PWM3_CH2
  171. #define BSP_USING_PWM3_CH3
  172. #define BSP_USING_PWM3_CH4
  173. #define BSP_USING_PWM8_CH2
  174. #define BSP_USING_PWM8_CH3
  175. /*-------------------------- PWM CONFIG END --------------------------*/
  176. /*-------------------------- ADC CONFIG BEGIN --------------------------*/
  177. /** if you want to use adc you can use the following instructions.
  178. *
  179. * STEP 1, open adc driver framework support in the RT-Thread Settings file
  180. *
  181. * STEP 2, define macro related to the adc
  182. * such as #define BSP_USING_ADC1
  183. *
  184. * STEP 3, copy your adc init function from stm32xxxx_hal_msp.c generated by stm32cubemx to the end of board.c file
  185. * such as void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
  186. *
  187. * STEP 4, modify your stm32xxxx_hal_config.h file to support adc peripherals. define macro related to the peripherals
  188. * such as #define HAL_ADC_MODULE_ENABLED
  189. *
  190. */
  191. #define BSP_USING_ADC1
  192. /*#define BSP_USING_ADC2*/
  193. /*#define BSP_USING_ADC3*/
  194. /*-------------------------- ADC CONFIG END --------------------------*/
  195. /*-------------------------- WDT CONFIG BEGIN --------------------------*/
  196. /** if you want to use wdt you can use the following instructions.
  197. *
  198. * STEP 1, open wdt driver framework support in the RT-Thread Settings file
  199. *
  200. * STEP 2, modify your stm32xxxx_hal_config.h file to support wdt peripherals. define macro related to the peripherals
  201. * such as #define HAL_IWDG_MODULE_ENABLED
  202. *
  203. */
  204. /*-------------------------- WDT CONFIG END --------------------------*/
  205. /*-------------------------- HARDWARE TIMER CONFIG BEGIN --------------------------*/
  206. /** if you want to use hardware timer you can use the following instructions.
  207. *
  208. * STEP 1, open hwtimer driver framework support in the RT-Thread Settings file
  209. *
  210. * STEP 2, define macro related to the hwtimer
  211. * such as #define BSP_USING_TIM and
  212. * #define BSP_USING_TIM1
  213. *
  214. * STEP 3, copy your hardwire timer init function from stm32xxxx_hal_msp.c generated by stm32cubemx to the end of board.c file
  215. * such as void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
  216. *
  217. * STEP 4, modify your stm32xxxx_hal_config.h file to support hardwere timer peripherals. define macro related to the peripherals
  218. * such as #define HAL_TIM_MODULE_ENABLED
  219. *
  220. */
  221. #define BSP_USING_TIM
  222. #ifdef BSP_USING_TIM
  223. #define BSP_USING_TIM2
  224. #define BSP_USING_TIM3
  225. /*#define BSP_USING_TIM15*/
  226. /*#define BSP_USING_TIM16*/
  227. /*#define BSP_USING_TIM17*/
  228. #endif
  229. /*-------------------------- HAREWARE TIMER CONFIG END --------------------------*/
  230. /*-------------------------- RTC CONFIG BEGIN --------------------------*/
  231. /** if you want to use rtc(hardware) you can use the following instructions.
  232. *
  233. * STEP 1, open rtc driver framework(hardware) support in the RT-Thread Settings file
  234. *
  235. * STEP 2, define macro related to the rtc
  236. * such as BSP_USING_ONCHIP_RTC
  237. *
  238. * STEP 3, modify your stm32xxxx_hal_config.h file to support rtc peripherals. define macro related to the peripherals
  239. * such as #define HAL_RTC_MODULE_ENABLED
  240. *
  241. */
  242. #define BSP_USING_ONCHIP_RTC
  243. /*-------------------------- RTC CONFIG END --------------------------*/
  244. /*-------------------------- SDIO CONFIG BEGIN --------------------------*/
  245. /** if you want to use sdio you can use the following instructions.
  246. *
  247. * STEP 1, open sdio driver framework support in the RT-Thread Settings file
  248. *
  249. * STEP 2, define macro related to the sdio
  250. * such as BSP_USING_SDIO
  251. *
  252. * STEP 3, copy your sdio init function from stm32xxxx_hal_msp.c generated by stm32cubemx to the end of board.c file
  253. * such as void HAL_SD_MspInit(SD_HandleTypeDef* hsd)
  254. *
  255. * STEP 4, modify your stm32xxxx_hal_config.h file to support sdio peripherals. define macro related to the peripherals
  256. * such as #define HAL_SD_MODULE_ENABLED
  257. *
  258. * STEP 5, config your device file system or another applications
  259. *
  260. */
  261. /*#define BSP_USING_SDIO*/
  262. /*-------------------------- SDIO CONFIG END --------------------------*/
  263. /*-------------------------- ETH CONFIG BEGIN --------------------------*/
  264. /** if you want to use eth you can use the following instructions.
  265. *
  266. * STEP 1, define macro related to the eth
  267. * such as BSP_USING_ETH
  268. *
  269. * STEP 2, copy your eth init function from stm32xxxx_hal_msp.c generated by stm32cubemx to the end if board.c file
  270. * such as void HAL_ETH_MspInit(ETH_HandleTypeDef* heth)
  271. *
  272. * STEP 3, modify your stm32xxxx_hal_config.h file to support eth peripherals. define macro related to the peripherals
  273. * such as #define HAL_ETH_MODULE_ENABLED
  274. *
  275. * STEP 4, config your phy type
  276. * such as #define PHY_USING_LAN8720A
  277. * #define PHY_USING_DM9161CEP
  278. * #define PHY_USING_DP83848C
  279. * STEP 5, implement your phy reset function in the end of board.c file
  280. * void phy_reset(void)
  281. *
  282. * STEP 6, config your lwip or other network stack
  283. *
  284. */
  285. /*#define BSP_USING_ETH*/
  286. #ifdef BSP_USING_ETH
  287. /*#define PHY_USING_LAN8720A*/
  288. /*#define PHY_USING_DM9161CEP*/
  289. /*#define PHY_USING_DP83848C*/
  290. #endif
  291. /*-------------------------- ETH CONFIG END --------------------------*/
  292. /*-------------------------- USB HOST CONFIG BEGIN --------------------------*/
  293. /** if you want to use usb host you can use the following instructions.
  294. *
  295. * STEP 1, open usb host driver framework support in the RT-Thread Settings file
  296. *
  297. * STEP 2, define macro related to the usb host
  298. * such as BSP_USING_USBHOST
  299. *
  300. * STEP 3, copy your usb host init function from stm32xxxx_hal_msp.c generated by stm32cubemx to the end of board.c file
  301. * such as void HAL_HCD_MspInit(HCD_HandleTypeDef* hhcd)
  302. *
  303. * STEP 4, config your usb peripheral clock in SystemClock_Config() generated by STM32CubeMX and replace this function in board.c
  304. *
  305. * STEP 5, modify your stm32xxxx_hal_config.h file to support usb host peripherals. define macro related to the peripherals
  306. * such as #define HAL_HCD_MODULE_ENABLED
  307. *
  308. */
  309. /*#define BSP_USING_USBHOST*/
  310. /*-------------------------- USB HOST CONFIG END --------------------------*/
  311. /*-------------------------- USB DEVICE CONFIG BEGIN --------------------------*/
  312. /** if you want to use usb device you can use the following instructions.
  313. *
  314. * STEP 1, open usb device driver framework support in the RT-Thread Settings file
  315. *
  316. * STEP 2 define macro related to the usb device
  317. * such as BSP_USING_USBDEVICE
  318. *
  319. * STEP 3, copy your usb device init function from stm32xxxx_hal_msp.c generated by stm32cubemx to the end of board.c file
  320. * such as void HAL_PCD_MspInit(PCD_HandleTypeDef* hpcd)
  321. *
  322. * STEP 4, config your usb peripheral clock in SystemClock_Config() generated by STM32CubeMX and replace this function in board.c
  323. *
  324. * STEP 5, modify your stm32xxxx_hal_config.h file to support usb device peripherals. define macro related to the peripherals
  325. * such as #define HAL_PCD_MODULE_ENABLED
  326. *
  327. */
  328. /*#define BSP_USING_USBDEVICE*/
  329. /*-------------------------- USB DEVICE CONFIG END --------------------------*/
  330. /*-------------------------- ON_CHIP_FLASH CONFIG BEGIN --------------------------*/
  331. /** if you want to use on chip flash you can use the following instructions.
  332. *
  333. * STEP 1 define macro related to the on chip flash
  334. * such as BSP_USING_ON_CHIP_FLASH
  335. *
  336. * STEP 2, modify your stm32xxxx_hal_config.h file to support on chip flash peripherals. define macro related to the peripherals
  337. * such as #define HAL_FLASH_MODULE_ENABLED
  338. *
  339. */
  340. #define BSP_USING_ON_CHIP_FLASH
  341. /*-------------------------- ON_CHIP_FLASH CONFIG END --------------------------*/
  342. #ifdef __cplusplus
  343. }
  344. #endif
  345. #endif /* __BOARD_H__ */