cancel
Showing results for 
Search instead for 
Did you mean: 

Disable/enable interrupts globally on STM32F746

TechMarc
Associate II

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

5 REPLIES 5
S.Ma
Principal
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;
}

turboscrew
Senior III

How about __disable_irq() and __enable_irq()?

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;
}

Piranha
Chief II

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

They don't nest..

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..