In this article, we will learn how to port the rt-thread nano system to the CW32L052 development board.
1. Create rt-thread nano project
The project adds rt-thread nano file based on the previous https://bbs.eeworld.com.cn/thread-1250118-1-1.html project
1.1. Add source files
There are two ways to add source files. One is to download the source files from the rt-thead official website and add them manually. The other is to install the IDE and the MDK software pack. Here we use the pack installation method.
Download the rt-thread package
Add kernel source files to the project
Added project files
1.2. Modify the file
1.2.1、Shield the PendSV_Handler function
1.2.2. Shield the HardFault_Handler function
1.2.3. Shield the SysTick_Handler function
1.2.4. Modify the memory stack space RT_HEAP_SIZE
The internal RAM of CW32L050 is 8K, modify it here.
1.2.5. Add hardware initialization and SysTick_Handler function
1.3 Test Procedure
Modify the main.c main program
#include "main.h"
#include "rtthread.h"
void rcc_config(void)
{
uint8_t res = 0U;
RCC_AHBPeriphClk_Enable(RCC_AHB_PERIPH_FLASH, ENABLE);
RCC_LSI_Enable( ); //开启外部高速时钟LSI
res = RCC_SysClk_Switch( RCC_SYSCLKSRC_LSI ); //切换系统时钟到LSI
if( res == 0x00 ) //系统时钟切换成功
{
RCC_HSI_Disable(); //切换时钟到PLL后关闭源时钟HSI
FirmwareDelay( 400 ); //about 100mS
}
RCC_HSI_Enable( RCC_HSIOSC_DIV1 ); //开启内部高速时钟HSI = HSIOSC / 2
FLASH_SetLatency(FLASH_Latency_3);
res = RCC_SysClk_Switch( RCC_SYSCLKSRC_HSI ); //切换系统时钟到HSI
if( res == 0x00 ) //系统时钟切换成功
{
RCC_LSI_Disable(); //切换时钟到HSI后关闭LSI时钟
FirmwareDelay( 275000 ); //about 100mS
}
RCC_HCLKPRS_Config(RCC_HCLK_DIV1);
RCC_HCLK_OUT(); //通过PA04观察HCLK频率
}
int32_t main(void)
{
while (1)
{
led2_tog();
rt_thread_mdelay(100);
}
}
2. Program operation
After the modification is completed, compile, download, and power on and reset the development board. The running video is as follows:
cw32
3. Attachments
|