相关文章:
【GD32L233C-START评测】1、优点与缺点都很明显的GD32L233C-START(开箱)
【GD32L233C-START评测】2、非阻塞方式点灯,blink,blink,blink……
【GD32L233C-START评测】4、串口不定长数据接收
【GD32L233C-START评测】5、Flash读写——使用内部Flash存储数据
【GD32L233C-START评测】6、硬件I2C驱动0.96吋OLED
【GD32L233C-START评测】7、硬件SPI1驱动RC522
【GD32L233C-START评测】8、获取MCU96位唯一ID、SRAM、FLASH大小
【GD32L233C-START评测】9、IAP程序升级——基于YMODEM协议
【GD32L233C-START评测】10、使用内部参考电压校准adc,adc采样更准确
【GD32L233C-START评测】11、GD32 ISP软件还不支持GD32L233
【GD32L233C-START评测】12、按键——外部中断
【GD32L233C-START评测】13、I2C驱动环境光和接近传感器RPR-0521RS
1、安装RT-Thread keil Pack
或者离线下载安装
https://www.rt-thread.org/download/mdk/RealThread.RT-Thread.3.1.5.pack
2、在工程中勾选RTOS中的kernel 和 shell
3、编译报错
4、配置时钟#error "TODO 1: OS Tick Configuration."
// #error "TODO 1: OS Tick Configuration."
SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
NVIC_SetPriority(SysTick_IRQn, 0x00U);
void SysTick_Handler(void)
{
void rt_os_tick_callback(void);
rt_os_tick_callback();
}
5、配置串口#error "TODO 2: Enable the hardware uart and config baudrate."
//#error "TODO 2: Enable the hardware uart and config baudrate."
extern void SerialInit(void);
SerialInit();
void SerialInit(void)
{
/* enable COM GPIO clock */
rcu_periph_clock_enable(RCU_GPIOA);
/* enable USART clock */
rcu_periph_clock_enable(RCU_USART0);
/* connect port to USART TX */
gpio_af_set(GPIOA, GPIO_AF_7, GPIO_PIN_9);
/* connect port to USART RX */
gpio_af_set(GPIOA, GPIO_AF_7, GPIO_PIN_10);
/* configure USART TX as alternate function push-pull */
gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_PULLUP, GPIO_PIN_9);
gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, GPIO_PIN_10);
/* configure USART RX as alternate function push-pull */
gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_PULLUP, GPIO_PIN_10);
gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, GPIO_PIN_10);
/* USART configure */
usart_deinit(USART0);
usart_word_length_set(USART0, USART_WL_8BIT);
usart_stop_bit_set(USART0, USART_STB_1BIT);
usart_parity_config(USART0, USART_PM_NONE);
usart_baudrate_set(USART0, 115200U);
usart_receive_config(USART0, USART_RECEIVE_ENABLE);
usart_transmit_config(USART0, USART_TRANSMIT_ENABLE);
usart_enable(USART0);
}
6、串口输出#error "TODO 3: Output the string 'str' through the uart."
//#error "TODO 3: Output the string 'str' through the uart."
extern void _rt_hw_console_output( const char *str );
_rt_hw_console_output(str);
void _rt_hw_console_output( const char *str )
{
rt_size_t i = 0, size = 0;
char a = '\r';
size = rt_strlen(str);
for (i = 0; i < size; i++)
{
if (*(str + i) == '\n')
{
usart_data_transmit(USART0, (uint32_t )a);
while((usart_flag_get(USART0, USART_FLAG_TC) == RESET));
}
usart_data_transmit(USART0, (uint32_t)*(str + i));
while((usart_flag_get(USART0, USART_FLAG_TC) == RESET));
}
}
7、串口输入#error "TODO 4: Read a char from the uart and assign it to 'ch'."
//#error "TODO 4: Read a char from the uart and assign it to 'ch'."
extern char _rt_hw_console_getchar(void);
ch= _rt_hw_console_getchar();
char _rt_hw_console_getchar(void)
{
/* the initial value of ch must < 0 */
int ch = -1;
if (usart_flag_get(USART0, USART_FLAG_RBNE) != RESET)
{
ch = usart_data_receive(USART0);
}
else
{
rt_thread_mdelay(10);
}
return ch;
}
8、PendSV_Handler和HardFault_Handler重复定义
PendSV_Handler和HardFault_Handler两个中断,RT-Thread系统处理,屏蔽掉gd32l23x_it.c中的即可。
9、finsh_config.h未包含
10、创建led线程
static rt_thread_t led_thread = RT_NULL;
void LedInit(void)
{
/* enable the LED GPIO clock */
rcu_periph_clock_enable(RCU_GPIOA);
/* configure LED GPIO pin */
gpio_mode_set(GPIOA, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO_PIN_7 | GPIO_PIN_8);
gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_7 | GPIO_PIN_8);
/* reset LED GPIO pin */
gpio_bit_reset(GPIOA, GPIO_PIN_7 | GPIO_PIN_8);
}
static void led_thread_entry(void *parameter)
{
while (1)
{
gpio_bit_toggle(GPIOA, GPIO_PIN_7|GPIO_PIN_8);
rt_thread_mdelay(1000);
rt_kprintf("led blink\r\n");
}
}
void LedThreadStart(void)
{
led_thread = rt_thread_create( "led", /*线程名字*/
led_thread_entry,/*线程入口函数*/
RT_NULL,/*线程入口函数参数*/
256, /*线程栈大小*/
4 , /*线程优先级*/
20); /*线程时间片*/
rt_thread_startup (led_thread);
}
11、硬件初始化
在rt_hw_board_init函数中包含led初始化函数。
12、在main函数中调用启动led线程
int main(void)
{
LedThreadStart();
return 0;
}
13、现象
本帖最后由 freeelectron 于 2022-2-7 13:05 编辑