board.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. /*
  2. * Copyright (c) 2006-2019, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2019-10-26 ChenYong first version
  9. */
  10. #ifndef __BOARD_H__
  11. #define __BOARD_H__
  12. #include <rtthread.h>
  13. #include <stm32f1xx.h>
  14. #include "drv_common.h"
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #define RT_APP_PART_ADDR 0x8032000
  19. #define CHIP_FAMILY_STM32
  20. #define CHIP_SERIES_STM32F1
  21. #define CHIP_NAME_STM32F103RE
  22. /*-------------------------- UART CONFIG BEGIN --------------------------*/
  23. /** After configuring corresponding UART or UART DMA, you can use it.
  24. *
  25. * STEP 1, define macro define related to the serial port opening based on the serial port number
  26. * such as #define BSP_USING_UATR1
  27. *
  28. * STEP 2, according to the corresponding pin of serial port, modify the related serial port information
  29. * such as #define UART1_TX_PORT GPIOX -> GPIOA
  30. * #define UART1_RX_PORT GPIOX -> GPIOA
  31. * #define UART1_TX_PIN GPIO_PIN_X -> GPIO_PIN_9
  32. * #define UART1_RX_PIN GPIO_PIN_X -> GPIO_PIN_10
  33. *
  34. * STEP 3, if you want using SERIAL DMA, you must open it in the RT-Thread Settings.
  35. * RT-Thread Setting -> Components -> Device Drivers -> Serial Device Drivers -> Enable Serial DMA Mode
  36. *
  37. * STEP 4, according to serial port number to define serial port tx/rx DMA function in the board.h file
  38. * such as #define BSP_UART1_RX_USING_DMA
  39. *
  40. */
  41. #define BSP_UART3_RX_USING_DMA //喇叭
  42. #define BSP_UART2_RX_USING_DMA //DTU
  43. #define BSP_UART4_RX_USING_DMA //屏幕
  44. #define BSP_USING_UART1
  45. #define BSP_USING_UART2
  46. #define BSP_USING_UART3
  47. #define BSP_USING_I2C1
  48. #define BSP_USING_UART4
  49. #define BSP_USING_UART5
  50. #if defined(BSP_USING_UART1)
  51. #define UART1_TX_PORT GPIOA
  52. #define UART1_RX_PORT GPIOA
  53. #define UART1_TX_PIN GPIO_PIN_9
  54. #define UART1_RX_PIN GPIO_PIN_10
  55. #endif
  56. #if defined(BSP_USING_UART2)
  57. #define UART2_TX_PORT GPIOA
  58. #define UART2_RX_PORT GPIOA
  59. #define UART2_TX_PIN GPIO_PIN_2
  60. #define UART2_RX_PIN GPIO_PIN_3
  61. #endif
  62. #if defined(BSP_USING_UART3)
  63. #define UART3_TX_PORT GPIOB
  64. #define UART3_RX_PORT GPIOB
  65. #define UART3_TX_PIN GPIO_PIN_10
  66. #define UART3_RX_PIN GPIO_PIN_11
  67. #endif
  68. #if defined(BSP_USING_UART4)
  69. #define UART4_TX_PORT GPIOC
  70. #define UART4_RX_PORT GPIOC
  71. #define UART4_TX_PIN GPIO_PIN_10
  72. #define UART4_RX_PIN GPIO_PIN_11
  73. #endif
  74. #if defined(BSP_USING_UART5)
  75. #define UART5_TX_PORT GPIOC
  76. #define UART5_RX_PORT GPIOD
  77. #define UART5_TX_PIN GPIO_PIN_12
  78. #define UART5_RX_PIN GPIO_PIN_2
  79. #endif
  80. #if defined(BSP_USING_UART6)
  81. #define UART6_TX_PORT GPIOX
  82. #define UART6_RX_PORT GPIOX
  83. #define UART6_TX_PIN GPIO_PIN_X
  84. #define UART6_RX_PIN GPIO_PIN_X
  85. #endif
  86. #if defined(BSP_USING_UART7)
  87. #define UART7_TX_PORT GPIOX
  88. #define UART7_RX_PORT GPIOX
  89. #define UART7_TX_PIN GPIO_PIN_X
  90. #define UART7_RX_PIN GPIO_PIN_X
  91. #endif
  92. #if defined(BSP_USING_UART8)
  93. #define UART8_TX_PORT GPIOX
  94. #define UART8_RX_PORT GPIOX
  95. #define UART8_TX_PIN GPIO_PIN_X
  96. #define UART8_RX_PIN GPIO_PIN_X
  97. #endif
  98. #if defined(BSP_USING_LPUART1)
  99. #define LPUART1_TX_PORT GPIOX
  100. #define LPUART1_RX_PORT GPIOX
  101. #define LPUART1_TX_PIN GPIO_PIN_X
  102. #define LPUART1_RX_PIN GPIO_PIN_X
  103. #endif
  104. /*-------------------------- UART CONFIG END --------------------------*/
  105. /*-------------------------- I2C CONFIG BEGIN --------------------------*/
  106. /** if you want to use i2c bus(soft simulate) you can use the following instructions.
  107. *
  108. * STEP 1, open i2c driver framework(soft simulate) support in the RT-Thread Settings file
  109. *
  110. * STEP 2, define macro related to the i2c bus
  111. * such as #define BSP_USING_I2C1
  112. *
  113. * STEP 3, according to the corresponding pin of i2c port, modify the related i2c port and pin information
  114. * such as #define BSP_I2C1_SCL_PIN GET_PIN(port, pin) -> GET_PIN(C, 11)
  115. * #define BSP_I2C1_SDA_PIN GET_PIN(port, pin) -> GET_PIN(C, 12)
  116. */
  117. /*#define BSP_USING_I2C1*/
  118. #ifdef BSP_USING_I2C1
  119. #define BSP_I2C1_SCL_PIN GET_PIN(B, 6)
  120. #define BSP_I2C1_SDA_PIN GET_PIN(B, 7)
  121. #endif
  122. /*#define BSP_USING_I2C2*/
  123. #ifdef BSP_USING_I2C2
  124. #define BSP_I2C2_SCL_PIN GET_PIN(port, pin)
  125. #define BSP_I2C2_SDA_PIN GET_PIN(port, pin)
  126. #endif
  127. /*-------------------------- I2C CONFIG END --------------------------*/
  128. /*-------------------------- SPI CONFIG BEGIN --------------------------*/
  129. /** if you want to use spi bus you can use the following instructions.
  130. *
  131. * STEP 1, open spi driver framework support in the RT-Thread Settings file
  132. *
  133. * STEP 2, define macro related to the spi bus
  134. * such as #define BSP_USING_SPI1
  135. *
  136. * STEP 3, copy your spi init function from stm32xxxx_hal_msp.c generated by stm32cubemx to the end of board.c file
  137. * such as void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
  138. *
  139. * STEP 4, modify your stm32xxxx_hal_config.h file to support spi peripherals. define macro related to the peripherals
  140. * such as #define HAL_SPI_MODULE_ENABLED
  141. */
  142. #define BSP_USING_SPI1
  143. /*#define BSP_USING_SPI2*/
  144. /*#define BSP_USING_SPI3*/
  145. /*-------------------------- SPI CONFIG END --------------------------*/
  146. /*-------------------------- QSPI CONFIG BEGIN --------------------------*/
  147. /** if you want to use qspi you can use the following instructions.
  148. *
  149. * STEP 1, open qspi driver framework support in the RT-Thread Settings file
  150. *
  151. * STEP 2, define macro related to the qspi
  152. * such as #define BSP_USING_QSPI
  153. *
  154. * STEP 3, copy your qspi init function from stm32xxxx_hal_msp.c generated by stm32cubemx to the end of board.c file
  155. * such as void HAL_QSPI_MspInit(QSPI_HandleTypeDef* hqspi)
  156. *
  157. * STEP 4, modify your stm32xxxx_hal_config.h file to support qspi peripherals. define macro related to the peripherals
  158. * such as #define HAL_QSPI_MODULE_ENABLED
  159. *
  160. */
  161. /*#define BSP_USING_QSPI*/
  162. /*-------------------------- QSPI CONFIG END --------------------------*/
  163. /*-------------------------- PWM CONFIG BEGIN --------------------------*/
  164. /** if you want to use pwm you can use the following instructions.
  165. *
  166. * STEP 1, open pwm driver framework support in the RT-Thread Settings file
  167. *
  168. * STEP 2, define macro related to the pwm
  169. * such as #define BSP_USING_PWM1
  170. *
  171. * STEP 3, copy your pwm timer init function from stm32xxxx_hal_msp.c generated by stm32cubemx to the end if board.c file
  172. * such as void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base) and
  173. * void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
  174. *
  175. * STEP 4, modify your stm32xxxx_hal_config.h file to support pwm peripherals. define macro related to the peripherals
  176. * such as #define HAL_TIM_MODULE_ENABLED
  177. *
  178. */
  179. /*#define BSP_USING_PWM1*/
  180. /*#define BSP_USING_PWM2*/
  181. #define BSP_USING_PWM3
  182. #define BSP_USING_PWM3_CH1
  183. #define BSP_USING_PWM3_CH3
  184. #define BSP_USING_PWM3_CH4
  185. #define BSP_USING_PWM8
  186. #define BSP_USING_PWM8_CH2
  187. #define BSP_USING_PWM8_CH3
  188. /*-------------------------- PWM CONFIG END --------------------------*/
  189. /*-------------------------- ADC CONFIG BEGIN --------------------------*/
  190. /** if you want to use adc you can use the following instructions.
  191. *
  192. * STEP 1, open adc driver framework support in the RT-Thread Settings file
  193. *
  194. * STEP 2, define macro related to the adc
  195. * such as #define BSP_USING_ADC1
  196. *
  197. * STEP 3, copy your adc init function from stm32xxxx_hal_msp.c generated by stm32cubemx to the end of board.c file
  198. * such as void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
  199. *
  200. * STEP 4, modify your stm32xxxx_hal_config.h file to support adc peripherals. define macro related to the peripherals
  201. * such as #define HAL_ADC_MODULE_ENABLED
  202. *
  203. */
  204. #define BSP_USING_ADC1
  205. /*#define BSP_USING_ADC2*/
  206. /*#define BSP_USING_ADC3*/
  207. /*-------------------------- ADC CONFIG END --------------------------*/
  208. /*-------------------------- WDT CONFIG BEGIN --------------------------*/
  209. /** if you want to use wdt you can use the following instructions.
  210. *
  211. * STEP 1, open wdt driver framework support in the RT-Thread Settings file
  212. *
  213. * STEP 2, modify your stm32xxxx_hal_config.h file to support wdt peripherals. define macro related to the peripherals
  214. * such as #define HAL_IWDG_MODULE_ENABLED
  215. *
  216. */
  217. /*-------------------------- WDT CONFIG END --------------------------*/
  218. /*-------------------------- HARDWARE TIMER CONFIG BEGIN --------------------------*/
  219. /** if you want to use hardware timer you can use the following instructions.
  220. *
  221. * STEP 1, open hwtimer driver framework support in the RT-Thread Settings file
  222. *
  223. * STEP 2, define macro related to the hwtimer
  224. * such as #define BSP_USING_TIM and
  225. * #define BSP_USING_TIM1
  226. *
  227. * STEP 3, copy your hardwire timer init function from stm32xxxx_hal_msp.c generated by stm32cubemx to the end of board.c file
  228. * such as void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
  229. *
  230. * STEP 4, modify your stm32xxxx_hal_config.h file to support hardwere timer peripherals. define macro related to the peripherals
  231. * such as #define HAL_TIM_MODULE_ENABLED
  232. *
  233. */
  234. /*#define BSP_USING_TIM*/
  235. #ifdef BSP_USING_TIM
  236. #define BSP_USING_TIM3
  237. /*#define BSP_USING_TIM15*/
  238. /*#define BSP_USING_TIM16*/
  239. /*#define BSP_USING_TIM17*/
  240. #endif
  241. /*-------------------------- HAREWARE TIMER CONFIG END --------------------------*/
  242. /*-------------------------- RTC CONFIG BEGIN --------------------------*/
  243. /** if you want to use rtc(hardware) you can use the following instructions.
  244. *
  245. * STEP 1, open rtc driver framework(hardware) support in the RT-Thread Settings file
  246. *
  247. * STEP 2, define macro related to the rtc
  248. * such as BSP_USING_ONCHIP_RTC
  249. *
  250. * STEP 3, modify your stm32xxxx_hal_config.h file to support rtc peripherals. define macro related to the peripherals
  251. * such as #define HAL_RTC_MODULE_ENABLED
  252. *
  253. */
  254. #define BSP_USING_ONCHIP_RTC
  255. /*-------------------------- RTC CONFIG END --------------------------*/
  256. /*-------------------------- SDIO CONFIG BEGIN --------------------------*/
  257. /** if you want to use sdio you can use the following instructions.
  258. *
  259. * STEP 1, open sdio driver framework support in the RT-Thread Settings file
  260. *
  261. * STEP 2, define macro related to the sdio
  262. * such as BSP_USING_SDIO
  263. *
  264. * STEP 3, copy your sdio init function from stm32xxxx_hal_msp.c generated by stm32cubemx to the end of board.c file
  265. * such as void HAL_SD_MspInit(SD_HandleTypeDef* hsd)
  266. *
  267. * STEP 4, modify your stm32xxxx_hal_config.h file to support sdio peripherals. define macro related to the peripherals
  268. * such as #define HAL_SD_MODULE_ENABLED
  269. *
  270. * STEP 5, config your device file system or another applications
  271. *
  272. */
  273. /*#define BSP_USING_SDIO*/
  274. /*-------------------------- SDIO CONFIG END --------------------------*/
  275. /*-------------------------- ETH CONFIG BEGIN --------------------------*/
  276. /** if you want to use eth you can use the following instructions.
  277. *
  278. * STEP 1, define macro related to the eth
  279. * such as BSP_USING_ETH
  280. *
  281. * STEP 2, copy your eth init function from stm32xxxx_hal_msp.c generated by stm32cubemx to the end if board.c file
  282. * such as void HAL_ETH_MspInit(ETH_HandleTypeDef* heth)
  283. *
  284. * STEP 3, modify your stm32xxxx_hal_config.h file to support eth peripherals. define macro related to the peripherals
  285. * such as #define HAL_ETH_MODULE_ENABLED
  286. *
  287. * STEP 4, config your phy type
  288. * such as #define PHY_USING_LAN8720A
  289. * #define PHY_USING_DM9161CEP
  290. * #define PHY_USING_DP83848C
  291. * STEP 5, implement your phy reset function in the end of board.c file
  292. * void phy_reset(void)
  293. *
  294. * STEP 6, config your lwip or other network stack
  295. *
  296. */
  297. /*#define BSP_USING_ETH*/
  298. #ifdef BSP_USING_ETH
  299. /*#define PHY_USING_LAN8720A*/
  300. /*#define PHY_USING_DM9161CEP*/
  301. /*#define PHY_USING_DP83848C*/
  302. #endif
  303. /*-------------------------- ETH CONFIG END --------------------------*/
  304. /*-------------------------- USB HOST CONFIG BEGIN --------------------------*/
  305. /** if you want to use usb host you can use the following instructions.
  306. *
  307. * STEP 1, open usb host driver framework support in the RT-Thread Settings file
  308. *
  309. * STEP 2, define macro related to the usb host
  310. * such as BSP_USING_USBHOST
  311. *
  312. * STEP 3, copy your usb host init function from stm32xxxx_hal_msp.c generated by stm32cubemx to the end of board.c file
  313. * such as void HAL_HCD_MspInit(HCD_HandleTypeDef* hhcd)
  314. *
  315. * STEP 4, config your usb peripheral clock in SystemClock_Config() generated by STM32CubeMX and replace this function in board.c
  316. *
  317. * STEP 5, modify your stm32xxxx_hal_config.h file to support usb host peripherals. define macro related to the peripherals
  318. * such as #define HAL_HCD_MODULE_ENABLED
  319. *
  320. */
  321. /*#define BSP_USING_USBHOST*/
  322. /*-------------------------- USB HOST CONFIG END --------------------------*/
  323. /*-------------------------- USB DEVICE CONFIG BEGIN --------------------------*/
  324. /** if you want to use usb device you can use the following instructions.
  325. *
  326. * STEP 1, open usb device driver framework support in the RT-Thread Settings file
  327. *
  328. * STEP 2 define macro related to the usb device
  329. * such as BSP_USING_USBDEVICE
  330. *
  331. * STEP 3, copy your usb device init function from stm32xxxx_hal_msp.c generated by stm32cubemx to the end of board.c file
  332. * such as void HAL_PCD_MspInit(PCD_HandleTypeDef* hpcd)
  333. *
  334. * STEP 4, config your usb peripheral clock in SystemClock_Config() generated by STM32CubeMX and replace this function in board.c
  335. *
  336. * STEP 5, modify your stm32xxxx_hal_config.h file to support usb device peripherals. define macro related to the peripherals
  337. * such as #define HAL_PCD_MODULE_ENABLED
  338. *
  339. */
  340. /*#define BSP_USING_USBDEVICE*/
  341. /*-------------------------- USB DEVICE CONFIG END --------------------------*/
  342. /*-------------------------- ON_CHIP_FLASH CONFIG BEGIN --------------------------*/
  343. /** if you want to use on chip flash you can use the following instructions.
  344. *
  345. * STEP 1 define macro related to the on chip flash
  346. * such as BSP_USING_ON_CHIP_FLASH
  347. *
  348. * STEP 2, modify your stm32xxxx_hal_config.h file to support on chip flash peripherals. define macro related to the peripherals
  349. * such as #define HAL_FLASH_MODULE_ENABLED
  350. *
  351. */
  352. #define BSP_USING_ON_CHIP_FLASH
  353. /*-------------------------- ON_CHIP_FLASH CONFIG END --------------------------*/
  354. //250322 适配为stm32适用的RAM SIZE
  355. /*-------------------------- ROM/RAM CONFIG BEGIN --------------------------*/
  356. #define STM32_FLASH_START_ADRESS ((uint32_t)0x08032000) // 确认与链接脚本一致
  357. #define STM32_FLASH_SIZE (312) // 312 KB
  358. #define STM32_FLASH_END_ADDRESS ((uint32_t)(STM32_FLASH_START_ADRESS + STM32_FLASH_SIZE * 1024))
  359. #define STM32_SRAM1_SIZE (64) // STM32F103RET6 实际 RAM 为 64 KB
  360. #define STM32_SRAM1_START (0x20000000)
  361. #define STM32_SRAM1_END (STM32_SRAM1_START + STM32_SRAM1_SIZE * 1024) // 0x20010000
  362. // HEAP_BEGIN 定义无误,保持原样
  363. #if defined(__CC_ARM) || defined(__CLANG_ARM)
  364. extern int Image$RW_IRAM1$ZI$Limit;
  365. #define HEAP_BEGIN ((void *)&Image$RW_IRAM1$ZI$Limit)
  366. #elif __ICCARM__
  367. #pragma section="CSTACK"
  368. #define HEAP_BEGIN (__segment_end("CSTACK"))
  369. #else
  370. extern int __bss_end;
  371. #define HEAP_BEGIN ((void *)&__bss_end)
  372. #endif
  373. #define HEAP_END STM32_SRAM1_END // 修正为 0x20010000
  374. /*-------------------------- ROM/RAM CONFIG END --------------------------*/
  375. void SystemClock_Config(void);
  376. #ifdef __cplusplus
  377. }
  378. #endif
  379. #endif /* __BOARD_H__ */