cancel
Showing results for 
Search instead for 
Did you mean: 

When configuring GPIO's as external interrupts, CubeMX is generating code to enable interrupts immediately. This can be annoying if the interrupt fires before the software is fully initialized.

mads.l
Associate II

Using an operating system such as free-rtos, it is common to send a message from the interrupt to a thread, but if the handle to the thread is not yet created - a hard-fault is usually seen. Testing a flag in the interrupt routine activated when the system is initialized can be used, but the best solution would be to let the user code take care of the NVIC enable instead of Cube-MX. Is there a way I can achive this?

Brg

Mads-l

1 ACCEPTED SOLUTION

Accepted Solutions
Pavel A.
Evangelist III

Mask all interrupts that should not be handled before FreeRTOS scheduler starts.

Especially these that call FreeRTOS API.

This can be done with __set_BASEPRI. Set it at least to configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY.

Note that the parameter of __set_BASEPRI must be shifted left 4 bits (with standard ST HAL setting of __NVIC_PRIO_BITS=4)

For example if your configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY is 6:

__set_BASEPRI( 6 << (8 - __NVIC_PRIO_BITS))

When FreeRTOS scheduler starts it will automatically reset BASEPRI to 0.

If you disable interrupts completely (__disable_irq), the HAL timer tick won't run too. If you use the ST HAL libraries, you may want to leave it running.

-- pa

Thanks to @berendi and @clive !

View solution in original post

3 REPLIES 3
Pavel A.
Evangelist III

Mask all interrupts that should not be handled before FreeRTOS scheduler starts.

Especially these that call FreeRTOS API.

This can be done with __set_BASEPRI. Set it at least to configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY.

Note that the parameter of __set_BASEPRI must be shifted left 4 bits (with standard ST HAL setting of __NVIC_PRIO_BITS=4)

For example if your configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY is 6:

__set_BASEPRI( 6 << (8 - __NVIC_PRIO_BITS))

When FreeRTOS scheduler starts it will automatically reset BASEPRI to 0.

If you disable interrupts completely (__disable_irq), the HAL timer tick won't run too. If you use the ST HAL libraries, you may want to leave it running.

-- pa

Thanks to @berendi and @clive !

mads.l
Associate II

Thanks Pavel, solved my problem.

Piranha
Chief II

The same can be done universally by just calling taskDISABLE_INTERRUPTS().