原创
【瑞萨 RA6E2】+按键LED+串口中断收发+内部虚拟EEPROM
硬件:瑞萨RA6E2
软件:FSP 4.0.5 / e2studio (需要使用4.0.5才可以选择RA6E2的芯片R7FA6E2BB3CFM)
资料参考:
新建工程流程:
文件->新建->瑞萨C/C++项目->Renesas RA
一· 按键LED
LED灯和按键原理图
LED灯引脚配置
按键引脚配置
stack配置
- #define USER_SW_IRQ_NUMBER ( 10 )
- volatile bool g_sw_press = false;
- void hal_entry(void)
- {
- /* TODO: add your own code here */
- bsp_io_level_t led_current_state = (bsp_io_level_t) 0x01;
- /* 打开外部中断*/
- R_ICU_ExternalIrqOpen(&g_external_irq0_ctrl, &g_external_irq0_cfg);</p><p>/*使能外部中断*/
- R_ICU_ExternalIrqEnable(&g_external_irq0_ctrl);
- while (true)
- {
- /* Toggle user LED when user pushbutton is pressed*/
- if(true == g_sw_press)
- {
- /* Clear user pushbutton flag */
- g_sw_press = false;
- /* Read user LED pin */
- R_IOPORT_PinRead(&g_ioport_ctrl, LED1, &led_current_state);
- /* Reverse LED pin state*/
- led_current_state ^= BSP_IO_LEVEL_HIGH;
- /* Toggle user LED */
- R_IOPORT_PinWrite(&g_ioport_ctrl, LED1, led_current_state);
- R_IOPORT_PinRead(&g_ioport_ctrl, LED2, &led_current_state);
- led_current_state ^= BSP_IO_LEVEL_HIGH;
- R_IOPORT_PinWrite(&g_ioport_ctrl, LED2, led_current_state);
- }
- }
- #if BSP_TZ_SECURE_BUILD
- /* Enter non-secure code */
- R_BSP_NonSecureEnter();
- #endif
- }
- void irq_ep_callback(external_irq_callback_args_t *p_args)
- {
- if (USER_SW_IRQ_NUMBER == p_args->channel)
- {
- g_sw_press = true;
- }
- }
二· 串口收发
串口原理图
注意:需要用跳帽连接如下位置
串口配置
引脚配置
代码参考的是野火
SCI UART——串口通信三· 内部虚拟EEPROM使用
RA6E2有4KB 虚拟EEPROM,也就是4096字节,但是由于使用rm_vee_flash组件实际只有2028字节可以使用
- void rm_vee_example();
- /* 用于写数据完成*/
- volatile bool callback_called = false;
- /* 内部大小是4kb, 每个字节占用2byte大小,理论存储2048字节,
- * 每一条记录需要8字节的数据的开头和结尾,占用16字节,所以只有2032字节可以使用,还要预留Padding 3字节
- */
- /* 写入数据的长度*/
- #define DATA_SIZE ( 2028 )
- /* Record ID 用来记录存取的数据 0-15*/
- #define ID_TESTDATA ( 1U )
- /* Example data Structure*/
- uint8_t data[DATA_SIZE] = {0};
- uint8_t data_recv[DATA_SIZE] = { 0 };
- uint8_t data_recv1[DATA_SIZE] = { 0 };
- uint32_t length = DATA_SIZE;
- /*******************************************************************************************************************//**
- * @brief 这个函数擦除VEEPROM使用的整个数据闪存。
- * @param[IN] None
- * @retval FSP_SUCCESS 格式化成功除
- * @retval FSP_SUCCESSFSP_SUCCESS之外的任何其他错误码
- **********************************************************************************************************************/
- fsp_err_t vee_format_operation(void)
- {
- fsp_err_t err = FSP_SUCCESS;
- uint8_t ref_data = 0;
- rm_vee_status_t p_status;
- /* Start a manual format operation.*/
- err = RM_VEE_FLASH_Format(&g_vee0_ctrl, &ref_data);
- if(FSP_SUCCESS != err)
- {
- return err;
- }
- /* Get the current status of the driver.*/
- err = RM_VEE_FLASH_StatusGet(&g_vee0_ctrl, &p_status);
- if(FSP_SUCCESS != err)
- {
- return err;
- }
- /* Compare Last ID written with Default ID.*/
- if (ID_TESTDATA == p_status.last_id)
- {
- }
- else
- {
- err = FSP_ERR_NOT_ERASED;
- }
- return err;
- }
- void rm_vee_example()
- {
- int i = 0;
- uint8_t *data_ptr1 = 0;
- uint8_t *data_ptr2 = 0;
- /* 打开 Virtual EEPROM Module. */
- fsp_err_t err = RM_VEE_FLASH_Open(&g_vee0_ctrl, &g_vee0_cfg);
- assert(FSP_SUCCESS == err);
- /* 格式化EEPROM*/
- // vee_format_operation();
- /* 先读一次,表示断电后读取数据,验证数据的正确性*/
- err = RM_VEE_FLASH_RecordPtrGet(&g_vee0_ctrl, ID_TESTDATA,
- (uint8_t **) &data_ptr1, &length);
- for(i = 0; i < DATA_SIZE; ++i)
- data_recv1[i] = *data_ptr1++;
- length = DATA_SIZE;
- /* 填充数据*/
- for (i = 0; i < DATA_SIZE; ++i)
- {
- data[i] = (uint8_t)i;
- }
- /* Write the pressure data to a Virtual EEPROM Record. */
- err = RM_VEE_FLASH_RecordWrite(&g_vee0_ctrl, ID_TESTDATA,
- (uint8_t *)data, length);
- assert(FSP_SUCCESS == err);
- /* Wait for the Virtual EEPROM callback to indicate it finished writing data. */
- while (false == callback_called);
- /* Get a pointer to the record that is stored in data flash. */
- err = RM_VEE_FLASH_RecordPtrGet(&g_vee0_ctrl, ID_TESTDATA,
- (uint8_t **) &data_ptr2, &length);
- assert(FSP_SUCCESS == err);
- for(i = 0; i < DATA_SIZE; ++i)
- data_recv[i] = *data_ptr2++;
- //读取数据与写入数据一致则点亮蓝色LED灯
- R_IOPORT_PinWrite(&g_ioport_ctrl, LED1, BSP_IO_LEVEL_LOW);
- for (i = 0; i < DATA_SIZE; ++i)
- {
- if (data[i] != data_recv[i])
- break;
- }
- if (i == DATA_SIZE)
- R_IOPORT_PinWrite(&g_ioport_ctrl, LED1, BSP_IO_LEVEL_HIGH);
- /* Close the Virtual EEPROM Module. */
- err = RM_VEE_FLASH_Close(&g_vee0_ctrl);
- assert(FSP_SUCCESS == err);
- }
- void vee_callback(rm_vee_callback_args_t *p_args)
- {
- FSP_PARAMETER_NOT_USED(p_args);
- callback_called = true;
- }
- void hal_entry(void)
- {
- /* TODO: add your own code here */
- rm_vee_example();
- #if BSP_TZ_SECURE_BUILD
- /* Enter non-secure code */
- R_BSP_NonSecureEnter();
- #endif
- }
作者: 莫羨, 来源:面包板社区
链接: https://mbb.eet-china.com/blog/uid-me-4040671.html
版权声明:本文为博主原创,未经本人允许,禁止转载!
文章评论(0条评论)
登录后参与讨论