Skip to main content
Associate II
November 12, 2024
Solved

Using NOP()

  • November 12, 2024
  • 3 replies
  • 7167 views

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 ???

 

 

Best answer by liaifat85

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).

3 replies

waclawek.jan
Super User
November 12, 2024

__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

liaifat85Best answer
Visitor II
November 12, 2024

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).

waclawek.jan
Super User
November 12, 2024

> 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

mƎALLEm
Technical Moderator
November 12, 2024

@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."
Andrew Neil
Super User
November 12, 2024

@mƎALLEm 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

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.