2024-07-08 07:14 AM
1. CubeMX only allows HAL or LL for SPI and other peripherals. STM32C031C6 itself provides the good SPI clock rate.
SPI LL API function only allows two-byte R/W.. The slave STPM34 Meter IC requires 4-Byte SPI R/W. So we have to choose HAL SPI API calls, such as HAL_SPI_TransmitReceive().
However HAL introduces a big delay (15 us or more) between two consecutive HAL SPI-API calls. We need 6 SPI-API calls within 128us for our application, This big delay inserted by HAL makes it impossible. .
2. The only solution is to write the register low level SPI R/W functions. Is it possible to write it under the current CubeMx IDE compiler for STM32C031C6? Could you provide us the solutions?
Thanks,
Rong
2024-07-08 07:17 AM
The auto-generated code just does the initialisation stuff - you can write your own register-level code to do the runtime sending thereafter.
2024-07-08 09:11 AM
Hi @RongShengWang ,
Here 2 examples with SPI LL APIs using STM32C031: https://github.com/STMicroelectronics/STM32CubeC0/tree/main/Projects/NUCLEO-C031C6/Examples_LL/SPI.
You can start from the IOC file of each example and adapt it to yours needs.
-Amel
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.
2024-07-08 09:30 AM
Hi, Almel,
SPI LL API function only allows two-byte R/W each time. The slave side requires 4-Byte SPI R/W each time. We can't use LL for the Master SPI.
HAL introduces a big delay (15 us -20 us) between two consecutive HAL SPI-API calls (such as two calls to HAL_SPI_TransmitReceive()). . We need 6 SPI-API calls within 128us for our application, This big delay inserted by HAL between any two consecutive HAL SPI-API calls makes it impossible. .
Could you explain how your LL example can overcome the problem in the above?
Thanks
Rong
2024-07-08 09:31 AM
Hi, Andrew Neil,
"you can write your own register-level code to do the runtime" - Could you provide me with a reference code?
Thanks,
Rong
2024-07-08 09:45 AM
Sorry, no.
I suggest you look at the LL code, and adapt that...
2024-07-08 10:00 AM
Hi,
"you can write your own register-level code to do the runtime sending thereafter." - The CubeMX compiler may not recognize the own register-level code, such as "SPI1->DR = (uint16_t)(tx_data << 8);", which I copied from some
reference projects using STM32 SPI registers to handle SPI.
How to make CubeMX compiler to recognize it?
Thanks,
Rong
2024-07-08 10:03 AM
@RongShengWang wrote:The CubeMX compiler ...
You mean the CubeIDE compiler - ie, GCC ?
@RongShengWang wrote:... may not recognize the own register-level code, such as "SPI1->DR = (uint16_t)(tx_data << 8);"
What makes you say that?
2024-07-08 10:05 AM
I am using CubeIDE compiler for everything now.
2024-07-08 10:09 AM
Hi, Almel,
SPI LL API function only allows two-byte R/W each time. The slave side requires 4-Byte SPI R/W each time. We can't use LL for the Master SPI because the protocol is 4-byte based.
Besides We need 6 SPI-API calls within 128us for our application.
Could you explain why LL can satisfy the above requirement?
Thanks,
Rong