Hello,
I'm working on a project uses RA6M5 MCU. FSP version is 3.5.0. IAR is 9.10.2.
I'm having a weird issue. I have an external IRQ. When running in debug mode in IAR, the R_ICU_ExternalIrqEnable() will call R_BSP_IrqEnableNoClear() eventually. But the code execution never finished from R_BSP_IrqEnableNoClear() - the debugging hanging in IAR, no further code execution possible. Here is the code:
icu_instance_ctrl_t g_external_ctrl; const external_irq_cfg_t g_external_cfg = { .channel = 14, .trigger = EXTERNAL_IRQ_TRIG_LEVEL_LOW, .filter_enable = true, .pclk_div = EXTERNAL_IRQ_PCLK_DIV_BY_64, .p_callback = my_isr, .p_context = NULL, .p_extend = NULL, .ipl = (12), .irq = VECTOR_NUMBER_ICU_IRQ, // = ((IRQn_Type) 32) }; typedef struct _my_control { uint16_t var1; uint16_t var2; uint16_t var3; uint16_t var4; } my_control_t; my_control_t g_control; void func_ext_irq(void) { fsp_err_t err = FSP_SUCCESS; err = R_ICU_ExternalIrqOpen(&g_external_ctrl, &g_external_cfg); if (FSP_SUCCESS != err) { return; } err = R_ICU_ExternalIrqEnable(&g_external_ctrl); if (FSP_SUCCESS != err) { return; } } // bsp_irq.h __STATIC_INLINE void R_BSP_IrqEnableNoClear (IRQn_Type const irq) { /* The following statement is used in place of NVIC_EnableIRQ to avoid including a branch for system exceptions * every time an interrupt is enabled in the NVIC. */ uint32_t _irq = (uint32_t) irq; NVIC->ISER[(((uint32_t) irq) >> 5UL)] = (uint32_t) (1UL << (_irq & 0x1FUL)); // <-- The execution never finished } void func_other() { . . . func_ext_irq(); memset(&g_control, 0, sizeof(g_control)); . . . }
Later, I commented out the R_ICU_ExternalIrqEnable() line. But the execution doesn't return from memset() which is a simple function. Here is the code:
void func_ext_irq(void) { fsp_err_t err = FSP_SUCCESS; err = R_ICU_ExternalIrqOpen(&g_external_ctrl, &g_external_cfg); if (FSP_SUCCESS != err) { return; } //err = R_ICU_ExternalIrqEnable(&g_external_ctrl); //if (FSP_SUCCESS != err) //{ // return; //} } void func_other() { . . . func_ext_irq(); memset(&g_control, 0, sizeof(g_control)); // <-- The execution never finished . . . }
I'm not sure what went wrong. There is no complain about the memory shortage. Is there any way to find out what went wrong with the above code? Is it something to do with the stack or program counter?
Thanks!
If the problem is with 'memset' you may need to add some heap size on BSP tab of Smart Configurator.
Also it is recommended to update to the latest FSP version 5.1.
Hi AZ_Renesas,
I increased the stack size(from 0x400 to 0xA00) and the heap size(from 0x100 to 0x800). But it doesn't help:
Is there a limitation of the number of external IRQ? We have 3 external IRQs. The first two IRQ get no problem. If I move this 3rd one which is the problemtaic one to early phase of the initialization, it seems also working. This indicates the issue is related to the system resource.
Due to the initialization sequence, I can't simply move this external IRQ to early phase.
Please let me know if there is a way to find out the cause of the issue.
Thanks in advance!
I suspected the issue is related to the interrupt. So I added the disable/enable interrupt around the R_ICU_ExternalIrqEnable(). This time, the execution of R_ICU_ExternalIrqEnable() is okay. But the PC is still lost at "Line 8". The "Line 8" isn't even a function call.
void enable_ext_irq(void) { fsp_err_t err = FSP_SUCCESS; __disable_interrupt(); err = R_ICU_ExternalIrqEnable(&g_external_ctrl); __enable_interrupt(); if (FSP_SUCCESS != err) // <-- Line 8 { printf("** enable_ext_irq failed **\r\n"); } }
Previously, there are 34 IRQs in the system. I managed to decrease the number of interrupts to be 20. However, the PC still gets lost on "Line 8" in the above code.
By the way, we use FreeRTOS in our system. Let me know if there is any potential solution.
.trigger = EXTERNAL_IRQ_TRIG_LEVEL_LOW,
If the IRQ pin is low, interrupt will occurs immediately after acceptance. So you have endless interrupt.
Could you set to falling edge?
Hi CS Yep,
Thank you so much. I tried your solution. It works! I appreciate it.
I have another issue which has the similar behaviour as this one: the execution hanging after UART init. I had to disable the Rx interrupt. Could you please help take a look at that issue? https://community.renesas.com/mcu-mpu/ra/f/forum/33540/the-rx-interrupt-has-to-be-disabled-during-uart-init-otherwise-the-execution-of-the-firmware-hanging
Thanks again!