renesas / fsp

Flexible Software Package (FSP) for Renesas RA MCU Family
https://renesas.github.io/fsp/
Other
182 stars 81 forks source link

No NULL-Pointer check in gpt_counter_underflow_isr in r_gpt.c #298

Closed stefannagelchargebyte closed 8 months ago

stefannagelchargebyte commented 8 months ago

Dear Renesas Team, I'm using the gpt_counter_underflow_isr which is linked to an ADC conversion. However, even if I use the gpt_counter_underflow_isr, I dont use the callback. This leads to a critical assert.

I would propose as you did for the gpt_counter_overflow_isr only add a check against NULL pointer for the callback.

Actual code: `void gpt_counter_underflow_isr (void) { / Save context if RTOS is used / FSP_CONTEXT_SAVE

IRQn_Type irq = R_FSP_CurrentIrqGet();

/* Clear pending IRQ to make sure it doesn't fire again after exiting */
R_BSP_IrqStatusClear(irq);

/* Recover ISR context saved in open. */
gpt_instance_ctrl_t * p_instance_ctrl = (gpt_instance_ctrl_t *) R_FSP_IsrContextGet(irq);

/* Call user callback. */
r_gpt_call_callback(p_instance_ctrl, TIMER_EVENT_TROUGH, 0);

/* Restore context if RTOS is used */
FSP_CONTEXT_RESTORE

}`

Proposal: `void gpt_counter_underflow_isr (void) { / Save context if RTOS is used / FSP_CONTEXT_SAVE

IRQn_Type irq = R_FSP_CurrentIrqGet();

/* Clear pending IRQ to make sure it doesn't fire again after exiting */
R_BSP_IrqStatusClear(irq);

/* Recover ISR context saved in open. */
gpt_instance_ctrl_t * p_instance_ctrl = (gpt_instance_ctrl_t *) R_FSP_IsrContextGet(irq);

/* Call user callback. */
if (NULL != p_instance_ctrl->p_callback)
{
    r_gpt_call_callback(p_instance_ctrl, TIMER_EVENT_TROUGH, 0);
}

/* Restore context if RTOS is used */
FSP_CONTEXT_RESTORE

}`

renesas-brandon-hussey commented 8 months ago

Hi @stefannagelchargebyte why are you enabling the GPT underflow interrupt if you are not going to have a callback? If you are using the GPT underflow event to trigger an ADC conversion using the ELC then you do not need to enable the GPT underflow interrupt.

stefannagelchargebyte commented 8 months ago

Because I didn't understand it :-) I thought you need the interrupt to trigger the event ... but after your mail I disabled the interrupts and the events are coming through, anyway. Thanks for the hint

renesas-brandon-hussey commented 8 months ago

No problem, glad to hear it solved your problem!