Skip to main content
TechMarc
Associate
March 4, 2019
Question

Disable/enable interrupts globally on STM32F746

  • March 4, 2019
  • 3 replies
  • 1055 views

Hello,

just a simple question. We share some data between ISR and application on STM32F746 processor (no RTOS used). How can we disable interrupts globally while application accesses the shared variables? Afterwards interrupts should be enabled again.

Thanks Marc

This topic has been closed for replies.

3 replies

S.Ma
Principal
March 4, 2019
uint32_t SPIP_MasterRunTransaction(SPIP_t* pSPIP) {
 uint32_t tmp;
 tmp = __get_PRIMASK();
 __set_PRIMASK(tmp | 1);
 SPIP_InterruptBasedStateMachine(0); 
 __set_PRIMASK(tmp);
 return 0;
}

Piranha
Principal III
March 6, 2019

Interrupt can still get in between lines 3-4 and change PRIMASK.

uint32_t SPIP_MasterRunTransaction(SPIP_t* pSPIP) {
 uint32_t tmp;
 __disable_irq();
 tmp = __get_PRIMASK();
 __set_PRIMASK(tmp | 1);
 __enable_irq();
 SPIP_InterruptBasedStateMachine(0); 
 __set_PRIMASK(tmp);
 return 0;
}

turboscrew
Senior III
March 5, 2019

How about __disable_irq() and __enable_irq()?

Tesla DeLorean
Guru
March 6, 2019

They don't nest..

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
Piranha
Principal III
March 6, 2019

When accessing shared data, often it's enough to disable/enable interrupts only for particular peripheral with NVIC_DisableIRQ() and NVIC_EnableIRQ() respectively.