2024-11-12 08:51 AM
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 ???
Solved! Go to Solution.
2024-11-12 09:13 AM
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).
2024-11-12 09:06 AM - edited 2024-11-12 09:08 AM
__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
2024-11-12 09:13 AM
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).
2024-11-12 09:19 AM
@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
2024-11-12 09:38 AM - edited 2024-11-12 10:15 AM
@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) :
In Cortex-M0, the DHCSR register is not accessible to the user code for that trick to work; instead, see:
also:
2024-11-12 10:24 AM - edited 2024-11-12 10:24 AM
> 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
2024-11-12 10:26 AM
> 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