-
Notifications
You must be signed in to change notification settings - Fork 521
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
STM32L452 SPI2 port assignation not working #447
Comments
I can't help. Contact the author of this program: by Mischianti Renzo https://mischianti.org The old example in SdFat was for a old board support package and there is no longer a working example for SdFat V2. |
I don't have your board but I tried a Nucleo L476RG using the "Arduino" SPI pins SS, MOSI, MOSI, SCK. (10, 11, 12, 13) I uses the standard STMicroelectronics Arduino board support package which has super slow SPI. Here is the standard bench example speed:
I edited SdFatConfig.h like this
A bit faster:
Still almost Uno performance. Try using the QuickStart example to get your connections working. See this for performance with RP2040 fast SPI. About 6 - 7 times faster. |
Hi Bill, Thanks for the help, I managed to make it work with what you suggested with some changes that you can see below! I did change
And then I kind of also forced the default SPI pins to be SPI2 ports: (CS = PB2, MOSI = PC3, MISO = PC2, SCK = PB10) For references here's the output of the quickstart test which shows that the lib was able to connect with the SD CARD on SPI2: |
You can use any pins that can be configured for any SPI port. If SPIn is the port configure it for the pins you require. then use:
If a begin call is needed to set the pins do this: Then you must call begin with your custom pins like this.
Then call |
I did it this way but no luck:
I'm getting this output: Could the error code help us? I'm not sure what it refers to. If you check in the beginning in my first post this is how I chose my SPI2 pins. And I actually already tested this way for SPI1 (see bellow) for a radio that's connected to it and it works, it seems that sd.begin() might be the issue somehow when using SdSpiConfig? Did you manage to make SPI2 work on your board? |
The error code refers to this call. Error codes are defined here. This is a common place for a failure when there is a bad SPI configuration or wiring error. SdFat has no knowledge of what pins are used for MISO, MOSI, or SCK. It only cares about the CS pin and that the SPI instance in the SdSpiConfig() definition works with the standard SPI member functions. Can you test SPI2 to make sure signals are on the correct pins. Here is a loop-back test. It won't test SCK so it would be good if you had a way to do a better test but this is a first step.
Here is the expected output:
SdFat must control CS, not auto control by the SPI driver. |
One possibility is your call: I think this means the SPI library controls CS, not SdFat. Try this call: I looked at the STM32 library and found this:
The default in SPI.h is: Actually you could remove the |
No luck for the last suggestion. :/ I wrote this :
I also tried this:
I could do the loop back test to make sure the right pins are getting configured good idea, the PCB got pins I can solder header to and do a loop back with a jumper. I'll do that on Monday. If that doesn't work I'm probably going to move to STM32Cube as this was working with their libraries using this tutorial. That would be a bummer tho. |
I got loop back to work with this program on my Nucleo L476RG.
Here is a logic analyzer trace: Now I will try to get SdFat to work. |
I attached a SD socket to the SPI2 pins and made these changes to the bench example: Added: Changed SD_CONFIG
Result:
|
Hello Bill, So it is working! For some reason I had to unmount/remount the card when I power cycle the board or reset it. Here's the final config code I used in the end:
With the modification you suggested:
I added the loop on the begin() function because it doesn't always work right away. I suspect either bad sd card or bad soldering. |
If the card is powered on and gets noise on clock with CS high, A card can go into SDIO mode. After that the only way to get it to SPI mode is power cycle. The Arduino Due can even corrupt a card when you upload a program.
|
Hello Bill, So I have an additional question, let me know if I should create a separate issue for it. I started writing code using ReadCsvFile as an example. Here are the parts of the code: In setup :
In the loop:
|
I tried to run the code in loop but it never stops. It just prints "Done" forever. When I did a reset the SD was corrupt since the file was not properly closed. I ran it several times and often the file is OK with the correct content. I added a loop counter and the following at the end of loop like this:
It ran until nLoop was greater than 10. It printed "done" each time and then "stop" The content of the SD was as expected:
I am not sure what you expected. |
For some reason whenever I do file.print() in the loop it crashes or hangs I'm not sure. I'm gonna probe this on the logic analyzer to see what's up and send you the screenshot for it. So it's not hardware, not the SD card. I'm not sure why the main loop causes problems.. |
Hello, So I've been able to fix the problem, after some thorough debugging. Somehow when I put the following code for sd.begin() initialization purpose outside of setup() it worked. Didn't think those class needed to be global.
Here's the full working test code:
|
Yes the instance of the SPI class must be global or in memory that is not destroyed when it goes out of scope. SdFat only gets a pointer to the SPI instance. When SPI_2 went out of scope it's destructor was called and SdFat had a pointer to a section of recycled stack. |
Hello,
I'm trying to connect my STM32L452 chip to an SD Card for logging purpose but it doesn't seem to work using port assignation delivered by STM32duino.
I tried using STM32Cube libraries and it's working, so the problem is not on my PCB but really the SdFat and/or STM32duino and the way I'm initializing things.
I tried to use the code example in here which is shown bellow.
Another thing is I went to find STM32Test.ino and it is mentioned that there is a V2 of the example but I can't find it.
I wonder if I missed something.
The text was updated successfully, but these errors were encountered: