cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f405, lock question

Angelo1
Associate II
Posted on May 06, 2014 at 00:33

Dear,

i have the following issue:

i have seen that i cannot process too many instructions from inside interrupt. I guess there is a limit. (still didn't looked the datasheet),

So i decided to do just some few operations in the interrupt routine, pushing the input in a fifo, and then process this input from the main loop.

But now, how can avoid race conditions if interrupt is triggered just when the main loop is processing/modifing the stack ?

Maybe someone can help me on the proper way to go. Thanks.

Angelo

7 REPLIES 7
jpeacock2399
Associate II
Posted on May 06, 2014 at 15:58

There is no limit to the length of an interrupt service routine other than the limits imposed by the application.  However it is good programming practice to minimize the size of the service routine, and defer processing to a completion task.

If you have a critical section in your main task then disable interrupts during the critical section to prevent a collision with the interrupt.  Update your FIFO extract pointer inside a critical section in the main loop to avoid the case of buffer overrun where insert and extract pointers are updated out of sequence due to interrupts.

  Jack Peacock

chen
Associate II
Posted on May 06, 2014 at 16:37

Hi

Jack is right on both points (size of ISR and critical sections).

Instead of trying to do this in bare hand crafted code - try one of the open source RTOS.

FreeRTOS is popular for developing commercial products.

ChiliOS has a few people here on the forum asking questions.

ecos - some one recently asked about this on this forum.

FreeRTOS definitely has inter-task messaging, with a special function for sending from ISR to task. The inter-task messaging is a FIFO, the FIFO mutex/semaphore is implemented by the OS for you so you do not have to worry about it.

Angelo1
Associate II
Posted on May 06, 2014 at 23:16

Dear,

many thanks,

for strategic reasons i don't use any OS. I looked the STM324xx library and didn't seen any lock/mutex/semaphore support. So i have to do it in a rude/raw way.

Is it possible to disable from the main loop just the interrupt i don't want to engage for race conditions ? I found

(IRQn_Type IRQn) (and Disable)

Can be used ? Or i should disable/reenable all interrupts ?

chen
Associate II
Posted on May 07, 2014 at 10:12

Hi

''Is it possible to disable from the main loop just the interrupt i don't want to engage ''

Yes.

''I found

(IRQn_Type IRQn) (and Disable)

Can be used ? Or i should disable/reenable all interrupts ?''

Look at the implementation and cross reference with the reference manual.

I think this may not disable some IRQs (such as the sysTick).

chen
Associate II
Posted on May 07, 2014 at 11:03

To truely disable all IRQs - I looked up how FreeRTOS does it.

It masks ALL IRQs in the ARM basepri register.

(I do not know I the copyright allows me to paste the code here)

Angelo1
Associate II
Posted on May 09, 2014 at 09:25

Hello,

thanks, yes i see FreeRTOS code, but can't understand it clearly.

I surfed the forum, and couldn't find any help. I would like to be sure of a way to disable EXTI15_10_IRQn (Ext int line 0), possible without disabling all interrupts.

Any help is appreciated.

chen
Associate II
Posted on May 09, 2014 at 09:59

''I would like to be sure of a way to disable EXTI15_10_IRQn (Ext int line 0), possible without disabling all interrupts.''

This is pretty easy.

Just disable it in the EXTI or via the NVIC :

 EXTI_InitStructure.EXTI_LineCmd = DISABLE;

or

NVIC_InitStructure.NVIC_IRQChannelCmd = DISABLE;