Hi,
I have a bluepill with an stm32f103. The documentation says it is predictible, but it still has a prefetch queue to avoid waitstates, so I wanted to experiment with this. I just want to play with counting cycles*. But the code stops executing for 600-1000ns every (apparently exactly) 1ms.
I run the following code :
asm("asm:");
asm(" mov r1, #0x00000001");
asm(" ldr r2, =0x40010800");
asm(".align 4");
asm("loop:");
asm(" str r1, [r2, #20]");
asm(" str r1, [r2, #16]");
asm(" str r1, [r2, #20]");
asm(" str r1, [r2, #16]");
asm(" str r1, [r2, #20]");
asm(" str r1, [r2, #16]");
asm(" str r1, [r2, #20]");
asm(" str r1, [r2, #16]");
asm(" b loop");
That should just toggle a pin on and off four time, then loop.
Here is what I see on the oscilloscope :

The pause seems to be of repetable length, but it's about half long if I compile in release instead of debug.
I have not made reproductible tests yet, but it seem to appear at random place in my loop (you see on the picture that after the long pause, I don't always have the same number of 0 or 1). Anyway it constantly repeat 1ms before the trigerring one.
Also depending on what I write before the loop, it seems stall during either a 1 or a 0 on the output pin. I can flash several times with the same firmware and it will apparently always be the same, but if I change the code before the loop it might change (even though I aligned the code before)
I have a very basic CubeMX new project, with :
- PA0 to PA7 and PC13 set to output
- RCC_MCO on on PA8 (clock output)
- SWDIO and SWDCLOCK on PA13 and 14
- 8MHz crystal with X9 multiplier to reach nominal 78MHz

All I can see activated in CubeMX is :
- Serial Wire debug
- High Speed Clock (HSE) set to Crystal/Ceramic oscillator
[li]NVIC only has [/li][/list]
enabledon things I can't disable[/li]
think I let everything else disabled (no watchdog timer).
I use a cheap STLinkV2 clone for programming.
Source code attached.
Any idea what is happening ?
Thank you,
J.
* : Just for fun, don't judge me. I can count cycles on 6502 where you often need it, I just wanted to experiment with next difficulty level.