Unable to use library on GPIOs > 31 on RP2350B
I'm working a custom board that uses the RP2350B MCU. I have found that I am unable to use SDIO with an SD card mapped to pins 33-39.
The B version of the RP2350 has additional GPIOs beyond the 29 available on the A version. This is more then the ~30 GPIOs that were available on the RP2040 and more then the 32 GPIO wide GPIO output system on the PIO. The hardware solution to this is to use the PIO:GPIOBASE register to "shift" the output of the PIO so that it addresses outputs 16-47. I looked through PioSdioCard.cpp, and didn't see any indication that the library detects the case where the shifting is necessary.
I want to make a pull request to add proper support for using pins 32 and up with SDIO. This would work be detecting the case where the PIO shift is required and offsetting the input pins while changing the PIO base.
Could you try SdFat-beta. It has support for RP2350B.
Edit: I am still making major changes to SdFat-beta so it would be helpful if you tried the attached version.
Unzip it and place the contents in an SdFat folder.
I have been debugging with an Adafruit Metro RP2340. I can get it to run at 150 MHz but it won't overclock much. Pico 2 with my homemade socket runs at 200 MHz.
I added fourth parameter toSdioConfig, the PIO clock divisor. The Metro will run with this set to 2.0, 1.5, and 1.25. 1.25 produces an asymmetric SD clock of 1/5 CPU clock.
I just tried another SD with the Metro RP2350 board. Looks like the problem was the SD I was using. Here is the bench example at 200 MHz:
Type is exFAT Card size: 256.36 GB (GB = 1E9 bytes)
Manufacturer ID: 0X1B OEM ID: SM Product: FE4S9 Revision: 3.0 Serial number: 0X8109620E Manufacturing date: 6/2023
FILE_SIZE_MB = 20 BUF_SIZE = 8192 bytes Starting write test, please wait.
write speed and latency speed,max,min,avg KB/Sec,usec,usec,usec 21318.41,3201,374,380 21250.45,11463,374,384
Starting read test, please wait.
read speed and latency speed,max,min,avg KB/Sec,usec,usec,usec 17790.63,467,459,460 17774.82,482,459,460
Still the Pico 2 beats the Meto. Pico 2 at 250 MHz with the same SD:
Type is exFAT Card size: 256.36 GB (GB = 1E9 bytes)
Manufacturer ID: 0X1B OEM ID: SM Product: FE4S9 Revision: 3.0 Serial number: 0X8109620E Manufacturing date: 6/2023
FILE_SIZE_MB = 20 BUF_SIZE = 8192 bytes Starting write test, please wait.
write speed and latency speed,max,min,avg KB/Sec,usec,usec,usec 26520.79,2787,299,304 26591.32,6789,299,306
Starting read test, please wait.
read speed and latency speed,max,min,avg KB/Sec,usec,usec,usec 22120.21,389,369,369 22144.71,379,369,369
Thank you for your help with this. The SdFat-Beta code you provided worked without any issues whatsoever. I also experimented with the PIO clock divisor. With my board I was able to use clock divisior = 1.0. Curiously, changing the clock divisor didn't seem to have any impact to the benchmark results.
Here are the results I got with a 16GB SanDisk card:
OEM ID: SD
Product: SC16G
Revision: 8.0
Serial number: 0X4D10C7A4
Manufacturing date: 4/2024
FILE_SIZE_MB = 5
BUF_SIZE = 512 bytes
Starting write test, please wait.
write speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
3654.97,38997,127,138
3849.11,15912,127,132
Starting read test, please wait.
read speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
3793.63,196,133,133
3793.63,197,133,133
Any idea on when the code adding support for the RP2350B will hit the main SdFat repo? Also what should we do with this issue ticket?
Curiously, changing the clock divisor didn't seem to have any impact to the benchmark results.
Something is wrong, your speed is nowhere near what I would expect for PIO clock divisor of one.
Here is the Adafruit RP2350 Metro which has a RP2350B with an old 16GB SanDisk card and the default PIO clock divisor of 1. CPU clock is 150 MHz.
I get write over 14,000 KB/Sec you get about 3,700 KB/Sec.
Type is FAT32 Card size: 15.93 GB (GB = 1E9 bytes)
Manufacturer ID: 0X3 OEM ID: SD Product: SE16G Revision: 8.0 Serial number: 0X2A26D2D4 Manufacturing date: 10/2015
FILE_SIZE_MB = 5 BUF_SIZE = 512 bytes Starting write test, please wait.
write speed and latency speed,max,min,avg KB/Sec,usec,usec,usec 14705.88,13751,32,34 14367.82,8071,32,35
Starting read test, please wait.
read speed and latency speed,max,min,avg KB/Sec,usec,usec,usec 12919.90,67,39,39 12919.90,62,39,39
Any idea on when the code adding support for the RP2350B will hit the main SdFat repo? Also what should we do with this issue ticket?
I need to post my current version as a beta for at least a month. There are a huge number of changes since the current release was posted six months ago.
You can just leave this open so others will find it and use the beta. The current beta works but Earle Philhower has added some new features I want to support so I need to post the version in the above zip file.
I found the issue that was causing my benchmark results to be much worse then yours - I had turned off optimization in the Arduino IDE. Compiling with -Os gives much improved results:
Manufacturer ID: 0X3
OEM ID: SD
Product: SC16G
Revision: 8.0
Serial number: 0X4D10C7A4
Manufacturing date: 4/2024
FILE_SIZE_MB = 5
BUF_SIZE = 512 bytes
Starting write test, please wait.
write speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
11792.45,57392,32,42
13477.09,47422,32,37
Starting read test, please wait.
read speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
12853.47,62,39,39
12853.47,60,39,39
Furthermore the speed is reduced by about half when changing the PIO divider to 2.