2022-10-28 07:32 AM
Hi,
I'm working on a custom board where we integrated an STM32L010RB and I have verry weird behaviour :
I need to use SPI1 peripheral and the clock signal is working as expected only if I enable optimization on the compiler settings.
The MISO is OK.
In STM32Cube IDE the SPI_CLK signal is routed by default to PA5.
If I use the PA5 PIN for SPI_CLK, my clock signal works as expected with or without optimizations.
If I change to use PB3 (which is the pin I need to use on my design), I have a signal on clk only if I enable a compiler optimization (any of it). But in this case some of my GPIO are not working (i.e. I can't read the correct pin state for inputs and cannot drive my outputs)
I really don't understand what this means, the relation between optimization and the fact it works or not. In fact, I can understand that optimization could lead to a buggy behaviour because of interrupts, or something else, but how can it fix a bug on SPI and produce bugs on GPIOs ?
I don't want to use optimizations, so how to make my SPI work without optimizations ? I'm completely lost !
Thanks in advance for your help.
Bye.
2022-10-28 12:14 PM
Debug as usually: find out what has been written to GPIOB (and perhaps SPI) registers, and check against expected values.
JW
2022-10-29 07:51 PM
If spi master mode I smell use of TXE instead of RXNE in the code.
2022-11-07 01:37 AM
Thanks for your replies, I'll investigate deeper and come back to you.
Have a nice day.
2022-11-17 07:14 AM
Hi every one,
I found the source of the problem so I want to share it !
One thing I didn't mentioned is I use NFC7 library for my project because we also embbed an ST25DV64KC.
Obviously it does not use SPI bus but I2C. We used an example code from nucleo as base for the use of the ST25DV. In this example code the function BSP_I2C1_Init initializes I2C bus by calling I2C1_MspInit and starts by a call to HAL_GPIO_Init(BUS_I2C1_SCL_GPIO_PORT, &GPIO_InitStruct);
GPIO_InitStruct is not initialized so this line overwrites any configuration previously done on GPIOB port which is where my SPI clock was (an also others signals).
As the init of the library is called after the whole peripherals init, all peripherals related to GPIOB had wrong configuration.
Next time we will be more careful with the use of example code and we probably will start from scratch to make sure we have full control on our code !
That's it, thanks for your help and have a nice day.
2022-11-17 07:32 AM
Having a HW resource overbooking check system in the mcu SW will be costly to catch such situation....