cancel
Showing results for 
Search instead for 
Did you mean: 

__enable_irq and __disable_irq in (gcc) C without CMSIS library/function? (STM32F051)

wb0gaz
Senior

I'm working on small (GCC/C-language) tests of STM32F051 with STM32CubeIde 1.8.0 on STM32F051 target. These tests are being done ---> without HAL, CMSIS or Lower Level drivers <---, so your patience is appreciated (that is, I don't intend in these tests to involve HAL or Lower Level drivers).

I'd like to know if I can enable/disable interrupts in a stand-alone fashion (by directly accessing relevant CPU resources in memory space). Being new to this platform, I've come to realize there's not an obvious (to me) "interrupts are enabled" CPU status/control flag somewhere.

I gather from RM0091 that Cortex-M0 Internal Peripherals are in 512K range E0000000..E00FFFFF, however, any read from those locations (so far) has yielded only zero values.

In PM0215 "The STM32 Cortex-M0 instruction set" section 3.7.1 shows what I think are the needed resources (as in assembly language instructions), but it does not mention Privileged modes.)

CPSID i ; Disable all interrupts except NMI (set PRIMASK)

CPSIE i ; Enable interrupts (clear PRIMASK)

cmsis_gcc.h shows this based on looking for __disable_irq():

/**

 \brief  Disable IRQ Interrupts

 \details Disables IRQ interrupts by setting the I-bit in the CPSR.

          Can only be executed in Privileged modes.

 */

__STATIC_FORCEINLINE void __disable_irq(void)

{

 __ASM volatile ("cpsid i" : : : "memory");

}

I attempted #include "cmsis_gcc.h" in my program - this results in compile-time errors such as

../Inc/cmsis_gcc.h:129:27: error: invalid storage class for function '__enable_irq'

 129 | __STATIC_FORCEINLINE void __enable_irq(void)

Grateful for any help/advice/pointers, and happy to do additional reading but some guidance would be very helpful at this stage.

3 REPLIES 3

PRIMASK as a processor core register, much like r0..r16 and a few others, i.e. it's not an Internal Peripheral.

> I attempted #include "cmsis_gcc.h" in my program

Show a minimal but complete program exhibiting the problem, together with the *complete* output of the compiler.

JW

wb0gaz
Senior

Thank you JW for good advice!

I started a new project (to include only the minimum necessary to demonstrate result, using new>stm32 project>targeted project type=empty), and this project DID compile with #include "cmsis_gcc.h" and __enable_irq(); in the source code.

'

Cause of reported project compile problem is not yet known, but I am now focusing on new project to focus only on demonstrating enable interrupts and execution reaching supplied ISR. There may be new stopping point, but basic #include and compile appears successful now.

I will focus on trying verify that interrupt is actually happening, and if/when I reach another stop point, I will come back to this topic and post minimal complete example and output of compiler.

Dave

Piranha
Chief II

https://github.com/STMicroelectronics/STM32CubeF0/blob/830a0e950d421c17abff57a2ea1e977870355519/Drivers/CMSIS/Device/ST/STM32F0xx/Include/stm32f051x8.h#L47

https://github.com/STMicroelectronics/STM32CubeF0/blob/830a0e950d421c17abff57a2ea1e977870355519/Drivers/CMSIS/Device/ST/STM32F0xx/Include/stm32f051x8.h#L113

These are the lines you must include, not the "cmsis_gcc.h".

But actually you are confusing the CMSIS-Driver and other drivers with just a simple CMSIS-Core and CMSIS-Device register definition files. This is all you need and it's not a driver of any kind:

#define STM32F051x8
#include "stm32f0xx.h"

Or probably even just a "stm32f051x8.h" is enough.