【瑞萨RA2系列开发板体验】+开箱及定时器中断点灯
今天,我终于有空把玩一下瑞萨的MCU了,我之前从来没接触过~
先来上开箱照,说实话有点失望~资源太少,连连接电源的USB都没留,更不要谈转TTL转USB接口~真的是最小系统,不能再小了~板上资源就2个LED,一个KEY,2个TOUCHPAD~
硬件搭建好,下面开始软件的搭建~
安装好E2 STUDIO,蛋的,1.5个G~
按照"e2快速上手指南.pdf"指导,安装并熟悉开发环境的各个部件~
里面讲的很清晰,包括创建库文件,创建MOOS工程及RTOS工程~
这了就不一一衍述~
现在主流MCU开发IDE,特别是个大厂商自己推出的,几乎都集成了MCU外设配置的功能~E2也不例外~这样能减少开发周期,甚至不要太关注底层~
下面我们用配置工具,配置一个定时器300ms中断,在中断中,切换LED状态,这样一个闪烁灯实验~
我们开始配置:
保存设置,并按
生成代码:
我们看下它的main函数:
- #include "hal_data.h"
- int main(void)
- {
- hal_entry ();
- return 0;
- }
复制代码 我们把代码写到hal_entry ()里面:
在hal_entry 里面添加:
- static void LED_Init(void)
- {
- fsp_err_t err; /* Initialize the IOPORT module and configure the pins */
- err = R_IOPORT_Open(&g_ioport_ctrl, &g_bsp_pin_cfg); /* Handle any errors. This function should be defined by the user. */
- assert(FSP_SUCCESS == err); /* Configure Pin as output * Call the R_IOPORT_PinCfg IF the configuration was not part of initial configurations made in open */
- err = R_IOPORT_PinCfg(&g_ioport_ctrl, g_bsp_pin_cfg_data[0].pin, g_bsp_pin_cfg_data[0].pin_cfg);
- assert(FSP_SUCCESS == err);
- err = R_IOPORT_PinCfg(&g_ioport_ctrl, g_bsp_pin_cfg_data[1].pin, g_bsp_pin_cfg_data[1].pin_cfg);
- assert(FSP_SUCCESS == err);
- }
- bsp_io_level_t level = BSP_IO_LEVEL_LOW;
- void gtp00_callback(timer_callback_args_t *p_args)
- {
- (void)p_args;
- if (BSP_IO_LEVEL_LOW == level)
- {
- level = BSP_IO_LEVEL_HIGH;
- }
- else
- {
- level = BSP_IO_LEVEL_LOW;
- } /* Update LED on RA6M3-PK */
- R_IOPORT_PinWrite(&g_ioport_ctrl, g_bsp_pin_cfg_data[0].pin, level);
- R_IOPORT_PinWrite(&g_ioport_ctrl, g_bsp_pin_cfg_data[1].pin, level);
- }
- /*******************************************************************************************************************//**
- * main() is generated by the RA Configuration editor and is used to generate threads if an RTOS is used. This function
- * is called by main() when no RTOS is used.
- **********************************************************************************************************************/
- void hal_entry(void)
- {
- /* TODO: add your own code here */
- LED_Init();
- g_timer00.p_api->open(g_timer00.p_ctrl, g_timer00.p_cfg);
- g_timer00.p_api->start(g_timer00.p_ctrl);
- #if BSP_TZ_SECURE_BUILD
- /* Enter non-secure code */
- R_BSP_NonSecureEnter();
- #endif
- while(1)
- {}
- }
复制代码 至于具体的GPIO定义在pin_data文件里,我们直接调用:
- const ioport_pin_cfg_t g_bsp_pin_cfg_data[] =
- {
- { .pin = BSP_IO_PORT_01_PIN_03, .pin_cfg = ((uint32_t) IOPORT_CFG_PORT_DIRECTION_OUTPUT
- | (uint32_t) IOPORT_CFG_PORT_OUTPUT_LOW) },
- { .pin = BSP_IO_PORT_01_PIN_04, .pin_cfg = ((uint32_t) IOPORT_CFG_PORT_DIRECTION_OUTPUT
- | (uint32_t) IOPORT_CFG_PORT_OUTPUT_LOW) },
- { .pin = BSP_IO_PORT_01_PIN_08, .pin_cfg = ((uint32_t) IOPORT_CFG_PERIPHERAL_PIN
- | (uint32_t) IOPORT_PERIPHERAL_debug) },
- { .pin = BSP_IO_PORT_02_PIN_13, .pin_cfg = ((uint32_t) IOPORT_CFG_PERIPHERAL_PIN
- | (uint32_t) IOPORT_PERIPHERAL_GPT1) },
- { .pin = BSP_IO_PORT_03_PIN_00, .pin_cfg = ((uint32_t) IOPORT_CFG_PERIPHERAL_PIN
- | (uint32_t) IOPORT_PERIPHERAL_DEBUG) }, };
复制代码 编译,下载,我们查看现象:
是不是很Easy,好了,开箱就到这了,谢谢观看~
|