-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
STM32H7 SPI DMA: Invalidate Dcache Timing Wrong #11594
Comments
@davids5 interested to hear from you what you think? |
@dmammolo I can tell you that the version of the H7 spi driver in PX4 is working (the diff is minimal: semaphore to mutex). |
Pinging @jlaitine for awareness! @dmammolo thank you for your deep investigation! Is it possible to reproduce the issue using the spitool app? Maybe just connecting MOSI to MISO pin and trying to write something and read it back and checking the result. It test also could be easier to let more people to investigate the issue. @davids5 is STM32H7 already used in many drones powered by PX4? As Dario commented this issue could be trick to notice. |
@davids5 regarding the diff to the PX4 version (mutex instead of semaphore) are you talking about this part of the code: If I understand the Dcache functionalities, invalidating triggers a sync of the the SRAM to Dcache memory. So IMO it does not make sense to do this if the SPI transfer/read and DMA completion is not done yet. @alandeassis this hardware change is not so easy to achieve with a pix32v6 and as mentioned this issue pops up only with specific code changes (which I can't share unfortunately). |
No it is not like that. The invalidate marks the cache lines invalid so the next read will be out to memory (not the cache) and bring in the lines to the cache. If the code is obeying the use case it should not be reading memory before the DMA completion. I suspect you have some overlapping accesses with specific code changes which you can't share. |
@dmammolo I understand, but you don't need to share all the modifications, just the minimum to help people to identify the issue. Also if you can reproduce the issue in some common STM32H7 evaluation board is easier because most people doesn't have pix32v6 hw to test it. |
@davids5 I think you are right and I have a suspicion what could cause the issue that I am observing. It is probably only an issue in combination with the PX4 SPI wrapper/stack. The issue can only occur if you have multiple devices on the same SPI and/or an IMU such as BMI055 or BMI088 which require requesting data for gyro and accel separately. I think that the px4 layer is not protecting against this, see my comment and link above. If you agree I can create an issue on PX4-Autopilot. |
@dmammolo I would expect that with 2 device on the same bus _locking_mode needs to be used and should be set to LOCK_PREEMPTION or LOCK_THREADS depending on the drivers and what their thread of execution is. LOCK_THREADS if a thread (Where the ISR: hrt or direct off of drdy, sets a semaphore ) and LOCK_PREEMPTION if off an ISR (hrt or direct off of drdy) |
I agree and I just verified that on px4 release 1.13.3 and 1.14.0 the locking mode for fmu-v6c is always LOCK_NONE. I will create an issue on the PX4 repository and close it here. Thanks for your inputs! |
I am observing issues on the SPI interface using IMUs (BMI055 and ICM40688-P) on a pix32v6 (STM32H7 with both IMUs on SPI1).
All IMUs use the
spi_exchange()
function to send a command and read back the FIFO data of the IMU.nuttx/arch/arm/src/stm32h7/stm32_spi.c
Line 2047 in 55ec92e
The issue I am observing is corrupted RX data, basically the data that is received is not the one that is expected. After some debugging and reading I suspect that the dcache invalidation of the rx dma buffer is done too early, i.e. before the SPI transfer and read even started. Currently the invalidation is done here:
nuttx/arch/arm/src/stm32h7/stm32_spi.c
Lines 2170 to 2174 in 55ec92e
But IMO it should happen here:
nuttx/arch/arm/src/stm32h7/stm32_spi.c
Lines 2253 to 2257 in 55ec92e
Before we copy the dma buffer on the local buffer(orig_buffer). Debugging with gdb I observed that the copying is successful (verified with memcmp) but when comparing the content of the dma buffer
priv->rxbuf
(I assume by printing the content of the buffer(using it's address) using gdb it does not use Dcache) with theorig_buffer
it sometimes differs. The issue is hard to reproduce and probably just an edge case. I.e. By changing a random line in my code the issue can start popping up or disappears again. Thus fixing this issue is not so easy.After some investigation I found this document from STM (AN4839), from which I extract that we have to do following:
Here some citations from the document making that clear:
Note, that the STM32F7 implementation follows above suggestions. the STM32H7 implementation did that too until this PR changed that logic: #1040
The text was updated successfully, but these errors were encountered: