Skip to content

Commit 01e1944

Browse files
committed
Fix IRQ management in FreeRTOS to avoid crash and deadlock in BLE stack.
1 parent 6420885 commit 01e1944

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

src/FreeRTOS/port_cmsis.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,4 +354,24 @@ static void vPortEnableVFP( void )
354354
configASSERT( NVIC_GetPriorityGrouping() <= ulMaxPRIGROUPValue );
355355
}
356356

357+
uint32_t ulSetInterruptMaskFromISR( void )
358+
{
359+
__asm volatile (
360+
" mrs r0, PRIMASK \n"
361+
" cpsid i \n"
362+
" bx lr "
363+
::: "memory"
364+
);
365+
}
366+
/*-----------------------------------------------------------*/
367+
368+
void vClearInterruptMaskFromISR( __attribute__( ( unused ) ) uint32_t ulMask )
369+
{
370+
__asm volatile (
371+
" msr PRIMASK, r0 \n"
372+
" bx lr "
373+
::: "memory"
374+
);
375+
}
376+
357377
#endif /* configASSERT_DEFINED */

src/FreeRTOS/portmacro_cmsis.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,10 @@ typedef unsigned long UBaseType_t;
104104
/* Critical section management. */
105105
extern void vPortEnterCritical( void );
106106
extern void vPortExitCritical( void );
107-
#define portSET_INTERRUPT_MASK_FROM_ISR() ulPortRaiseBASEPRI()
108-
#define portCLEAR_INTERRUPT_MASK_FROM_ISR(x) vPortSetBASEPRI(x)
107+
extern uint32_t ulSetInterruptMaskFromISR( void ) __attribute__( ( naked ) );
108+
extern void vClearInterruptMaskFromISR( uint32_t ulMask ) __attribute__( ( naked ) );
109+
#define portSET_INTERRUPT_MASK_FROM_ISR() ulSetInterruptMaskFromISR()
110+
#define portCLEAR_INTERRUPT_MASK_FROM_ISR(x) vClearInterruptMaskFromISR( x )
109111
#define portDISABLE_INTERRUPTS() __asm volatile ( " cpsid i " ::: "memory" )
110112
#define portENABLE_INTERRUPTS() __asm volatile ( " cpsie i " ::: "memory" )
111113
#define portENTER_CRITICAL() vPortEnterCritical()

0 commit comments

Comments
 (0)