-
Notifications
You must be signed in to change notification settings - Fork 3k
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
STM32: fix SPI write with data >8 Bit #15115
Conversation
@JojoS62, thank you for your changes. |
CI started |
Hi @JojoS62 When I implement SPI 3-Wire changes, I followed existing implementation of 4-wire logic: mbed-os/targets/TARGET_STM/stm_spi_api.c Lines 1196 to 1210 in bc01a4e
So I think that the following places should be fixed:
mbed-os/targets/TARGET_STM/stm_spi_api.c Lines 1203 to 1209 in bc01a4e
mbed-os/targets/TARGET_STM/stm_spi_api.c Lines 1077 to 1080 in bc01a4e
mbed-os/targets/TARGET_STM/stm_spi_api.c Lines 1106 to 1109 in bc01a4e
Asynchronous API logic ( Additionally I have question about SPI interface functions mbed-os/hal/include/hal/spi_api.h Lines 237 to 253 in bc01a4e
mbed-os/hal/include/hal/spi_api.h Lines 372 to 384 in bc01a4e
But existing asynchronous API implementation ( @LMESTM, @0xc0170 Which definition is correct? Are |
Jenkins CI Test : ✔️ SUCCESSBuild Number: 1 | 🔒 Jenkins CI Job | 🌐 Logs & ArtifactsCLICK for Detailed Summary
|
Question about the buffer sizes. everything is defined in bytes. |
yes, the class documentation says also bytes. But a 16 Bit operation can not send 1 byte, so how to handle this case? The buffer may also be to small and the type cast can crash.
So it seems blockwrites with >8 bit are not working correctly for some longer time. But 16 bit writes are important e.g. for data transfer to a display, otherwise you have to fiddle with byte swapping for a large amount of data. I'm also confused by mbed-os/hal/include/hal/spi_api.h Line 111 in bc01a4e
this says words, what I experienced also as the working behavior in <6.15.0 |
My understanding is that it's user's responsibility to use format/write properly (. You set up the format and then provide buffer (size in bytes, but should be multiple of format specified bits). |
I have checked again the previous behaviour (mbed 6.14.0), it was calling HAL_SPI_Transmit which gets a pointer and a size for datawords, so with 16 bit setting it was sending size * 16 bit. |
|
edit to 1) |
For example, in the above |
So let's merge ? or it needs update ? |
If no objections, I'll merge this tomorrow. |
this PR makes the SPI working like before in mbed-os-6.14, I would appreciate this. |
No, data reading isn't fixed.
I don't like idea of "bug" compatibility fixes. If you run the following code with mbed-os-6.14:
You will see the following SPI results:
I.e actual
Since poring guide (https://os.mbed.com/docs/mbed-os/v6.15/porting/spi-port.html) doesn't provide clear information about 16-bit mode implementation, I'd suggest to adhere to mbed-os/drivers/include/drivers/SPI.h Lines 195 to 209 in 9dd6fb4
mbed-os/drivers/include/drivers/SPI.h Lines 241 to 266 in 9dd6fb4
Such behavior may be implemented with changes like the followings in the
Such solution has the following advantages/disadvantages:
What do you think about it? If it's ok, @JojoS62 please implement "bytes" approach. |
its still on my todo list, I was struggeling with cmake. |
its driving me nuts. I have used the test program from @vznncv on a H743. There the known problem was shown, but also the last asynch transfer was completely missing. for 8 bit, the result is ok. |
Note that ST SPI IP has changed with STM32H7: |
yes, thanks, I have seen also the different treatment in the source code. |
ee70315
to
a5de5bf
Compare
@vznncv I've tried now your modifications, but I get the same wrong result with mbed-os-6.15, my modification and also your modification. I hope I got it right, its better when you send a git patch or the whole file. it is strange, it is sending too many clocks. How can this happen? Can you confirm? |
in spi_master_write. This fixes the problem with too many spi_sck
now it looks fine on the F407, also with LL SPI. I added a |
some points I've found so far:
the problem is definetly the complex enable/disable sequence on the H7. And also the mix of LL and HAL makes it damned hard to handle. |
Hi @JojoS62 I'll check your changes with my boards (F411 and H743) in 2-3 day. Notes:
|
yes, that will be better. Also the transfer for H7 needs to start in disabled state. I wanted to shorten the gap between two writes, it takes also on the fast H7 a few microsecnds. I have published the current testcode on github: And played also with higher SPI speeds. When the H7 is used with PLL3P, then a modification in the init code is neccessary, it destroys a previous set PLL3 setting. for SPI in H7, there is a valuable resources in AN5543 and www.st.com/content/ccc/resource/training/technical/product_training/group0/52/17/7a/28/2b/90/41/7d/STM32H7-Peripheral-Serial_Peripheral_interface_SPI/files/STM32H7-Peripheral-Serial_Peripheral_interface_SPI.pdf/_jcr_content/translations/en.STM32H7-Peripheral-Serial_Peripheral_interface_SPI.pdf |
FYI: I executed SPI non regression basic tests with all STM32 families with the current patches |
I will try to continue tomorrow and fix the issues that @vznncv mentioned. |
Hi @JojoS62 Sorry for delayed answer. I was busy and didn't have enough time to check changes/fixes. But finally I have updated my test example and test/check spi. demo/example resultsExample: https://github.com/vznncv/mbed-os-stm32-spi-3-wire-demo/tree/iss_spi_16bit The example communicates with sensor (it sends data to 6 "free" 8-bit registers and then reads them). For testing purposes I have used patches that I suggested (+some bug fixes that I made during debugging). The code with I have tested it with 3 MCU:
Summary:
SPI enabling/disabling optimization notes
SummaryI'd suggest to split this pull request into 2 ones:
What do you think about it? |
STM32H7 SPI async API (16 bit and 4-wire mode) notesI have compared CubeMX demo program and After adding helper code that disables SPI before HAL_SPI_TransmitReceive_IT call and enables it after transmission, the problems with async API disappears: vznncv@44e2735 |
This PR cannot be merged due to conflicts. Please rebase to resolve them. |
Summary of changes
the low level SPI write calls msp_write_data and passes data in single bytes. Sending data formats with more than 8 Bit are sending only 8 Bit with leading zeros for larger data.
This PR passes the data as pointer to make the type casting depending on the bitshift value working.
Impact of changes
fix sending 16 Bit Problem as in #15113
Migration actions required
Documentation
Pull request type
Test results
urgent fix
Reviewers