查看: 896|回复: 2

【瑞萨RA4系列开发板体验】+ E2 studio 初体验LED点灯和printf...

[复制链接]

116

主题

133

帖子

3768

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
3768
发表于 2023-2-24 16:42:59 | 显示全部楼层 |阅读模式
【瑞萨RA4系列开发板体验】+ E2 studio 初体验LED点灯和printf重定向
作者:jf_66383146

A.非常感谢论坛和瑞萨的活动
B.没有用过瑞萨的开发环境,上手比较简单,要深入还是需要时间研究,逻辑和stm32还是有比较大的区别
话不多说直接入主题
1.打开E2左上角 file->new project
如图
2.依次点击 renesas RA-> renesas RA C/C++ project->next
3.输入项目名称(不能含中文和中文符号)
选择自己的芯片型号
进入工程界面
配置堆栈大小
配置串口
原理图是P110,P109
LED配置
LED原理图
printf重定向
快捷键 ctrl+alt+p进入项目设置
hal_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;
  7. unsigned char send_buff[100];
  8. volatile bool uart_send_complete_flag = false;
  9. void user_uart_callback(uart_callback_args_t *p_args)
  10. {
  11.     if (p_args->event == UART_EVENT_TX_COMPLETE)
  12.     {
  13.         uart_send_complete_flag = true;
  14.     }
  15. }

  16. #ifdef __GNUC__                                 //串口重定向
  17. #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
  18. #else
  19. #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
  20. #endif
  21. PUTCHAR_PROTOTYPE
  22. {
  23.     err = R_SCI_UART_Write (&g_uart9_ctrl, (uint8_t*) &ch, 1);
  24.     if (FSP_SUCCESS != err)
  25.         __BKPT();
  26.     while (uart_send_complete_flag == false)
  27.     {
  28.     }
  29.     uart_send_complete_flag = false;
  30.     return ch;
  31. }

  32. int _write(int fd, char *pBuffer, int size)
  33. {
  34.     for (int i = 0; i < size; i++)
  35.     {
  36.         __io_putchar (*pBuffer++);
  37.     }
  38.     return size;
  39. }
  40. void hal_entry(void) //入口函数
  41. {
  42.     /* TODO: add your own code here */

  43.     /* Open the transfer instance with initial configuration. */

  44.     err = R_SCI_UART_Open (&g_uart9_ctrl, &g_uart9_cfg); //初始化串口和使能
  45.     assert(FSP_SUCCESS == err);
  46.     int int_i = 55;
  47.     float float_i = 66.20f;
  48.     char char_i[] = "hello e2studio";
  49.     while (1)
  50.     {
  51.         R_IOPORT_PinWrite (&g_ioport_ctrl, BSP_IO_PORT_04_PIN_15, BSP_IO_LEVEL_LOW);//LED灭
  52.         R_BSP_SoftwareDelay (500, BSP_DELAY_UNITS_MILLISECONDS); // 延时0.5s
  53.         printf ("int_i=%d\r\n", int_i);
  54.         printf ("float_i=%.2f\r\n", float_i);
  55.         printf ("char_i='%s'\r\n", char_i);

  56.         R_IOPORT_PinWrite (&g_ioport_ctrl, BSP_IO_PORT_04_PIN_15, BSP_IO_LEVEL_HIGH);//LED亮
  57.         R_BSP_SoftwareDelay (500, BSP_DELAY_UNITS_MILLISECONDS); // 延时0.5s
  58.     }
  59. #if BSP_TZ_SECURE_BUILD
  60.     /* Enter non-secure code */
  61.     R_BSP_NonSecureEnter();
  62. #endif
  63. }
  64. /*******************************************************************************************************************//**
  65. * This function is called at various points during the startup process.  This implementation uses the event that is
  66. * called right before main() to set up the pins.
  67. *
  68. * @param[in]  event    Where at in the start up process the code is currently at
  69. **********************************************************************************************************************/
  70. void R_BSP_WarmStart(bsp_warm_start_event_t event)
  71. {
  72.     if (BSP_WARM_START_RESET == event)
  73.     {
  74. #if BSP_FEATURE_FLASH_LP_VERSION != 0

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

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

  81.     if (BSP_WARM_START_POST_C == event)
  82.     {
  83.         /* C runtime environment and system clocks are setup. */

  84.         /* Configure pins. */
  85.         R_IOPORT_Open (&g_ioport_ctrl, g_ioport.p_cfg);
  86.     }
  87. }

  88. #if BSP_TZ_SECURE_BUILD

  89. BSP_CMSE_NONSECURE_ENTRY void template_nonsecure_callable ();

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

  93. }
  94. #endif
复制代码
编译输出
串口输出


回复

使用道具 举报

9

主题

95

帖子

9257

积分

论坛元老

Rank: 8Rank: 8

积分
9257
发表于 2023-2-25 15:04:53 | 显示全部楼层

E2 studio 自成一体
回复

使用道具 举报

3

主题

195

帖子

1090

积分

金牌会员

Rank: 6Rank: 6

积分
1090
发表于 2023-3-14 10:13:11 | 显示全部楼层

学习了,不错
回复

使用道具 举报

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

本版积分规则

用户排行榜

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
快速回复 返回顶部 返回列表