cancel
Showing results for 
Search instead for 
Did you mean: 

SDIO - 32F411 - Hw or Sw problem?

leogarberoglio
Associate III
Posted on April 21, 2015 at 00:57

Hi, I made a custom board to atach to a nucleo 411 board with a uSD shocket. I'm trying to get FatFs on it. I'v test almost every code on the web. I use System Workbench and Cube/stdperiph_lib.

I would like a simple initialization and test software just to dichard hardware problem. I'v saw a lot of examples, but with DMA and other things.

Is there a simple example just to test the minimun necesary comunication with the SD ? jus to be sure that there is no hardware issue on my board.

Thank!
9 REPLIES 9
leogarberoglio
Associate III
Posted on April 21, 2015 at 04:22

Well, I make a simple cube mx project, just with SDIO config.

I obtain this into main.c

int main(void)
{
/* MCU Configuration----------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_SDIO_SD_Init();
while (1)
{
}
/* USER CODE END 3 */
}

I debug it and step by step go into

MX_SDIO_SD_Init

void MX_SDIO_SD_Init(void)
{
hsd.Instance = SDIO;
hsd.Init.ClockEdge = SDIO_CLOCK_EDGE_RISING;
hsd.Init.ClockBypass = SDIO_CLOCK_BYPASS_DISABLE;
hsd.Init.ClockPowerSave = SDIO_CLOCK_POWER_SAVE_DISABLE;
hsd.Init.BusWide = SDIO_BUS_WIDE_1B;
hsd.Init.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_DISABLE;
hsd.Init.ClockDiv = 0;
HAL_SD_Init(&hsd, &SDCardInfo);
}

I don't go into HAL_SD_Init, I just wait until it execute, and then I saw what SDCardInfo have: https://www.dropbox.com/s/jgrm9w380sqwyf2/Captura%20de%20pantalla%202015-04-20%png?dl=0 So I can see info about my SD card, and it seems to be ok (CardCapacity is almost 1Gb) So may I say that my hardware is ok? or I need to run some other test? If I can't make FatFs working is becouse a software problem? Thank
leogarberoglio
Associate III
Posted on April 21, 2015 at 04:43

Now I add this code on main.c:

err = HAL_SD_ReadBlocks(&hsd, buf, 0, 512, 4);

And I obtain this into buf:

Name : buf
Details:''ë<\220MSDOS5.0\0\002 \002\0\002\0\002\0\0øç\0?\0ÿ\0\0\0\0\0\0À\034\0\0\0)Ë\214ÎtNO NA
E FAT16 3É\216Ѽð{\216Ù¸\0 \216Àü½\0|8N$}$\213�?\231è<\001r\034\203ë:f¡\034|&f;\a&\212Wüu\006\200Ê\002\210\026\002\200Ã\020së3É\212F\020\230÷f\024\003F\034\023V\036\003F\016\023Ñ\213v\021`\211Fü\211Vþ¸ \0÷æ\213^\v\003ÃH÷ó\001Fü\021Nþa¿\0\0èæ\0r9&8-t\027`±\v¾¡}ó¦at2Nt\t\203Ç''...
Default:0x20000460
Decimal:536872032
Hex:0x20000460
Binary:100000000000000000010001100000
Octal:04000002140

So, the hardware is Ok, right?
stm32forum
Associate II
Posted on April 21, 2015 at 15:08

Hi,

How did you made the connection (pin numbers -> SD)?

Did you use pull-up resistors?

leogarberoglio
Associate III
Posted on April 21, 2015 at 17:47

I use PC8, PC12 and PD2, this is ok. I have PU resistor on CMD and D0 lines

I test this code:

/* Includes ------------------------------------------------------------------*/
#include ''stm32f4xx_hal.h''
#include ''stm32f4xx_hal_sd.h''
#include ''sdio.h''
#include ''gpio.h''
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static uint32_t buf[512*4];
int main(void)
{
HAL_SD_ErrorTypedef err;
uint32_t cnt=0;
/* MCU Configuration----------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_SDIO_SD_Init();
while (1)
{
cnt++;
err = HAL_SD_ReadBlocks(&hsd, buf, 0, 512, 4);
if(err!=SD_OK)
{
cnt=0;
MX_SDIO_SD_Init();
}
}
}

with it I found a problem on HAL_SD_Init, las line on this function is

SDIO_Init(hsd->Instance, hsd->Init); 
return errorstate;

and with this instruction ClockDiv has 0x00 so the SDIO frequency goes to 24MHz and HAL_SD_ReadBlocks have random errors. I fix it with this:

/* Configure SDIO peripheral interface */
hsd->Init.ClockDiv = 0x76;
SDIO_Init(hsd->Instance, hsd->Init); 
return errorstate;
}

This way I have 400Khz and HAL_SD_ReadBlocks run ok. I test with 2MHz, 5MHz and 10MHz and everithing is ok, ReadBlocks run right. When I test with 12MHz or more I start to got problems. So, I think the harware is ok (for 10MHz) and I could implement FatFs. Is there another test to check that HW is Ok? Regards!
Posted on April 21, 2015 at 19:02

Is there another test to check that HW is Ok?

I'd test with working SPL code as a starting point, and I'd probably put pull-ups on the unused pins.

Attached is a blind stab at code that should run on the F411, based on code that worked on the STM32F401C-DISCO with a STM32F4-DIS-BB breakout board.

Summary:

CPU @ 42 MHz

SDIO @ 48 MHz (24 MHz external clock), 1-bit, DMA

Output via USART2 PA2/PA3 (Nucleo Virtual) @ 115200 8N1

No Card Detect pin support

________________

Attachments :

SDIOTEST-NUCLEO-ELGARBE-1BIT-REL1.hex : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I10n&d=%2Fa%2F0X0000000bgr%2FLuO27TvBaG8ZZ1nh.PJdgfnKgekYDedDM3_oQMXo84k&asPdf=false
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
leogarberoglio
Associate III
Posted on April 21, 2015 at 20:51

Thank clive, have you got source? system workbench project, maybe?

Posted on April 21, 2015 at 21:46

Of course I have source, I built it in Keil. It's bound to a bunch of test framework code I'm not sharing. The code is materially similar to that which I've released in Keil and GNU/GCC form for the STM32F4-DISCO series.

I have neither STM32F411E-DISCO or NUCLEO-411RE  boards.

Does the example work? Should provide read/write timing, and integrity check via a CRC32 of the data that was written vs that read back.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
leogarberoglio
Associate III
Posted on April 21, 2015 at 23:54

Clive, I attach a picture of my OSC configuration. Nucleo board have not external XTAL... Is your build compatible with Nucleo osc config?

Thank!

________________

Attachments :

Captura_de_pantalla_2015-04-21_18.45.10.png : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I10i&d=%2Fa%2F0X0000000bgp%2FhYgJJjpygh2SkVP8xZX6p0AKp2wlFo3aa3EiUIVsEHQ&asPdf=false
Posted on April 22, 2015 at 02:22

But you should be able to get a solid 8 MHz HSE input via the the MCO/PA8 output of the F103 doing the ST-LINK functionality.

Not sure which source I'm using here, or what the default jumpers/bridges on the Nucleo are.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..