cancel
Showing results for 
Search instead for 
Did you mean: 

Using NOP()

Dany0
Associate II

Hi all.

 

I'm an old PIC user and now trying to use the STM32 IDE

with some success as of now.

With PIC I can place some NOP() in the code to be able

to set a breakpoint, sometimes to halt the CPU, and since it is

a very fast function., if at the end of a testing I forget to

remove it, then is does not do harm.  And too, sometimes

to use it as a fast delay 10-15times in a row.

But I try a lots of "NOP()" & "NOP" & "nop" and alike without success.

 

So anyone have a clue ???

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
liaifat85
Senior III

If you encounter issues where __NOP() or __asm__("nop") doesn't seem to work, check that you have included the CMSIS header files (core_cmX.h).

View solution in original post

6 REPLIES 6

__NOP();

Keyword is "CMSIS intrinsics".

Note, that timing in the ARMs is not as straighforward as in PICs and a sole NOP() e.g. in Cortex-M7 may be skipped by the processor entirely (optimized out early in the pipeline).

JW

liaifat85
Senior III

If you encounter issues where __NOP() or __asm__("nop") doesn't seem to work, check that you have included the CMSIS header files (core_cmX.h).

SofLit
ST Employee

@Dany0 wrote:

Hi all.

With PIC I can place some NOP() in the code to be able

to set a breakpoint, sometimes to halt the CPU, and since it is

a very fast function.,


Don't know how are you using NOP to set breakpoint. NOP is not an ARM instruction that you could rely even to insert delay. 

I may suggest to use bkpt instruction to set a breakpoint:

https://developer.arm.com/documentation/dui0473/m/arm-and-thumb-instructions/bkpt

BKPT instruction with CMSIS: https://developer.arm.com/documentation/100235/0004/the-cortex-m33-instruction-set/cmsis-functions/list-of-cmsis-functions-to-generate-some-processor-instructions

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

@SofLit wrote:

I may suggest to use bkpt instruction to set a breakpoint


and here's a way to skip the instruction when there's no debugger attached (except Cortex-M0) :

https://community.st.com/t5/stm32-mcus-products/how-to-ignore-bkpt-instruction-on-cortex-m7/m-p/717525/highlight/true#M260138

 

In Cortex-M0, the DHCSR register is not accessible to the user code for that trick to work; instead, see:

https://community.st.com/t5/stm32-mcus-products/detect-debugger-connected-to-stm32l0/m-p/616693/highlight/true#M229267

also:

https://community.st.com/t5/stm32-mcus-products/detect-debugger-connected-to-stm32l0/m-p/405695/highlight/true#M115502

> Don't know how are you using NOP to set breakpoint.

It's an instruction on which the breakpoint can be set relatively comfortably.

It can be relied upon for a delay except Cortex-M7 (Maybe Cortex-M4 can be configured to fold the NOPs, but I've yet to see such implementation, and almost certainly it's not the Cortex-M0/M0+ case. Yes, ARM's documentation is inadequate in this regard and ST does not make it any better.).

JW

> If you encounter issues where __NOP() or __asm__("nop") doesn't seem to work, check that you have included the CMSIS header files (core_cmX.h).

.. which ought to be included implicitly, through including the appropriate CMSIS-mandated device header (e.g. stm32f4xx.h with the respective STM32Fxxx symbol defined beforehand).

JW