Closed
Description
I found a very weird issue with the SPI code (may affect others as well).
The code bellow works fine, but produces no SPI signal if you comment out the call to delay(0)
in the setup()
.
I'm testing this on STM32F407VE MCU.
-----Bug repro code start -----
#include <SPI.h>
void setup() {
delay(0); // You comment this line the SPI does generate produce any signals
// the delay code can be placed anywhere in this file the location does not matter.
// The pins are specific to my setup, they don't matter for the bug
SPI.setMOSI(PB5);
SPI.setMISO(PB4);
SPI.setSCLK(PB3);
SPI.begin();
}
void loop() {
SPI.transfer(0x55);
}
-----Bug repro code end -----
The only significant difference I can spot is when I call delay(0), some extra code is linked to the binary. I suspect the SPI code depends on the SysTick handler and does not quite work without it.
I would guess some week linking is causing this weirdness.
Extra code in the working binary:
<HAL_IncTick>:
4a03 ldr r2, [pc, #12] ; (8000528 <HAL_IncTick+0x10>)
6811 ldr r1, [r2, #0]
4b03 ldr r3, [pc, #12] ; (800052c <HAL_IncTick+0x14>)
781b ldrb r3, [r3, #0]
440b add r3, r1
6013 str r3, [r2, #0]
4770 bx lr
bf00 nop
200001c8 .word 0x200001c8
20000004 .word 0x20000004
<SysTick_Handler>:
b508 push {r3, lr}
f7fe fb56 bl 8000518 <HAL_IncTick>
f7fe fbd1 bl 8000612 <HAL_SYSTICK_IRQHandler>
f7ff fff8 bl 8001e64 <noOsSystickHandler>
bd08 pop {r3, pc}