一、安装RASC
setup_fsp_v4_0_0_rasc_v2022-07.exe
二、在rasc.exe目录内查看rasc_quick_start.html
其中就详细说明了如何在IAR和KEIL中如何添加RASC,我照着做就行了。
下一章主要分享学习资料的来源出处,不止为了入门,也为后续真实项目开发中,解决各类问题做准备。
三、使用RASC创建一个工程,发现问题?
然后分别用IAR和KEIL打开工程,然后点亮LED和打印HelloWorld,验证软硬件是否正常。
/**
* 1.uart0 callback:g_uart0CB
* 2.FSP-BSP-heap size:0x400
* 3.-u _printf_float
* 4.other link void
*/
#ifndef PRINTF
#define PRINTF
#endif
#ifdef PRINTF
volatile bool uart_send_complete_flag = false;
void g_uart0CB (uart_callback_args_t * p_args)
{
if(p_args->event == UART_EVENT_TX_COMPLETE)
{
uart_send_complete_flag = true;
}
}
#ifdef __GNUC__
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif
PUTCHAR_PROTOTYPE
{
uint8_t err = R_SCI_UART_Write(&g_uart0_ctrl, (uint8_t *)&ch, 1);
if(FSP_SUCCESS != err) __BKPT();
while(uart_send_complete_flag == false){}
uart_send_complete_flag = false;
return ch;
}
int _write(int fd,char *pBuffer,int size)
{
for(int i=0;i<size;i++)
{
__io_putchar(*pBuffer++);
}
return size;
}
#endif//PRINTF
void hal_entry (void)
#ifdef PRINTF
/* Open the transfer instance with initial configuration. */
fsp_err_t err = R_SCI_UART_Open(&g_uart0_ctrl, &g_uart0_cfg);
assert(FSP_SUCCESS == err);
printf("date:%s\ntime:%s\nfile:%s\nfunc:%s,line:%d\nhello world!\n", __DATE__, __TIME__, __FILE__, __FUNCTION__, __LINE__);
double PI = 3.1415926;
printf("PI=%f\n", PI);
#endif//PRINTF
使用上一节的代码会发现问题:1、不同编译器的适配 2、Semihost模式
我们优化代码如下,使其能在3个平台都可以使用。问题:在keil使用使用Semihost模式吗?如何使用?
#ifndef PRINTF
#define PRINTF
#endif
#ifdef PRINTF
#include <stdio.h>
/**
* notice: g_uart0CB; g_uart0_ctrl
*
* e2s:
* 1.uart0 callback:g_uart0CB
* 2.FSP-BSP-heap size:0x400
* 3.-u _printf_float
* 4.other link void
*
* iar:
* 1.uart0 callback:g_uart0CB
* 2.FSP-BSP-heap size:0x400
* 3.libray=full
* 4.Semihosted=None
*
* keil:
* 1.uart0 callback:g_uart0CB
* 2.FSP-BSP-heap size:0x400
*/
volatile bool uart_send_complete_flag = false;
void g_uart0CB (uart_callback_args_t * p_args)
{
if(p_args->event == UART_EVENT_TX_COMPLETE)
{
uart_send_complete_flag = true;
}
}
#if defined __GNUC__ && !defined __clang__
int _write(int fd, char *pBuffer, int size); //??????
int _write(int fd, char *pBuffer, int size)
{
(void)fd;
fsp_err_t err = R_SCI_UART_Write(&g_uart0_ctrl, (uint8_t *)pBuffer, (uint32_t)size);
if(FSP_SUCCESS != err) __BKPT();
while(uart_send_complete_flag == false);
uart_send_complete_flag = false;
return size;
}
#else
int fputc(int ch, FILE *f)
{
(void)f;
fsp_err_t err = R_SCI_UART_Write(&g_uart0_ctrl, (uint8_t *)&ch, 1);
if(FSP_SUCCESS != err) __asm("bkpt 0");
while(uart_send_complete_flag == false);
uart_send_complete_flag = false;
return ch;
}
#endif//#if defined __GNUC__ && !defined __clang__
#endif//PRINTF
void hal_entry (void)
#ifdef PRINTF
/* Open the transfer instance with initial configuration. */
fsp_err_t err = R_SCI_UART_Open(&g_uart0_ctrl, &g_uart0_cfg);
assert(FSP_SUCCESS == err);
printf("date:%s\ntime:%s\nfile:%s\nfunc:%s,line:%d\nhello world!\n", __DATE__, __TIME__, __FILE__, __FUNCTION__, __LINE__);
double PI = 3.1415926;
printf("PI=%f\n", PI);
#endif//PRINTF