本帖最后由 lugl4313820 于 2025-1-10 20:47 编辑
【前言】
感谢EEWORLD以及得捷电子组织这么好的活动,我也能荣幸的成为活动的一员。通过老师的细心教学,以及各位小伙伴位的无私分享了自己的代码,我经过两个月的学习,终于完成了所有的任务。下面我将逐一介绍我所完成的各项任务。
【硬件】
EK-RA6M5开发板:
【软件】
1、e2studio.
2、MobaXterm_Personal_24.0
3、jlink TTview
【经验分享】
1、【Follow me第二季第3期】基础任务 - DigiKey得捷技术专区 - 电子工程世界-论坛
2、【Follow me第二季第3期】基础任务quad-spi 和octo-spi flash对比速度测试 - DigiKey得捷技术专区 - 电子工程世界-论坛
3、【Follow me第二季第3期】DAC波形生成 - DigiKey得捷技术专区 - 电子工程世界-论坛
4、【Follow me第二季第3期】 [扩展任务] DAC输出不同波形,FLASH保存和读取历史数据 - DigiKey得捷技术专区 - 电子工程世界-论坛
【作品介绍】
1、环境创建
我使用的瑞萨的e2studio工具来创建,直接导入他的示例工程就行了。
编译:点击工程中的编译工具就行:
2、下载调试:
在下载调试之前要先按如下进行配置,需要选指定的工程,然后点调试就可以下载工程与调试:
【注】下载调式需要使用usb线插到调试接口:
3、blink与按键
首先我们要知道板载的LED与按键的对应的IO,在原理图上有介绍:
并且在工程的bsp_pin.h中也有标明:
然后在blink任务中使用非阻塞式来写入按键实现REDLED翻转的代码:
- /* TODO: add your own code here */
- while (1)
- {
-
- R_IOPORT_PinRead(&g_ioport_ctrl, BSP_IO_PORT_00_PIN_05, &p_port_value_port_004);
- if(!p_port_value_port_004)
- {
- sw_flage ++;
- if(sw_flage > 10) //如果计数达到10次,测表明已经按下,此处为消抖算法
- {
- //先读取LED灯的值,然后取反,实现翻转效果
- R_IOPORT_PinRead(&g_ioport_ctrl, BSP_IO_PORT_00_PIN_08, &p_port_value_red_led);
- R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_00_PIN_08, !p_port_value_red_led);
- }
- }
- else
- {
- sw_flage = 0;
-
- }
-
- vTaskDelay (1);
- }
1-3的作品详细介绍:【Follow me第二季第3期】基础任务 - DigiKey得捷技术专区 - 电子工程世界-论坛
4、添加命令打印
首先在menu_man.c的菜单数组中添加一行,一个为菜单,一个为回调函数
-
- static st_menu_fn_tbl_t s_menu_items[] =
- {
- {"Kit Information" , kis_display_menu},
- {"Web Server" , eth_emb_display_menu},
- {"Network Name Lookup" , eth_www_display_menu},
- {"Quad-SPI and Octo-SPI Speed Comparison" , ext_display_menu},
- {"Cryptography and USB High speed (MSC)" , enc_display_menu},
- {"DAC TEST" ,dac_display_menu},
- {"Next Steps", ns_display_menu },
- {"", NULL }
- };
-
然后创建DAC实现函数
菜单标题以及菜单命令列表:
- #define MODULE_NAME "\r\n DAC TEST\r\n"
-
- #define SUB_OPTIONS "\r\nMenu Options:" \
- "\r\n'a' - Increase waveform parameters" \
- "\r\n's' - Decrease waveform parameters" \
- "\r\n'r' - Read the waveform data from Quad-SPI flash into memory buffer" \
- "\r\n'w' - Write the current waveform data to Quad-SPI flash storage" \
- "\r\n'g' - Start generator" \
- "\r\n> Enter your choice and press tab to continue\r\n"
读取终端输入的命令并实现功能:
- * Function Name: ext_display_menu
- test_fn dac_display_menu(void)
- {
- DAC_Init();
-
-
- static int _maxvalue = 4095;
-
- int32_t c = -1;
- uint32_t block_size_actual = 0;
- int32_t block_sz_ndx = 0;
- int32_t block_sz_limit = (INPUT_BUFFER - 2);
- bool_t response_flag = false;
-
-
- sprintf(s_print_buffer, "%s%s", gp_clear_screen, gp_cursor_home);
-
-
- print_to_console((void*)s_print_buffer);
- sprintf(s_print_buffer, MODULE_NAME, g_selected_menu);
-
-
- print_to_console((void*)s_print_buffer);
- sprintf(s_print_buffer, SUB_OPTIONS);
-
-
- print_to_console((void*)s_print_buffer);
-
-
-
- block_sz_ndx = 0;
- memset(&s_block_sz_str, 0, INPUT_BUFFER);
- while (false == response_flag)
- {
- print_to_console("input: ");
- vTaskDelay(1);
- while ((CONNECTION_ABORT_CRTL != c))
- {
- c = input_from_console();
-
- if (c == 'a')
- {
- sprintf(s_print_buffer, "\r\nIncrease waveform parameters\r\n");
- print_to_console((void*)s_print_buffer);
-
- sprintf(s_print_buffer, "custom_var contains:\r\n");
- print_to_console((void *)s_print_buffer);
- _maxvalue += 500;
- if(_maxvalue >= 4095) _maxvalue = 4095;
- generateSineWaveIntegers(_maxvalue);
- for (uint32_t i = 0; i < 32; i++)
- {
- sprintf(s_print_buffer, "custom_var[%u] = %u\r\n", i, custom_var[i]);
- print_to_console((void *)s_print_buffer);
- }
- }
- if (c == 's')
- {
- sprintf(s_print_buffer, "\r\nDecrease waveform parameters\r\n");
- print_to_console((void*)s_print_buffer);
-
- sprintf(s_print_buffer, "custom_var contains:\r\n");
- print_to_console((void *)s_print_buffer);
- _maxvalue -= 500;
- if(_maxvalue < 0) _maxvalue = 1;
- generateSineWaveIntegers(_maxvalue);
- for (uint32_t i = 0; i < 32; i++)
- {
- sprintf(s_print_buffer, "custom_var[%u] = %u\r\n", i, custom_var[i]);
- print_to_console((void *)s_print_buffer);
- }
- }
- if (c == 'r')
- {
- sprintf(s_print_buffer, "\r\nRead the waveform data from Quad-SPI flash into memory buffer\r\n");
- print_to_console((void*)s_print_buffer);
- Read_Waveform_From_Flash(custom_var);
- is_custom_wave = true;
- sprintf(s_print_buffer, "After Reading, custom_var contains:\r\n");
- print_to_console((void *)s_print_buffer);
- for (uint32_t i = 0; i < 32; i++)
- {
- sprintf(s_print_buffer, "custom_var[%u] = %u\r\n", i, custom_var[i]);
- print_to_console((void *)s_print_buffer);
- }
-
- }
- else if (c == 'w')
- {
- sprintf(s_print_buffer, "\r\nWrite the current waveform data to Quad-SPI flash storage\r\n");
- print_to_console((void*)s_print_buffer);
- sprintf(s_print_buffer, "Before Writing, var contains:\r\n");
- print_to_console((void *)s_print_buffer);
- for (uint32_t i = 0; i < 32; i++)
- {
- sprintf(s_print_buffer, "var[%u] = %u\r\n", i, custom_var[i]);
- print_to_console((void *)s_print_buffer);
- }
- Write_Waveform_To_Flash(custom_var);
- }
- else if (c == 'g')
- {
- sprintf(s_print_buffer, "\r\nStart Generator...\r\n");
- print_to_console((void *)s_print_buffer);
- dac_start_flag = !dac_start_flag;
- }
-
- block_sz_ndx = 0;
- memset(&s_block_sz_str, 0, INPUT_BUFFER);
-
- if (MENU_EXIT_CRTL == c)
- {
- response_flag = true;
- block_size_actual = 0;
- break;
- }
-
- if (CARRAGE_RETURN != c)
- {
- sprintf(s_print_buffer, "%c", (char_t)c);
- print_to_console((void*)s_print_buffer);
- }
-
-
- }
- if ((MENU_EXIT_CRTL == c) || (0x00 == c))
- {
- break;
- }
-
- }
-
- return (0);
- }
- End of function ext_display_menu
这样就可以实现菜单实现了:
作品详细介绍连接:【Follow me第二季第3期】进阶任务——示例程序中新增命令打印信息: - DigiKey得捷技术专区 - 电子工程世界-论坛
5、【Follow me第二季第3期】DAC波形生成
在DAC中,首先使用RASC配置好DAC外设,在主程序中打开外设,然后使用一个while循环写入DAC的数值
主要代码为:
- * [url=home.php?mod=space&uid=159083]@brief[/url] Blinky example application
- void hal_entry (void)
- {
- #if BSP_TZ_SECURE_BUILD
-
-
- R_BSP_NonSecureEnter();
- #endif
- uint16_t v;
- uint8_t flag = 0;
-
- const bsp_delay_units_t bsp_delay_units = BSP_DELAY_UNITS_MICROSECONDS;
- R_DAC_Open(&g_dac0_ctrl, &g_dac0_cfg);
- R_DAC_Start(&g_dac0_ctrl);
-
- while(1)
- {
- if(0 == flag)
- {
- v = v+1;
- if(v == 4096)
- {
- flag = 1;
- }
- }
- else{
- v = v-1;
- if(0 == v)
- {
- flag = 0;
- }
- }
- v = v%4096;
- R_DAC_Write(&g_dac0_ctrl, v);
- R_BSP_SoftwareDelay(20, bsp_delay_units);
- }
-
-
- }
-
最后使用示例器来查看生成的波形:

