原创 【瑞萨 RA6E2】+按键LED+串口中断收发+内部虚拟EEPROM

2023-7-24 13:37 604 3 3 分类: MCU/ 嵌入式 文集: 瑞萨
硬件:瑞萨RA6E2
软件:FSP 4.0.5 / e2studio (需要使用4.0.5才可以选择RA6E2的芯片R7FA6E2BB3CFM
资料参考:
新建工程流程:
文件->新建->瑞萨C/C++项目->Renesas RA



选择保存工程的路径

选择芯片型号

一· 按键LED
LED灯和按键原理图

LED灯引脚配置

按键引脚配置



stack配置


  1. #define USER_SW_IRQ_NUMBER ( 10 )
  2. volatile bool g_sw_press = false;
  3. void hal_entry(void)
  4. {
  5. /* TODO: add your own code here */
  6. bsp_io_level_t led_current_state = (bsp_io_level_t) 0x01;
  7.        /* 打开外部中断*/
  8. R_ICU_ExternalIrqOpen(&g_external_irq0_ctrl, &g_external_irq0_cfg);</p><p>/*使能外部中断*/
  9. R_ICU_ExternalIrqEnable(&g_external_irq0_ctrl);
  10. while (true)
  11. {
  12. /* Toggle user LED when user pushbutton is pressed*/
  13. if(true == g_sw_press)
  14. {
  15. /* Clear user pushbutton flag */
  16. g_sw_press = false;
  17. /* Read user LED pin */
  18. R_IOPORT_PinRead(&g_ioport_ctrl, LED1, &led_current_state);
  19. /* Reverse LED pin state*/
  20. led_current_state ^= BSP_IO_LEVEL_HIGH;
  21. /* Toggle user LED */
  22. R_IOPORT_PinWrite(&g_ioport_ctrl, LED1, led_current_state);
  23. R_IOPORT_PinRead(&g_ioport_ctrl, LED2, &led_current_state);
  24. led_current_state ^= BSP_IO_LEVEL_HIGH;
  25. R_IOPORT_PinWrite(&g_ioport_ctrl, LED2, led_current_state);
  26. }
  27. }
  28. #if BSP_TZ_SECURE_BUILD
  29. /* Enter non-secure code */
  30. R_BSP_NonSecureEnter();
  31. #endif
  32. }
  33. void irq_ep_callback(external_irq_callback_args_t *p_args)
  34. {
  35. if (USER_SW_IRQ_NUMBER == p_args->channel)
  36. {
  37. g_sw_press = true;
  38. }
  39. }


二· 串口收发

串口原理图

注意:需要用跳帽连接如下位置


串口配置

引脚配置



代码参考的是野火

SCI UART——串口通信
三· 内部虚拟EEPROM使用
RA6E2有4KB 虚拟EEPROM,也就是4096字节,但是由于使用rm_vee_flash组件实际只有2028字节可以使用



  1. void rm_vee_example();
  2. /* 用于写数据完成*/
  3. volatile bool callback_called = false;
  4. /* 内部大小是4kb, 每个字节占用2byte大小,理论存储2048字节,
  5. * 每一条记录需要8字节的数据的开头和结尾,占用16字节,所以只有2032字节可以使用,还要预留Padding 3字节
  6. */
  7. /* 写入数据的长度*/
  8. #define DATA_SIZE ( 2028 )
  9. /* Record ID 用来记录存取的数据 0-15*/
  10. #define ID_TESTDATA ( 1U )
  11. /* Example data Structure*/
  12. uint8_t data[DATA_SIZE] = {0};
  13. uint8_t data_recv[DATA_SIZE] = { 0 };
  14. uint8_t data_recv1[DATA_SIZE] = { 0 };
  15. uint32_t length = DATA_SIZE;
  16. /*******************************************************************************************************************//**
  17. * @brief 这个函数擦除VEEPROM使用的整个数据闪存。
  18. * @param[IN] None
  19. * @retval FSP_SUCCESS 格式化成功除
  20. * @retval FSP_SUCCESSFSP_SUCCESS之外的任何其他错误码
  21. **********************************************************************************************************************/
  22. fsp_err_t vee_format_operation(void)
  23. {
  24. fsp_err_t err = FSP_SUCCESS;
  25. uint8_t ref_data = 0;
  26. rm_vee_status_t p_status;
  27. /* Start a manual format operation.*/
  28. err = RM_VEE_FLASH_Format(&g_vee0_ctrl, &ref_data);
  29. if(FSP_SUCCESS != err)
  30. {
  31. return err;
  32. }
  33. /* Get the current status of the driver.*/
  34. err = RM_VEE_FLASH_StatusGet(&g_vee0_ctrl, &p_status);
  35. if(FSP_SUCCESS != err)
  36. {
  37. return err;
  38. }
  39. /* Compare Last ID written with Default ID.*/
  40. if (ID_TESTDATA == p_status.last_id)
  41. {
  42. }
  43. else
  44. {
  45. err = FSP_ERR_NOT_ERASED;
  46. }
  47. return err;
  48. }
  49. void rm_vee_example()
  50. {
  51. int i = 0;
  52. uint8_t *data_ptr1 = 0;
  53. uint8_t *data_ptr2 = 0;
  54. /* 打开 Virtual EEPROM Module. */
  55. fsp_err_t err = RM_VEE_FLASH_Open(&g_vee0_ctrl, &g_vee0_cfg);
  56. assert(FSP_SUCCESS == err);
  57. /* 格式化EEPROM*/
  58. // vee_format_operation();
  59. /* 先读一次,表示断电后读取数据,验证数据的正确性*/
  60. err = RM_VEE_FLASH_RecordPtrGet(&g_vee0_ctrl, ID_TESTDATA,
  61. (uint8_t **) &data_ptr1, &length);
  62. for(i = 0; i < DATA_SIZE; ++i)
  63. data_recv1[i] = *data_ptr1++;
  64. length = DATA_SIZE;
  65. /* 填充数据*/
  66. for (i = 0; i < DATA_SIZE; ++i)
  67. {
  68. data[i] = (uint8_t)i;
  69. }
  70. /* Write the pressure data to a Virtual EEPROM Record. */
  71. err = RM_VEE_FLASH_RecordWrite(&g_vee0_ctrl, ID_TESTDATA,
  72. (uint8_t *)data, length);
  73. assert(FSP_SUCCESS == err);
  74. /* Wait for the Virtual EEPROM callback to indicate it finished writing data. */
  75. while (false == callback_called);
  76. /* Get a pointer to the record that is stored in data flash. */
  77. err = RM_VEE_FLASH_RecordPtrGet(&g_vee0_ctrl, ID_TESTDATA,
  78. (uint8_t **) &data_ptr2, &length);
  79. assert(FSP_SUCCESS == err);
  80. for(i = 0; i < DATA_SIZE; ++i)
  81. data_recv[i] = *data_ptr2++;
  82. //读取数据与写入数据一致则点亮蓝色LED灯
  83. R_IOPORT_PinWrite(&g_ioport_ctrl, LED1, BSP_IO_LEVEL_LOW);
  84. for (i = 0; i < DATA_SIZE; ++i)
  85. {
  86. if (data[i] != data_recv[i])
  87. break;
  88. }
  89. if (i == DATA_SIZE)
  90. R_IOPORT_PinWrite(&g_ioport_ctrl, LED1, BSP_IO_LEVEL_HIGH);
  91. /* Close the Virtual EEPROM Module. */
  92. err = RM_VEE_FLASH_Close(&g_vee0_ctrl);
  93. assert(FSP_SUCCESS == err);
  94. }
  95. void vee_callback(rm_vee_callback_args_t *p_args)
  96. {
  97. FSP_PARAMETER_NOT_USED(p_args);
  98. callback_called = true;
  99. }



  1. void hal_entry(void)
  2. {
  3. /* TODO: add your own code here */
  4. rm_vee_example();
  5. #if BSP_TZ_SECURE_BUILD
  6. /* Enter non-secure code */
  7. R_BSP_NonSecureEnter();
  8. #endif
  9. }

作者: 莫羨, 来源:面包板社区

链接: https://mbb.eet-china.com/blog/uid-me-4040671.html

版权声明:本文为博主原创,未经本人允许,禁止转载!

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
3
关闭 站长推荐上一条 /3 下一条