[SOLVED] SDFat port for STM Core

lucky1
Mon Dec 17, 2018 3:07 pm
I know about the FatFS implementation from CubeMX but is there also a port of the SDFat library ?

BennehBoy
Mon Dec 17, 2018 3:14 pm
[lucky1 – Mon Dec 17, 2018 3:07 pm] –
I know about the FatFS implementation from CubeMX but is there also a port of the SDFat library ?

If you’re wanting to drive an onboard SDIO device, probably not.

If it’s for a SPI type SD reader, have you tried the official version -> https://github.com/greiman/SdFat


lucky1
Mon Dec 17, 2018 4:02 pm
Yes, I have tried but the problem is that it relies on the SPI library and the implementation which is in the STM32 Core is not compatible.
I have also tried the SDFat/SPI/SDIO/stm32_dma implementation which is in the STM32GENERIC Core but that is also not working.

I have a larger teensy 3.6 project which relies on SDFat which I want to port to Nucleo F7 or H7 and I don´t want to use STM32GENERIC for it because
it is not officially supported by STM


BennehBoy
Mon Dec 17, 2018 4:57 pm
[lucky1 – Mon Dec 17, 2018 4:02 pm] –
Yes, I have tried but the problem is that it relies on the SPI library and the implementation which is in the STM32 Core is not compatible.

Not compatible how? Do you get any errors reported? If so, please post them.


fpiSTM
Mon Dec 17, 2018 7:28 pm
I’ve never tried SDFat and don’t know ifsomeone tried.

BennehBoy
Mon Dec 17, 2018 10:09 pm
[fpiSTM – Mon Dec 17, 2018 7:28 pm] –
I’ve never tried SDFat and don’t know ifsomeone tried.

I’ll try it tomorrow if I get time.


lucky1
Tue Dec 18, 2018 3:36 pm
Seems I got it to work with SDIO by adding the original code from here
https://github.com/greiman/SdFat and the SdioSTM32.cpp from the STM32Generic core SDFat library.
Only had to initialize the SDIO GPIOS. I also used the SDIO and stm32_dma library from STM32Generic.
However SPI SD Card would also be interesting for me but I haven´t looked into that.

BennehBoy
Tue Dec 18, 2018 4:03 pm
I might be tempted to do the same, the variable handling when printing (could be compile options clib/printf etc) to fatfs seems lacking compared to sdfat… Care to share your code?

BennehBoy
Tue Dec 18, 2018 6:49 pm
[BennehBoy – Tue Dec 18, 2018 4:03 pm] –
I might be tempted to do the same, the variable handling when printing (could be compile options clib/printf etc) to fatfs seems lacking compared to sdfat… Care to share your code?

Nope it’s not the newlib options.

invalid conversion from 'int' to 'const char*' [-fpermissive]


lucky1
Tue Dec 18, 2018 7:11 pm
I uploaded it here https://github.com/lucky01/SdFat
Maybe you get the SPI version to work. I have no idea how to initialize it.

BennehBoy
Tue Dec 18, 2018 7:34 pm
sdfat & SPI SD works fine btw. And no errors when trying to print integers.

lucky1
Wed Dec 19, 2018 7:14 am
I have the SD card slot connected to SPI2 on my STM32F4DISCO. Do you know how to get it running with that config ?

BennehBoy
Wed Dec 19, 2018 8:31 am
I wrote a long post explaining how to set this up then got to how to tell sdfat which bus to use and realised that the library will only work against the default spi instance.

Any reason why you can’t share SPI1?


BennehBoy
Wed Dec 19, 2018 9:03 am
And as if by magic a new version of sdfat popped up in the IDE…

It looks like there’s a method to switch to alternate spi instances now…. (or I missed it previously)

setPort

void SdSpiAltDriver::setPort(uint8_t portNumber) {
m_spi = &m_SPI1;
#if BOARD_NR_SPI >= 2
if (portNumber == 2) {
m_spi = &m_SPI2;
}
#endif // BOARD_NR_SPI >= 2
#if BOARD_NR_SPI >= 3
if (portNumber == 3) {
m_spi = &m_SPI3;
}
#endif // BOARD_NR_SPI >= 2


BennehBoy
Wed Dec 19, 2018 10:08 am
PS, I’ll have a play at using SPI2 on one of my 407VET6’s later.

BennehBoy
Wed Dec 19, 2018 11:39 am
Looks like the architecture preprocessors in sdfat would need messing with to get spi2 working for STM’s core, the method to invoke sdfat stating a spi port fails when I try compiling.

no matching function for call to ‘SdFat::SdFat(int)’


BennehBoy
Tue Jan 15, 2019 2:41 pm
In case anyone is interested, I ask Greiman he would add HAL SDIO support to sdfat, and pointed him at the work done by danielf and lucky -> https://github.com/greiman/SdFat/issues/124

lucky1
Thu Jan 17, 2019 11:17 am
[BennehBoy – Tue Dec 18, 2018 7:34 pm] –
sdfat & SPI SD works fine btw. And no errors when trying to print integers.

I just tried SDFat with SPI on my Disco STM32F407 without success.
How did you connect the SD slot ?


BennehBoy
Thu Jan 17, 2019 11:39 am
I used an external SD slot, it’s not possible to use the onboard SD reader via SPI.

lucky1
Thu Jan 17, 2019 1:06 pm
[BennehBoy – Thu Jan 17, 2019 11:39 am] –
I used an external SD slot, it’s not possible to use the onboard SD reader via SPI.

I use a external slot too, but which pins did you connect it to ?


BennehBoy
Thu Jan 17, 2019 1:10 pm
I set mine up this way:

MOSI PB5 //HWSPI Instance 1
MISO PB4 //HWSPI Instance 1
CLK PB3 //HWSPI Instance 1
CS PE13 // any GPIO – you do not have to use the SS pin couple with the SPI instance, since this is s/w controlled anyway


lucky1
Thu Jan 17, 2019 1:43 pm
[BennehBoy – Thu Jan 17, 2019 1:10 pm] –
I set mine up this way:

MOSI PB5 //HWSPI Instance 1
MISO PB4 //HWSPI Instance 1
CLK PB3 //HWSPI Instance 1
CS PE13 // any GPIO – you do not have to use the SS pin couple with the SPI instance, since this is s/w controlled anyway

Does not work. My testcode looks like this. Any idea ?

SdFat SD;

SD.begin();
File myFile = SD.open("test.txt", FILE_WRITE);
if(myFile.isOpen()) {
myFile.println("testing 1, 2, 3.");
myFile.close();
}


lucky1
Thu Jan 17, 2019 2:03 pm
Is working ! My SD card was defective !! Grrrr !
Thanks for your help

BennehBoy
Wed Jan 23, 2019 4:29 pm
BTW, the latest version of sdfat allows for using alternate spi ports…

explicit SdFat(SPIClass* spiPort);


Leave a Reply

Your email address will not be published. Required fields are marked *