详细分享如文章:【Follow me第二季第3期】DAC波形生成 - DigiKey得捷技术专区 - 电子工程世界-论坛
6、基础任务quad-spi 和octo-spi flash对比速度测试
测试结果:

具体任务分享:【Follow me第二季第3期】基础任务quad-spi 和octo-spi flash对比速度测试 - DigiKey得捷技术专区 - 电子工程世界-论坛
7、扩展任务,实现命令来输出波形,并可以进行调节,支持存储与读取:
【设计思路】
1、首先在前面的基础任务中初始化DAC、SPI FLASH、按键、命令接收等驱动。
2、生成一个正弦波的初始数据,放入缓冲区。
3、开始监听命令,如果接收到开始,则开启DAC波形输入,如果接收到保存数据,则执行把当前数据存入flash中,当有按键输入时,对波形数据进行放大或者缩小。
【程序流程】:
输出波形为,在blink_enty里面实现,实现无阻塞式的连续波形输入,同时用一个状态标志来实现开关:
- void blinky_thread_entry(void *pvParameters)
- {
- static int count;
- static uint8_t sw_flage;
- FSP_PARAMETER_NOT_USED (pvParameters);
- bsp_io_level_t p_port_value_port_004;
- bsp_io_level_t p_port_value_red_led;
-
-
-
- while (1)
- {
-
- R_IOPORT_PinRead(&g_ioport_ctrl, BSP_IO_PORT_00_PIN_05, &p_port_value_port_004);
- if(!p_port_value_port_004)
- {
- sw_flage ++;
- if(sw_flage > 10)
- {
- R_IOPORT_PinRead(&g_ioport_ctrl, BSP_IO_PORT_00_PIN_08, &p_port_value_red_led);
- R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_00_PIN_08, !p_port_value_red_led);
- }
- }
- else
- {
- sw_flage = 0;
-
- }
- if(dac_start_flag)
- {
- count ++;
- count = count%32;
- R_DAC_Write(&g_dac0_ctrl, custom_var[count]);
- }
- vTaskDelay (1);
- }
- }
在对波形进行调制中,我使用了sin函数对波形数据进行重新计算,并放入缓冲中:
-
- void generateSineWaveIntegers(int max_value) {
- for (int i = 0; i < ARRAY_SIZE; i++) {
- double x = (2 * PI * i) / (ARRAY_SIZE - 1);
- double sin_value = sin(x);
-
- double mapped_value = (sin_value + 1) / 2 * max_value;
- custom_var[i] = (uint16_t)round(mapped_value);
- }
- }
写入缓冲到spi flash中,其代码如下:
- **
- * @brief 将波形数据存储到 Quad Flash
- * @param buffer 需要存储的波形
- * @retval 无
- */
- void Write_Waveform_To_Flash(uint16_t *buffer)
- {
- fsp_err_t err = FSP_SUCCESS;
- uint32_t page_write_count = 0;
- uint8_t *p_mem_addr = (uint8_t *)QSPI_DEVICE_START_ADDRESS;
- spi_flash_protocol_t current_spi_mode;
-
-
- p_mem_addr = (uint8_t *)QSPI_DEVICE_START_ADDRESS;
-
-
- err = qpi_init();
- if (FSP_SUCCESS == err)
- {
-
- current_spi_mode = g_qspi_cfg.spi_protocol;
- }
-
- err = R_QSPI_Erase(&g_qspi_ctrl, p_mem_addr, SECTOR_SIZE);
- if (FSP_SUCCESS != err)
- {
- sprintf(s_print_buffer, "Failed to erase QSPI flash\r\n");
- return;
- }
-
- err = get_flash_status();
- if (FSP_SUCCESS != err)
- {
- sprintf(s_print_buffer, "Failed to get flash status after erase\r\n");
- return;
- }
-
-
- while (((page_write_count * PAGE_WRITE_SIZE) < sizeof(custom_var)) && (FSP_SUCCESS == err))
- {
- err = R_QSPI_Write(&g_qspi_ctrl, &buffer[page_write_count * PAGE_WRITE_SIZE / sizeof(uint16_t)], p_mem_addr, PAGE_WRITE_SIZE);
- if (FSP_SUCCESS != err)
- {
- sprintf(s_print_buffer, "Failed to write data to QSPI flash\r\n");
- }
- else
- {
- err = get_flash_status();
- if (FSP_SUCCESS != err)
- {
- sprintf(s_print_buffer, "Failed to get flash status after write\r\n");
- }
- }
- p_mem_addr += PAGE_WRITE_SIZE;
- page_write_count++;
- }
-
-
-
-
- deinit_qspi(current_spi_mode);
- }
-
读取存储数据到缓冲区中:
- /**
- * @brief 从 Quad Flash 读取波形数据
- * @param buffer 存储波形的缓冲区
- * @retval 无
- */
- void Read_Waveform_From_Flash(uint16_t *buffer)
- {
- fsp_err_t err = FSP_SUCCESS;
- uint32_t page_read_count = 0;
- uint8_t *p_mem_addr = (uint8_t *)QSPI_DEVICE_START_ADDRESS;
- spi_flash_protocol_t current_spi_mode;
-
-
- current_spi_mode = SPI_FLASH_PROTOCOL_EXTENDED_SPI;
-
-
-
- err = qpi_init();
- if (FSP_SUCCESS == err)
- {
-
- current_spi_mode = g_qspi_cfg.spi_protocol;
- }
-
-
- while ((page_read_count * PAGE_WRITE_SIZE) < sizeof(custom_var))
- {
- memcpy(&buffer[page_read_count * PAGE_WRITE_SIZE / sizeof(uint16_t)], p_mem_addr, PAGE_WRITE_SIZE);
- p_mem_addr += PAGE_WRITE_SIZE;
- page_read_count++;
- }
-
-
- deinit_qspi(current_spi_mode);
- }
-
然后组装从串口终端中的命令进行相应的事件处理:
- * Function Name: ext_display_menu
- test_fn dac_display_menu(void)
- {
- DAC_Init();
-
-
- static int _maxvalue = 4095;
-
- int32_t c = -1;
- uint32_t block_size_actual = 0;
- int32_t block_sz_ndx = 0;
- int32_t block_sz_limit = (INPUT_BUFFER - 2);
- bool_t response_flag = false;
-
-
- sprintf(s_print_buffer, "%s%s", gp_clear_screen, gp_cursor_home);
-
-
- print_to_console((void*)s_print_buffer);
- sprintf(s_print_buffer, MODULE_NAME, g_selected_menu);
-
-
- print_to_console((void*)s_print_buffer);
- sprintf(s_print_buffer, SUB_OPTIONS);
-
-
- print_to_console((void*)s_print_buffer);
-
-
-
- block_sz_ndx = 0;
- memset(&s_block_sz_str, 0, INPUT_BUFFER);
- while (false == response_flag)
- {
- print_to_console("input: ");
- vTaskDelay(1);
- while ((CONNECTION_ABORT_CRTL != c))
- {
- c = input_from_console();
-
- if (c == 'a')
- {
- sprintf(s_print_buffer, "\r\nIncrease waveform parameters\r\n");
- print_to_console((void*)s_print_buffer);
-
- sprintf(s_print_buffer, "custom_var contains:\r\n");
- print_to_console((void *)s_print_buffer);
- _maxvalue += 500;
- if(_maxvalue >= 4095) _maxvalue = 4095;
- generateSineWaveIntegers(_maxvalue);
- for (uint32_t i = 0; i < 32; i++)
- {
- sprintf(s_print_buffer, "custom_var[%u] = %u\r\n", i, custom_var[i]);
- print_to_console((void *)s_print_buffer);
- }
- }
- if (c == 's')
- {
- sprintf(s_print_buffer, "\r\nDecrease waveform parameters\r\n");
- print_to_console((void*)s_print_buffer);
-
- sprintf(s_print_buffer, "custom_var contains:\r\n");
- print_to_console((void *)s_print_buffer);
- _maxvalue -= 500;
- if(_maxvalue < 0) _maxvalue = 1;
- generateSineWaveIntegers(_maxvalue);
- for (uint32_t i = 0; i < 32; i++)
- {
- sprintf(s_print_buffer, "custom_var[%u] = %u\r\n", i, custom_var[i]);
- print_to_console((void *)s_print_buffer);
- }
- }
- if (c == 'r')
- {
- sprintf(s_print_buffer, "\r\nRead the waveform data from Quad-SPI flash into memory buffer\r\n");
- print_to_console((void*)s_print_buffer);
- Read_Waveform_From_Flash(custom_var);
- is_custom_wave = true;
- sprintf(s_print_buffer, "After Reading, custom_var contains:\r\n");
- print_to_console((void *)s_print_buffer);
- for (uint32_t i = 0; i < 32; i++)
- {
- sprintf(s_print_buffer, "custom_var[%u] = %u\r\n", i, custom_var[i]);
- print_to_console((void *)s_print_buffer);
- }
-
- }
- else if (c == 'w')
- {
- sprintf(s_print_buffer, "\r\nWrite the current waveform data to Quad-SPI flash storage\r\n");
- print_to_console((void*)s_print_buffer);
- sprintf(s_print_buffer, "Before Writing, var contains:\r\n");
- print_to_console((void *)s_print_buffer);
- for (uint32_t i = 0; i < 32; i++)
- {
- sprintf(s_print_buffer, "var[%u] = %u\r\n", i, custom_var[i]);
- print_to_console((void *)s_print_buffer);
- }
- Write_Waveform_To_Flash(custom_var);
- }
- else if (c == 'g')
- {
- sprintf(s_print_buffer, "\r\nStart Generator...\r\n");
- print_to_console((void *)s_print_buffer);
- dac_start_flag = !dac_start_flag;
- }
-
- block_sz_ndx = 0;
- memset(&s_block_sz_str, 0, INPUT_BUFFER);
-
- if (MENU_EXIT_CRTL == c)
- {
- response_flag = true;
- block_size_actual = 0;
- break;
- }
-
- if (CARRAGE_RETURN != c)
- {
- sprintf(s_print_buffer, "%c", (char_t)c);
- print_to_console((void*)s_print_buffer);
- }
-
-
- }
- if ((MENU_EXIT_CRTL == c) || (0x00 == c))
- {
- break;
- }
-
- }
-
- return (0);
- }
- End of function ext_display_menu
工程介绍如下:
【活动心得体会】
1、这次活动,有非常好的老师进行教学,提供的教程非常的详细,经过我的仔细学习,掌握了瑞萨RA6M5的工程创建、下载、调试等基本方法。
2、这次的任务涵盖的知识面宽,尽管学习花费了许多的时间,才完成所有的任务,收获也是非常大的,特别是RA6M5的USB外设、SPI_FLASH,我都是第一次接触,对我们工程师帮助非常大。
3、组织的老师也非常给力,细心的解答我们在活动中遇到的问题。
总之,通过这次活动,使得我对瑞萨的RA6M5有了非常详尽的了解,希望在今后的工程中能用到。再次感谢EEWORLD、得捷电子。
|