3

I'm starting to work with a stm32l0 board and it was fine until I had some more interesting functions to use. I never read SD card out of windows, I found Pins links and started to read about SPI which could be a suitable solution for our prject (I think).

But the issue is in the programming part, every tutorial I find skips basics. I uses STM32CubeMX to generate code with HAL and FATFS but I don't know how to initialize and then use my SD card. I try to paste code I find but I can't debug it then and there is no point just pasting someone's code.

Thanks and sorry for my grammar,

EDIT : I came here after this post : link I'm now trying to access a SDcard with a stm32l0 controller. I've been advised to use FATFS to read the device but what I understood is that the library needs a way to access the data : SPI. I selected FATFS and SPI2 in STM32CubeMX and imported the project in Eclipse (I'm using HAL and the SW4STM32). On the pin description I saw MISO,CK,MOSI in CubeMX which were on pins PB12,PB13,PB14. But in the main file those pins are never used.
Another thing affraid me in the post I mentionned : the SDcard needs to be initialized in a way a never heard of.
I don't know if you need to have the SPI_Init and GPIO_Init functions, I will edit this message if you need it.
I will edit anyway in the morning because the post must be so confuzed, my brain is burning up i'm sorry. Ask if you need precision on whatever. Thanks !

Blaitox
  • 33
  • 1
  • 1
  • 4
  • Welcome to Stack Overflow! Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, [describe the problem](http://meta.stackoverflow.com/questions/254393) and what has been done so far to solve it. – Joe C Feb 19 '17 at 22:24
  • Sorry I didn't know. I posted here because I found a similar problem here but the author looked like he managed to do a lot of things that might help me before being stuck. I'll find the subject and post it just after ! – Blaitox Feb 19 '17 at 23:03

2 Answers2

2

If you use CubeMx and configure SPI to access SD card, the pins are automatically configured in your code. Look at the definitions/implementations of the first few functions in your generated main.c.

If you do not have any experience in STM32 and its HAL drivers, first try to understand how the things stack up.

The quickest way to do that is to try an example.

All your CubeMx Firmware libraries are located at

C:/Users/UserName/STM32Cube/Repository/STM32Cube_FW_XX

Go to Projects>Examples folder (may not be exact - but paths are similar) and you will find the examples.

SamR
  • 384
  • 3
  • 12
  • What you mean is that the "hspi.Instance = SPI2;" automatically sets the right pins for the bus ? – Blaitox Feb 21 '17 at 21:59
  • If you go to Cube, in the pinout tab, enable the SPI peripheral to see the GPIOs automatically allocated in the package view. When you generate the code, MX_XXXX methods configure the pins and the peripheral – SamR Feb 21 '17 at 22:03
  • Ok thank you ! I read SPI examples in the folder you gave me, and I understood how to send bytes. But do you know if I have to initialize the entire process myself or is it done with the FatFs f_mount function ? I am not familiar with the "mount" word so I don't get how far it goes. And in this case what name does my card have ? I read sometimes "0" or sometimes "SD:" Or do i have to send the 74 clock cycles, then the byte, and then use f_mount on it ? – Blaitox Feb 21 '17 at 22:14
  • 1
    Enable FATFS in Cube pinout tab under middleware tree. Then go to configuration tab and you can configure FATFS (If you dont know what you are doing, the dafaults come with Cube is fine). Generate code and then read [STM32 FATFS guide](http://www.st.com/content/ccc/resource/technical/document/user_manual/61/79/2b/96/c8/b4/48/19/DM00105259.pdf/files/DM00105259.pdf/jcr:content/translations/en.DM00105259.pdf) – SamR Feb 21 '17 at 22:36
  • I didn't notice the tab in Cube thanks ! I'll read that and run some tests, may I ask here if I have some issues with FatFs ? – Blaitox Feb 22 '17 at 00:11
  • Not that I'm aware of. I have used it before and works well. – SamR Feb 22 '17 at 02:47
0

For others facing this issue, just select user defined in CubeMX and use kiwih's drivers. They are very good and well documented!

https://github.com/kiwih/cubemx-mmc-sd-card