Skip to main content
CKugl.1
Senior
December 3, 2022
Question

Is there any way to change HAL's SDMMC_DATATIMEOUT?

  • December 3, 2022
  • 3 replies
  • 2883 views

My system has a user-removeable SD Card. If there is a problem with the card at initialization time, the system gets stuck looping in

SD_FindSCR() at stm32l4xx_hal_sd.c:3,970 0x8039632	
SD_WideBus_Enable() at stm32l4xx_hal_sd.c:3,822 0x803947a	
HAL_SD_ConfigWideBusOperation() at stm32l4xx_hal_sd.c:2,643 0x8038db0	
BSP_SD_Init() at sd_diskio.c:190 0x8025d18	
SD_initialize() at sd_diskio.c:225 0x8025da4	

specifically here:

 while(!__HAL_SD_GET_FLAG(hsd, SDMMC_FLAG_RXOVERR | SDMMC_FLAG_DCRCFAIL | SDMMC_FLAG_DTIMEOUT | SDMMC_FLAG_DBCKEND))
 {
 if(__HAL_SD_GET_FLAG(hsd, SDMMC_FLAG_RXDAVL))
 {
 *(tempscr + index) = SDMMC_ReadFIFO(hsd->Instance);
 index++;
 }
 
 if((HAL_GetTick() - tickstart) >= SDMMC_DATATIMEOUT)
 {
 return HAL_SD_ERROR_TIMEOUT;
 }
 }

Is there any way to override the

#define SDMMC_DATATIMEOUT ((uint32_t)0xFFFFFFFFU)

in stm32l4xx_ll_sdmmc.h?

I'd rather not edit the code generated by SMT32CubeIDE.

STM32CubeIDE

Version: 1.11.0

Build: 13638_20221122_1308 (UTC)

Board Name NUCLEO-L4A6ZG

Generated with: STM32CubeMX 6.5.0

MCU Series STM32L4

MCU Line STM32L4x6

MCU name STM32L4A6ZGTx

MCU Package LQFP144

This topic has been closed for replies.

3 replies

AScha.3
Super User
December 3, 2022
  1. why not just:

#undef SDMMC_DATATIMEOUT

#define SDMMC_DATATIMEOUT ((uint32_t)0x00FFU)

"If you feel a post has answered your question, please click ""Accept as Solution""."
Tesla DeLorean
Guru
December 3, 2022

I don't know why the implementation needs to be this sloppy.

Either parameters need to feed down from the top level, or some of these things need to live in the instance structures, have defaults, and be easy to modify during initialization.

Spinning in loops forever is not a viable error propagation and failure management strategy. So much of this code expects everything to work perfectly, and dies unhelpfully when not.

Poor testing, poor real-world usage and expectations.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
Tesla DeLorean
Guru
December 3, 2022

Probably not without editing something.

You're going to have to take ownership of the code/behaviour and make it work in manner suitable for commercial deployment.

Does the system have a card detect method?

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
CKugl.1
CKugl.1Author
Senior
December 3, 2022

> You're going to have to take ownership of the code/behaviour and make it work in manner suitable for commercial deployment.

I don't disagree, but is HAL intended to be used only as example code? Like most generated code, it doesn't seem to be all that readable for that purpose.

Pavel A.
Super User
December 5, 2022

> is HAL intended to be used only as example code?

Call it "rapid prototyping"?

Changes in the ST library can be done in a controlled way - like, for example, when one needs to modify Linux drivers or kernel itself.

Keep it in a version control, branch and commit your changes.

This is maybe not for students or amateurs, but not a rocket science.

AScha.3
Super User
December 3, 2022

yep, most micro-sd-card-holders have a small switch, to check, card in or not.

but i came to same problem just 2 days ago: sd-card suddenly dead after 1y 24/7 in use.

system wait...50 days. long timeout...

no tested solution until now, but should be easy to get around.

"If you feel a post has answered your question, please click ""Accept as Solution""."