cancel
Showing results for 
Search instead for 
Did you mean: 

Return Code in Cube MX's initialization functions

robert-hartung
Associate II
Posted on September 09, 2015 at 14:17

When using CubeMX to generate project (e.g. for SW4STM32), the code for SD Card looks like this:

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 = 4;

  HAL_SD_Init(&hsd, &SDCardInfo);

  HAL_SD_WideBusOperation_Config(&hsd, SDIO_BUS_WIDE_4B);

}

The user has no possibility to add own error detection code, as there is no use section. My suggestion is to return the status type like this:

HAL_SD_ErrorTypedef MX_SDIO_SD_Init(void)

{

 HAL_SD_ErrorTypedef err = SD_OK;

  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 = 4;

  err = HAL_SD_Init(&hsd, &SDCardInfo);

  if(err != SD_OK) {

 return err;

  }

  err = HAL_SD_WideBusOperation_Config(&hsd, SDIO_BUS_WIDE_4B);

  return err;

}

- Robert

#improvement #hal #cubemx
3 REPLIES 3
Posted on September 11, 2015 at 17:34

Hi hartung.robert,

Could you precise the STM32CubeMx version and the product you are using?

-Shahrzad-

robert-hartung
Associate II
Posted on October 12, 2015 at 14:51

Hi shahrzad,

I am using: STM32CubeMX Version 4.1.0, STM32Cube V1.0

I am using an STM32F2 processor.

- Robert

Posted on October 12, 2015 at 19:16

Hi hartung.robert,

In main.c file, there is an emplacement for user code directly after the call of ''MX_SDIO_SD_Init(void)'' function.I think that you can add your code within it.

The behavior is what you expect.

-Shahrzad-