本帖最后由 sujingliang 于 2024-7-21 11:13 编辑
一、准备工作
1、下载rt-thread env tools:
https://download-redirect.rt-thread.org/download/env_release/env-windows-v2.0.0.7z
2、下载rt-thread最新版:
https://www.rt-thread.org/download.html
1)https://github.com/RT-Thread/rt-thread
2)https://gitee.com/rtthread/rt-thread
git clone https://gitee.com/rtthread/rt-thread.git
3)https://pan.baidu.com/s/10_50j70OVGYrEWmm2X1qvQ
提取码:t22b
3、制作BSP参考:
STM32 系列 BSP 制作教程https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/tutorial/make-bsp/stm32-bsp/STM32%E7%B3%BB%E5%88%97BSP%E5%88%B6%E4%BD%9C%E6%95%99%E7%A8%8B
二、BSP制作过程
1、复制stm32h503-st-nucleo目录到stm32h533-st-nucleo
目前rt-thread源码中,没有stm32h533-st-nucleo的bsp,但是有stm32h503-st-nucleo、stm32h563-st-nucleo,这两个BSP是stm32h533-st-nucleo的一个系列产品,可以做为制作stm32h533-st-nucleo BSP的模板。
进入:c:\rt-thread\bsp\stm32目录下,复制stm32h503-st-nucleo一份,改名stm32h533-st-nucleo
2、用STM32CubeMX建立一份stm32h533-st-nucleo最简单工程模板,只包括USART2,生成mdk工程。
其中stm32h5xx_hal_msp.c文件只有USART2初始化内容,为了用于rt-thread CMD shell
- void HAL_UART_MspInit(UART_HandleTypeDef* huart)
- {
- GPIO_InitTypeDef GPIO_InitStruct = {0};
- RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
- if(huart->Instance==USART2)
- {
- /* USER CODE BEGIN USART2_MspInit 0 */
- /* USER CODE END USART2_MspInit 0 */
- /** Initializes the peripherals clock
- */
- PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USART2;
- PeriphClkInitStruct.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;
- if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
- {
- Error_Handler();
- }
- /* Peripheral clock enable */
- __HAL_RCC_USART2_CLK_ENABLE();
- __HAL_RCC_GPIOA_CLK_ENABLE();
- /**USART2 GPIO Configuration
- PA2 ------> USART2_TX
- PA3 ------> USART2_RX
- */
- GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3;
- GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
- GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
- HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
- /* USER CODE BEGIN USART2_MspInit 1 */
- /* USER CODE END USART2_MspInit 1 */
- }
- }
- /**
- * [url=home.php?mod=space&uid=247401]@brief[/url] UART MSP De-Initialization
- * This function freeze the hardware resources used in this example
- * @param huart: UART handle pointer
- * @retval None
- */
- void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
- {
- if(huart->Instance==USART2)
- {
- /* USER CODE BEGIN USART2_MspDeInit 0 */
- /* USER CODE END USART2_MspDeInit 0 */
- /* Peripheral clock disable */
- __HAL_RCC_USART2_CLK_DISABLE();
- /**USART2 GPIO Configuration
- PA2 ------> USART2_TX
- PA3 ------> USART2_RX
- */
- HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3);
- /* USER CODE BEGIN USART2_MspDeInit 1 */
- /* USER CODE END USART2_MspDeInit 1 */
- }
- }
copy STM32CubeMX生成的
inc、Src目录和.mxproject、CubeMX_Config.ioc文件到C:\rt-thread\bsp\stm32\stm32h533-st-nucleo\board\CubeMX_Config覆盖原文件
3、修改board.c文件
文件目录:C:\rt-thread\bsp\stm32\stm32h533-st-nucleo\board
将文件中void SystemClock_Config(void)函数改成:
|