Wednesday, May 13, 2020

SDCARD - Nucleoboard

nucleo.jpg The Nucleo-H743ZI2 - How much did I just bite off!!! Been at this problem for almost 2 weeks now, the SDCARD reader, VIA the SPI and SDMMC1 while they both worked with the example code, but those example code had other parts i didn’t need. So removing the parts that were’nt relevent to me my project, I ended up breaking the code.

IT was clearly required to create a whole new project - Now I’ve done this multiple times and each time the sodding FatFS didn’t work!

After I Found the debug infomation and actually a HUGE amount of info from a Facebook user by the name of Jeff, lent me his code for the sdcard, it wasn’t completed and didn’t work for what I needed, HOWEVER It did point me to the directions of the missing commands!

In the file

__weak uint8_t BSP_SD_Init(void)
  uint8_t sd_state = MSD_OK;
  /* Check if the SD card is plugged in the slot */
  //if (BSP_SD_IsDetected() != SD_PRESENT)
  /* HAL SD initialization */
  sd_state = HAL_SD_Init(&hsd1);

  return sd_state;

what I did was the comment the check to see if the card was inserted, while I will put this in later, i just wanted to know if the card worked.

The SDCard has 2.2K resistor pull-ups, connected to MOSI, and MISO - the MX IDE calls these, SDMMC1_CMD (mosi), SDMMC1_DO (miso).

on the Nucleoboard there are red, green and a yellow.

#define GREEN_PIN                                GPIO_PIN_0
#define GREEN_GPIO_PORT                          GPIOB

#define YELLOW_PIN                                GPIO_PIN_1
#define YELLOW_GPIO_PORT                          GPIOE

#define RED_PIN                                GPIO_PIN_14
#define RED_GPIO_PORT                          GPIOB

void PrepUserOI(){


	GPIO_InitTypeDef GPIO_InitStruct = {0};
	GPIO_InitStruct.Pin = GPIO_PIN_1;
	GPIO_InitStruct.Pull = GPIO_NOPULL;
	HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);

	GPIO_InitStruct.Pin = GPIO_PIN_0;
	GPIO_InitStruct.Pull = GPIO_NOPULL;
	HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

	GPIO_InitStruct.Pin = GPIO_PIN_14;
	GPIO_InitStruct.Pull = GPIO_NOPULL;
	HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

inside the main file
the annoypart was to tell the system to START the sd_init();
sadly i couldn’t find this in the information documenations normally provided by ST.

here is how I got it working

 /* Initialize all configured peripherals */
  char res;
  //res = disk_initialize(0);
	res = BSP_SD_Init();
	if (res == FR_OK) {
		res = disk_initialize(0);
		if (res == FR_OK) {
			res = f_mount(&fs, "0:/", 0);
			if (res == FR_OK) {
				strcpy(buffer, "Hello world, this is a test");
				if (f_open(&fil, "hello world test file.txt", FA_CREATE_ALWAYS | FA_WRITE)
						== FR_OK) {

					f_write(&fil, buffer, sizeof(buffer), &bytes);




the code uploaded and begin to run, and instead of the yellow pulse range of around 200khz, i got the fill 12Mhz and some Blue pulses (this is the Data to the SDcard - MOSI)


with this I made a backup of this as the whole ordeal was awful!

BUT I concluded that while messy, the IDE and MX did do a good job of filling in the SDMMC1 and paring up to the SDCARD FatFS 0.12C

I have included the download of this project (its only for the Fat32 access)
CubeIDE GCC - C (not C++) Download Source

I’ll write up a more detailed what I found, how I figured out how to get this system to work!

Add comment

Fill out the form below to add your own comments