【Follow me第二季第3期】作业任务提交
[复制链接]
本帖最后由 Juggernaut 于 2025-1-7 22:57 编辑
首先,真心感谢eeworld && digikey!感谢提供一个很好的学习机会,同时感谢瑞萨做workshop的同学,细致的讲解,反正我看了不下十次。
作业内容:
【所有任务视频】
859
【任务实现详情】
首先环境搭建出了点小问题,全靠教学视频和大佬们的帮助:
1. 【Follow me第二季第3期】哪位真的按照视频指南完成了E2 STUDIO环境搭建? - DigiKey得捷技术专区 - 电子工程世界-论坛
2. 【Follow me第二季第3期】这个estudio神了,环境设置问题 - DigiKey得捷技术专区 - 电子工程世界-论坛
环境搭建好了后的作业:
3.【Follow me第二季第3期】搭建环境&下载调试示例程序 - DigiKey得捷技术专区 - 电子工程世界-论坛
IDE环境是:setup_fsp_v5_6_0_e2s_v2024-1
FSP的案例是:ra-fsp-examples-master
运行demo效果如下:
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
4. 【Follow me第二季第3期】入门任务:Blink,按键 - DigiKey得捷技术专区 - 电子工程世界-论坛
物料清单:就是EK-RA6M5开发板;
主要思路:通过RASC配置好LED1 LED2和按键;
实现代码:
R_IOPORT_PinRead(&g_ioport_ctrl, BSP_IO_PORT_00_PIN_05, &key_state);
if(key_state==BSP_IO_LEVEL_LOW){
//软件消抖
R_BSP_SoftwareDelay(10, BSP_DELAY_UNITS_MILLISECONDS);
//点亮LED3
R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_00_PIN_08, BSP_IO_LEVEL_HIGH); //LED3亮
//等待按键松开
while(key_state==BSP_IO_LEVEL_LOW)
{
R_IOPORT_PinRead(&g_ioport_ctrl, BSP_IO_PORT_00_PIN_05, &key_state);
}
//熄灭LED3
R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_00_PIN_08, BSP_IO_LEVEL_LOW); //LED3灭
}
效果图:
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
5. 【Follow me第二季第3期】基础任务:quad-spi flash和octo-spi flash配置及读写速... - DigiKey得捷技术专区 - 电子工程世界-论坛
物料清单:就是EK-RA6M5开发板;
主要思路:通过RASC配置好QSPI 和 OSPI;
实现代码:
void ospi_performance_test(uint32_t data_size,
uint32_t *ospi_performance_write_result,
uint32_t *ospi_performance_read_result)
{
fsp_err_t err;
uint32_t i = 1;
if (R_CGC_Open (g_cgc.p_ctrl, g_cgc.p_cfg) != FSP_SUCCESS)
{
__asm("bkpt");
}
while (i)
{
err = R_OSPI_Open(g_ospi.p_ctrl, g_ospi.p_cfg);
if (FSP_SUCCESS != err)
{
__asm("bkpt");
}
#if HIGH_SPEED_MODE
configure_dopi_ospi();
ospi_test_wait_until_wip();
#endif
*ospi_performance_write_result = write_dopi_ospi(data_size);
ospi_test_wait_until_wip();
*ospi_performance_read_result = read_dopi_ospi(data_size);
ospi_test_wait_until_wip();
erase_dopi_ospi();
ospi_test_wait_until_wip();
#if HIGH_SPEED_MODE
configure_spi_ospi();
ospi_test_wait_until_wip();
#endif
err = R_OSPI_Close(g_ospi.p_ctrl);
if (FSP_SUCCESS != err)
{
__asm("bkpt");
}
i--;
}
}
static uint32_t qspi_write_test(uint32_t block_size)
{
fsp_err_t fsp_err;
uint32_t qspi_write_result = 0;
timer_status_t status = {};
fsp_err_t err = FSP_SUCCESS;
spi_flash_protocol_t current_spi_mode;
/* Convert from kB */
block_size *= 1024;
/* The comms mode is EXTENDED_SPI by default */
current_spi_mode = SPI_FLASH_PROTOCOL_EXTENDED_SPI;
/* initialise the QSPI, and change mode to that set in FSP */
err = qpi_init();
if (FSP_SUCCESS == err)
{
/* The comms mode has changed. So if recovering, this new mode required */
current_spi_mode = g_qspi_cfg.spi_protocol;
}
uint32_t page_write_count = 0;
uint8_t * p_mem_addr;
/* Cast to req type */
p_mem_addr = (uint8_t *)QSPI_DEVICE_START_ADDRESS;
while (((page_write_count * SECTOR_SIZE) < block_size)
&& ( FSP_SUCCESS == err ) )
{
/* Erase Flash for one sector */
err = R_QSPI_Erase(&g_qspi_ctrl, p_mem_addr, SECTOR_SIZE);
if (FSP_SUCCESS != err)
{
sprintf(s_print_buffer, "R_QSPI_Erase Failed\r\n");
}
else
{
err = get_flash_status();
if (FSP_SUCCESS != err)
{
sprintf(s_print_buffer, "Failed to get status for QSPI operation\r\n");
}
/* Verify the erased block data */
uint32_t count;
for (count = 0; count < SECTOR_SIZE; count++ )
{
if (DEFAULT_MEM_VAL != p_mem_addr[count])
{
/* Verification failed, perhaps the ERASE failed */
err = FSP_ERR_NOT_ERASED;
}
}
}
p_mem_addr += SECTOR_SIZE;
page_write_count++;
}
/* Start the test timer */
fsp_err = R_GPT_Start(g_memory_performance.p_ctrl);
/* Handle error */
if (FSP_SUCCESS != fsp_err)
{
/* Fatal error */
SYSTEM_ERROR
}
/* Cast to req type */
p_mem_addr = (uint8_t *)QSPI_DEVICE_START_ADDRESS;
page_write_count = 0;
while (((page_write_count * PAGE_WRITE_SIZE) < block_size)
&& (FSP_SUCCESS == err))
{
if (FSP_SUCCESS == err)
{
/* Write data to QSPI Flash */
/* Each block begins one character shifted along the source text. To avoid regular striping in memory */
err = R_QSPI_Write(&g_qspi_ctrl, &(sp_source[page_write_count]), p_mem_addr, PAGE_WRITE_SIZE);
if (FSP_SUCCESS != err)
{
sprintf(s_print_buffer, "R_QSPI_Write Failed\r\n");
}
else
{
err = get_flash_status();
if (FSP_SUCCESS != err)
{
sprintf(s_print_buffer, "Failed to get status for QSPI operation\r\n");
}
}
}
p_mem_addr += PAGE_WRITE_SIZE;
page_write_count++;
}
/* close QSPI module */
deinit_qspi(current_spi_mode);
fsp_err = R_GPT_Stop(g_memory_performance.p_ctrl);
/* Handle error */
if (FSP_SUCCESS != fsp_err)
{
/* Fatal error */
SYSTEM_ERROR
}
fsp_err = R_GPT_StatusGet(g_memory_performance.p_ctrl, &status);
/* Handle error */
if (FSP_SUCCESS != fsp_err)
{
/* Fatal error */
SYSTEM_ERROR
}
fsp_err = R_GPT_Reset(g_memory_performance.p_ctrl);
/* Handle error */
if (FSP_SUCCESS != fsp_err)
{
/* Fatal error */
SYSTEM_ERROR
}
qspi_write_result = status.counter;
return (qspi_write_result);
}
效果图:
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
6. 【Follow me第二季第3期】基础任务:DAC配置生成波形及性能测试 - DigiKey得捷技术专区 - 电子工程世界-论坛
物料清单:就是EK-RA6M5开发板;
主要思路:通过RASC配置好DAC和 GPT;
实现代码:
void g_timer0_callback(timer_callback_args_t * p_args)
{
uint16_t dacvalue=0;
static double w=0.0;
w+=M_PI/90;
if(w>=2*M_PI)
{
w=0.0;
}
dacvalue=(sin(w) + 1) / 2 * 4096;
R_DAC_Write(&g_dac0_ctrl, dacvalue);
}
效果图:
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
7. 【Follow me第二季第3期】进阶任务:示例程序中新增命令打印信息 - DigiKey得捷技术专区 - 电子工程世界-论坛
物料清单:就是EK-RA6M5开发板;
主要思路:找到s_menu_items[]数组,该数组主要用于路由菜单内容,按规定添加测试内容即可;
实现代码:
test_fn kis_follow_menu(void)
{
int8_t c = -1;
bsp_unique_id_t const * p_uid = R_BSP_UniqueIdGet ();
sprintf (s_print_buffer, "%s%s", gp_clear_screen, gp_cursor_home);
/* ignoring -Wpointer-sign is OK when treating signed char_t array as as unsigned */
print_to_console((void*)s_print_buffer);
sprintf (s_print_buffer, MODULE_NAME, g_selected_menu);
/* ignoring -Wpointer-sign is OK when treating signed char_t array as as unsigned */
print_to_console((void*)s_print_buffer);
/* provide small delay so board_status should be up to date */
vTaskDelay (s_ticks_to_wait);
xEventGroupSetBits (g_update_console_event, STATUS_DISPLAY_MENU_KIS);
while (CONNECTION_ABORT_CRTL != c)
{
c = input_from_console ();
if ((MENU_EXIT_CRTL == c) || (CONNECTION_ABORT_CRTL == c))
{
break;
}
}
xEventGroupClearBits (g_update_console_event, STATUS_DISPLAY_MENU_KIS);
return (0);
}
效果图:
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
8. 【Follow me第二季第3期】扩展任务:一个波形信号发生器 - DigiKey得捷技术专区 - 电子工程世界-论坛
物料清单:就是EK-RA6M5开发板;
主要思路:直接产生正弦波和三角波,保存在数组中,然后将信号类型存储在flash上,此处选择QSPI flash。
实现代码:
size_t half_period = size / 2; // Half period of the triangle wave
for (size_t i = 0; i < size; i++)
{
if (i < half_period)
{
// Rising edge: 0 to 4096
array[i] = (uint16_t) ((double) i / (half_period - 1) * 4096);
}
else
{
// Falling edge: 4096 to 0
array[i] = (uint16_t) ((double) (size - i - 1) / (half_period - 1) * 4096);
}
}
效果图:
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
【心得体会】
1. RASC工具真心好用,外设配置个人感觉比cubeMX不相上下;E2 studio第一次用,总体上不错,弱弱的建议:能否加个固件“下载”按钮?
2. 第一次接触信号波形,跟着大部队跌跌撞撞的学习然后实现自己的功能,感觉很棒,要是有个示波器就好了;
3. 任务安排的比较合理,循序渐进,譬如现在让我去做blink的功能,我就会选择中断的方式实现LED灯亮灯灭,而不是最初的监视按键电平。
【源码】
最后,再次感谢eeworld && digikey!!
|