1.硬件信息
2.rasc配置
2.1sci-usart 配置
2.2 stack配置
配置注意- stack的通道必须和sci的数值一致
2.3串口属性属性
2.4 修改堆得大小
默认堆得大小是0,在使用printf函数时候需要堆得空间所以配置一下堆
软件编写
bsp_debug_uart.c
#include "bsp_debug_uart.h"
void bsp_uart_init(void)
{
fsp_err_t err = FSP_SUCCESS;
err = R_SCI_UART_Open (&g_uart0_ctrl, &g_uart0_cfg);
assert(FSP_SUCCESS == err);
}
volatile bool uart_send_complete_flag = false;
void uart0_callback (uart_callback_args_t * p_args)
{
switch (p_args->event)
{
case UART_EVENT_RX_CHAR:
{
R_SCI_UART_Write(&g_uart0_ctrl, (uint8_t *)&(p_args->data), 1);
break;
}
case UART_EVENT_TX_COMPLETE:
{
uart_send_complete_flag = true;
break;
}
default:
break;
}
}
#if defined __GNUC__ && !defined __clang__
int _write(int fd, char *pBuffer, int size);
int _write(int fd, char *pBuffer, int size)
{
(void)fd;
R_SCI_UART_Write(&g_uart0_ctrl, (uint8_t *)pBuffer, (uint32_t)size);
while(uart_send_complete_flag == false);
uart_send_complete_flag = false;
return size;
}
#else
int fputc(int ch, FILE *f)
{
(void)f;
R_SCI_UART_Write(&g_uart0_ctrl, (uint8_t *)&ch, 1);
while(uart_send_complete_flag == false);
uart_send_complete_flag = false;
return ch;
}
#endif
bsp_debug_uart.h
#ifndef __BSP_UART_H__
#define __BSP_UART_H__
#include "hal_data.h"
#include "stdio.h"
void bsp_uart_init(void);
#endif
hal_entery.c
void hal_entry(void)
{
R_IOPORT_Open (&g_ioport_ctrl, g_ioport.p_cfg);
bsp_uart_init();
printf("hello RA4\\r\\n");
while(1)
{
R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_04_PIN_04, BSP_IO_LEVEL_LOW);
R_BSP_SoftwareDelay(100, BSP_DELAY_UNITS_MILLISECONDS);
R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_04_PIN_04, BSP_IO_LEVEL_HIGH);
R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_04_PIN_05, BSP_IO_LEVEL_LOW);
R_BSP_SoftwareDelay(100, BSP_DELAY_UNITS_MILLISECONDS);
R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_04_PIN_05, BSP_IO_LEVEL_HIGH);
R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_04_PIN_15, BSP_IO_LEVEL_LOW);
R_BSP_SoftwareDelay(100, BSP_DELAY_UNITS_MILLISECONDS);
R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_04_PIN_15, BSP_IO_LEVEL_HIGH);
}
#if BSP_TZ_SECURE_BUILD
R_BSP_NonSecureEnter();
#endif
效果
|