2017-05-20 03:24 PM
Hi all!
I'm trying to read/write data to an SD card from my STM32F072 Discovery board.
I configure SPI1 on CubeMx and the FatFs middleware. I've written the user_dsikio.c and the Input-Output functions based on the STM32F072 Eval board, but I can't make it work.
When I try to open a file, or format the SD, the microcontroller stops there and finishes at the Default_Handler, as I can see with the debugger.
Where can I find an example of a STM32F072 Discovery board with an SD?
Can anyone help me?
Thanks!!!!!!!!!!
#sd-card #stm32f072 #stm32f072-discoverySolved! Go to Solution.
2017-05-25 10:05 PM
Hi, there. I just download your project.
In your io_sd.c
static void SPIx_Init(void){ //SPI baudrate is set to 12 MHz (PCLK1/SPI_BaudRatePrescaler = 48/4 = 12 MHz) //PCLK1 frequency is set to 48 MHz //SD card SPI interface max baudrate is 25MHz for write/read hal_Spi.Instance = SPI1; hal_Spi.Init.Mode = SPI_MODE_MASTER; hal_Spi.Init.Direction = SPI_DIRECTION_2LINES; hal_Spi.Init.DataSize = SPI_DATASIZE_8BIT; hal_Spi.Init.CLKPolarity = SPI_POLARITY_LOW; hal_Spi.Init.CLKPhase = SPI_PHASE_2EDGE; hal_Spi.Init.NSS = SPI_NSS_SOFT; hal_Spi.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64; hal_Spi.Init.FirstBit = SPI_FIRSTBIT_MSB; hal_Spi.Init.TIMode = SPI_TIMODE_DISABLE; hal_Spi.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; hal_Spi.Init.CRCPolynomial = 7; hal_Spi.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE; hal_Spi.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;...Should it be SPI_POLARITY_HIGH?
You may use debug step by step to discover SPIx is really initialzed.
Hope it helps.
zt
2017-05-20 06:25 PM
Do you have an adequate stack allocation? Is there an interrupt you are not handling?
2017-05-22 01:55 PM
Hi!
The stack allocation is configured to 0x230. May be it not enough?
What interrupts I have to define? I set FatFs with the default configurations.
Sorry for my questions, I'm new on this middleware.
Thanks!
2017-05-22 02:39 PM
That's rather small, try starting with 0x1000 (4KB). Review how deep you're into it when you hit the Default Handler.
The ones from SPI1 if it is using them. Just suggesting the most probable causes for the failure you describe.
>>
I'm new on this middleware
That's Ok, I'm not supporting it
2017-05-22 03:13 PM
I will try and let you know!
Thanks!
2017-05-22 06:07 PM
Hi,
I changed the stack, but it still doesn't work. I post in the link my project with the source code.
https://drive.google.com/open?id=0B3Bi8jcrgm3qNmptbTFRcS1vTGs
SD is connected to SPI1.
What I'm doing wrong? : (
Thanks!
2017-05-23 03:48 AM
What I'm doing wrong? : (
I'm no Cube user either.
You can evaluate the SCB registers for causes once you are in the fault handler, or trying to step through the code until you find the 'offensive' code.
Both requires usage of the debugger.
2017-05-25 06:21 PM
Hey Pablo,
in
http://www.st.com/en/embedded-software/stm32cubef0.html
, there is an example of uSD/Fatfs for STM32F072 Eval(download the source, unzip it , located in STM32Cube_FW_F0_V1.8.0\Projects\STM32072B_EVAL\Applications\FatFs\FatFs_uSD)
----------------------------------------------------------------------------------------------------------------------
I did use spi and F0 device with Fatfs and uSD few months ago, I basically follow the structure in the cube example.
And it works fine. However, there is a malloc instruction called in BSP_SD_WriteBlocks and BSP_SD_ReadBlocks
subroutines. You may change it if you don't like.
Hope that helps you too!
Zt.
2017-05-25 10:05 PM
Hi, there. I just download your project.
In your io_sd.c
static void SPIx_Init(void){ //SPI baudrate is set to 12 MHz (PCLK1/SPI_BaudRatePrescaler = 48/4 = 12 MHz) //PCLK1 frequency is set to 48 MHz //SD card SPI interface max baudrate is 25MHz for write/read hal_Spi.Instance = SPI1; hal_Spi.Init.Mode = SPI_MODE_MASTER; hal_Spi.Init.Direction = SPI_DIRECTION_2LINES; hal_Spi.Init.DataSize = SPI_DATASIZE_8BIT; hal_Spi.Init.CLKPolarity = SPI_POLARITY_LOW; hal_Spi.Init.CLKPhase = SPI_PHASE_2EDGE; hal_Spi.Init.NSS = SPI_NSS_SOFT; hal_Spi.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64; hal_Spi.Init.FirstBit = SPI_FIRSTBIT_MSB; hal_Spi.Init.TIMode = SPI_TIMODE_DISABLE; hal_Spi.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; hal_Spi.Init.CRCPolynomial = 7; hal_Spi.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE; hal_Spi.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;...Should it be SPI_POLARITY_HIGH?
You may use debug step by step to discover SPIx is really initialzed.
Hope it helps.
zt
2017-06-08 05:26 PM
Thank you very much!! I was out of the office, that's why I didn't reply.
It's Working!
Thanks a lot