Open lhondareyte opened 1 year ago
Hello, and thank you for reporting your issue.
Is 5v power and ground (detailed in your SD card board's user manual) supplied to the SD card board? If so, then apply this diff:
diff --git a/sys/stm32/stm32f4xx_nucleo_sd.c b/sys/stm32/stm32f4xx_nucleo_sd.c
index cc8b213..607b392 100644
--- a/sys/stm32/stm32f4xx_nucleo_sd.c
+++ b/sys/stm32/stm32f4xx_nucleo_sd.c
@@ -107,7 +107,7 @@ SPIx_Init(void)
- SD card SPI interface max baudrate is 25MHz for write/read
- PCLK2 max frequency is 100 MHz
*/
- hnucleo_Spi.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
+ hnucleo_Spi.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4;
hnucleo_Spi.Init.Direction = SPI_DIRECTION_2LINES;
hnucleo_Spi.Init.CLKPhase = SPI_PHASE_2EDGE;
hnucleo_Spi.Init.CLKPolarity = SPI_POLARITY_HIGH;
Recompile and flash the f4discovery kernel. Let me know if this fixes your issue. I will commit a proper fix to the tree once I hear back from you.
Also, try different SD cards or MicroSD cards if your Lexar card isn't working. I test with various SanDisk MicroSD cards.
Regards, Christopher Hettrick
Hello, thanks for your fast reply, Yes, my adapter is 5v powered (with a built-in 3.3v regulator). It works with your patch and a SanDisk card (not Lexar 16go 300x - blue series). Thanks a lot. That said, I had a problem with my connectors and this didn't help. I will submit some patches soon for an easy build under FreeBSD. Thanks again for this port, great job!
Luc Hondareyte.
I forgot the console message :)
2.11 BSD UNIX for STM32, rev G290 #13: Sun Mar 05 11:49:27 CET 2023 luc@unxbox:/home/luc/discobsd/sys/stm32/f4discovery cpu: STM32F407xx rev VGT6, 168 MHz, bus 48 MHz oscillator: phase-locked loop, clock source: high speed external uart2: pins tx=PA2/rx=PA3, af=7, console sd0: port spi2 sd0: type SDHC, size 2576384 kbytes sd0a: partition type b7, sector 2, size 102400 kbytes sd0b: partition type b8, sector 204802, size 2048 kbytes sd0c: partition type b7, sector 208898, size 102400 kbytes phys mem = 192 kbytes user mem = 96 kbytes root dev = (0,1) swap dev = (0,2) root size = 102400 kbytes swap size = 2048 kbytes Automatic boot in progress: starting file system checks. /dev/sd0a: 1452 files, 12015 used, 89984 free /dev/sd0c: 3 files, 3 used, 101996 free Updating motd... done Starting daemons: update cron Mon Jan 30 03:00:55 PST 2023 2.11 BSD UNIX (name.my.domain) (console) login:
Hello, thanks for your fast reply, Yes, my adapter is 5v powered (with a built-in 3.3v regulator). It works with your patch and a SanDisk card (not Lexar 16go 300x - blue series). Thanks a lot. That said, I had a problem with my connectors and this didn't help. I will submit some patches soon for an easy build under FreeBSD. Thanks again for this port, great job!
Luc Hondareyte.
Hi again, I am glad that you have got it working.
Did your issue go away once you changed cards and fixed the wiring? Or did you also need the Prescaler diff? Please test your current working setup, but without the diff applied, and report back of your findings.
In case you are wondering, the SPI-based SD card driver is mainly the Adafruit driver for Nucleo boards that is bundled in STM32CubeF4. It may not yet have support for very new or very large cards. Development boards such as the F412G-Disco have a MicroSD card slot wired for SDIO/SDMMC, which is significantly faster than using the SPI-based mode of SD cards.
Running diskspeed
on a 32GB Sandisk Ultra SDHC UHS-I A1 on STM32F412G-Disco, using sdmmc driver:
# diskspeed
Testing 4-kbyte block size.
Write speed: 8 Mbytes in 7.249 seconds = 1130 kbytes/sec
Read speed: 8 Mbytes in 2.493 seconds = 3286 kbytes/sec
Running diskspeed
on a 32GB Sandisk Ultra SDHC UHS-I A1 on STM32F4-Discovery, using spi SD driver:
# diskspeed
Testing 4-kbyte block size.
Write speed: 8 Mbytes in 26.355 seconds = 310 kbytes/sec
Read speed: 8 Mbytes in 16.178 seconds = 506 kbytes/sec
Thanks for supplying the dmesg / console messages.
Regards
Lightly tested this diff on a brand new STM32F407G-DISC1 board with the same SPI-based micro SD card setup as when I tested on an original version STM32F4DISCOVERY (so early that is has the silicon errata for MCU ID and revision ID) back in March. With or without the diff works fine for me with an old (maybe fake) 1GB SanDisk micro SD card. With or without the diff does not work for me with a new 32GB Sandisk Ultra SDHC UHS-I A1 micro SD card on the new STM32F407G-DISC1 board with long wires hooking up the SD card daughter board.
In my previous comment I had that same 32GB SD card working with the original STM32F4DISCOVERY using SPI and the STM32F412G-Disco (my main development board) using both SPI and SDIO.
I am betting that the long wires to the SD card are causing a timing issue here. Or it could be too new to be supported by the SPI-based SD driver. More investigation is needed.
I'm leaving this open until it gets solved, but in practice this issue gets solved by using a development board with an on-board micro SD card slot that is wired for SDIO, such as the STM32F412G-Disco1 or STM32F469I-Disco2. It's faster as well.
Regards.
Hello, On a F4DICOVERY, sd card is not detected, with this message:
I am using this adapter connected as follow:
The SD card is a lexar 16Go. Any help will be apprecied.