查看: 549|回复: 1

【瑞萨RA4系列开发板体验】printf+hello world

[复制链接]

116

主题

133

帖子

3768

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
3768
发表于 2023-2-1 11:50:38 | 显示全部楼层 |阅读模式
【瑞萨RA4系列开发板体验】printf+hello world
作者:lugl

今天看了看Jlink v10,最便宜的也得400块,太贵了,但是要调试程序,只有选择printf来实现了,所以先把printf来实现。
1、按照常规的新建好工程:

2、打开资料《RA2E1/RA2L1入门指南》的《# 瑞萨e2studio----打印函数(printf、sprintf)的实现》这篇文章,他们的芯片型号不一样,但是操作也是基本相同的。
3、按照以后步步骤添加uart0:

4、选好IO为P101、P100为RX、TX


5、设置E2STUDIO堆栈

6、修改e2studio的重定向printf设置C++ 构建->设置->GNU ARM Cross C Linker->Miscellaneous去掉Other linker flags中的 “--specs=rdimon.specs”

7、完整的halt_entry.c内容如下:
  1. #include "hal_data.h"
  2. #include <stdio.h>
  3. FSP_CPP_HEADER
  4. void R_BSP_WarmStart(bsp_warm_start_event_t event);
  5. FSP_CPP_FOOTER

  6. fsp_err_t err = FSP_SUCCESS;unsigned char send_buff[100];
  7. volatile bool uart_send_complete_flag = false;
  8. void user_uart_callback (uart_callback_args_t * p_args)
  9. {
  10.     if(p_args->event == UART_EVENT_TX_COMPLETE)
  11.     {
  12.         uart_send_complete_flag = true;
  13.     }
  14. }

  15. #ifdef __GNUC__                                 //串口重定向
  16. #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
  17. #else
  18. #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
  19. #endif
  20. PUTCHAR_PROTOTYPE
  21. {
  22.     err = R_SCI_UART_Write(&g_uart0_ctrl, (uint8_t *)&ch, 1);
  23.     if(FSP_SUCCESS != err) __BKPT();
  24.     while(uart_send_complete_flag == false){}
  25.     uart_send_complete_flag = false;
  26.     return ch;
  27. }
  28. int _write(int fd,char *pBuffer,int size)
  29. {
  30.     for(int i=0;i<size;i++)
  31.     {
  32.         __io_putchar(*pBuffer++);
  33.     }
  34.     return size;
  35. }

  36. /*******************************************************************************************************************//**
  37. * main() is generated by the RA Configuration editor and is used to generate threads if an RTOS is used.  This function
  38. * is called by main() when no RTOS is used.
  39. **********************************************************************************************************************/
  40. void hal_entry(void)
  41. {
  42.     /* TODO: add your own code here */
  43.     err = R_SCI_UART_Open(&g_uart0_ctrl, &g_uart0_cfg);
  44.     assert(FSP_SUCCESS == err);
  45.     unsigned char buff[]="RA E2STUDIO";
  46.     uint8_t buff_len = strlen(buff);
  47.     err = R_SCI_UART_Write(&g_uart0_ctrl, buff, buff_len);
  48.     if(FSP_SUCCESS != err) __BKPT();
  49.     while(uart_send_complete_flag == false){}
  50.     uart_send_complete_flag = false;
  51.     sprintf(send_buff, "\nHello World!.\n");
  52.     uint8_t len = strlen(send_buff);
  53.     err = R_SCI_UART_Write(&g_uart0_ctrl, send_buff, len);
  54.     if(FSP_SUCCESS != err) __BKPT();
  55.     while(uart_send_complete_flag == false){}
  56.     uart_send_complete_flag = false;
  57.     memset(send_buff, '\0', sizeof(100));
  58.     int int_i=55;
  59.     float float_i=66.20f;
  60.     char char_i[]="hello e2studio";
  61.     while(1)
  62.     {
  63.         printf("int_i=%d\n",int_i);
  64.         printf("float_i=%.2f\n",float_i);
  65.         printf("char_i='%s'\n",char_i);
  66.         R_BSP_SoftwareDelay(1000, BSP_DELAY_UNITS_MILLISECONDS);
  67.         // NOLINT100->160
  68.     }

  69. #if BSP_TZ_SECURE_BUILD
  70.     /* Enter non-secure code */
  71.     R_BSP_NonSecureEnter();
  72. #endif
  73. }

  74. /*******************************************************************************************************************//**
  75. * This function is called at various points during the startup process.  This implementation uses the event that is
  76. * called right before main() to set up the pins.
  77. *
  78. * @param[in]  event    Where at in the start up process the code is currently at
  79. **********************************************************************************************************************/
  80. void R_BSP_WarmStart(bsp_warm_start_event_t event)
  81. {
  82.     if (BSP_WARM_START_RESET == event)
  83.     {
  84. #if BSP_FEATURE_FLASH_LP_VERSION != 0

  85.         /* Enable reading from data flash. */
  86.         R_FACI_LP->DFLCTL = 1U;

  87.         /* Would normally have to wait tDSTOP(6us) for data flash recovery. Placing the enable here, before clock and
  88.          * C runtime initialization, should negate the need for a delay since the initialization will typically take more than 6us. */
  89. #endif
  90.     }

  91.     if (BSP_WARM_START_POST_C == event)
  92.     {
  93.         /* C runtime environment and system clocks are setup. */

  94.         /* Configure pins. */
  95.         R_IOPORT_Open (&g_ioport_ctrl, g_ioport.p_cfg);
  96.     }
  97. }

  98. #if BSP_TZ_SECURE_BUILD

  99. BSP_CMSE_NONSECURE_ENTRY void template_nonsecure_callable ();

  100. /* Trustzone Secure Projects require at least one nonsecure callable function in order to build (Remove this if it is not required to build). */
  101. BSP_CMSE_NONSECURE_ENTRY void template_nonsecure_callable ()
  102. {

  103. }
  104. #endif
复制代码
8、编译后烧录到开发板:USB转TTL接到P100、P101上,打开串口助手,就可以收到开发板发出来的信息了:

【总结】根据教程一步一步就可以实现配置uart0,非常简单。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

3

主题

195

帖子

1241

积分

金牌会员

Rank: 6Rank: 6

积分
1241
发表于 2023-3-14 11:16:04 | 显示全部楼层

不错,学习一下
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

用户排行榜

RA助手

主题: 116帖子:133精华:0

RA_Lance

主题: 92帖子:132精华:9

lugl

主题: 38帖子:126精华:0

xujiwei263

主题: 16帖子:73精华:0

books咦

主题: 11帖子:11精华:2

Juggernaut

主题: 9帖子:95精华:0
快速回复 返回顶部 返回列表