cancel
Showing results for 
Search instead for 
Did you mean: 

[Bug] Errors in template for sd_diskio.c in STM32CubeMX 5.6.0/1

PHlin.1
Associate III

Hi,

I was hoping that this will be fixed in 5.6.1, but it's still there.

In function "DRESULT SD_read" is this part of code:

#if defined(ENABLE_SCRATCH_BUFFER)
    }
    else
    {
      /* Slow path, fetch each sector a part and memcpy to destination buffer */
      int i;
 
      for (i = 0; i < count; i++)
      {
        ret = BSP_SD_ReadBlocks_DMA((uint32_t*)scratch, (uint32_t)sector++, 1);
        if (ret == MSD_OK )
        {

The problem is that variable "ret" is not defined and I have to define it manually after each code generation.

My settings are FreeRTOS, DMA and defined ENABLE_SCRATCH_BUFFER and ENABLE_SD_DMA_CACHE_MAINTENANCE

Also in addition to this, on line 78 is this code with missing USER CODE END comment.

/* USER CODE BEGIN enableSDDmaCacheMaintenance */
#define ENABLE_SD_DMA_CACHE_MAINTENANCE  1 
/* USER CODE BEGIN enableSDDmaCacheMaintenance */

The last thing is that I have defined symbol in project tool settings / Preprocessor "MBEDTLS_CONFIG_FILE="mbedtls_config.h" and this symbol disappear from the project settings every time the CubeMX code is generated, does anyone have any idea why is that happening?

Thanks,

Petr

12 REPLIES 12
Khouloud ZEMMELI
ST Employee

​Hello @PHlin.1​ 

could you please share your ioc file ?

Thanks,

Khouloud

Here is the ioc file

Khouloud ZEMMELI
ST Employee

​Hi @PHlin.1​ ,

For the ret declaration , it's ok on my side : uint8_t ret = BSP_SD_ReadBlocks_DMA((uint32_t*)buff, (uint32_t)(sector), count); (using the 5.6.1 MX version)

For the USER CODE END , issue will be fixed.

Best Regards,

Khouloud

Khouloud ZEMMELI
ST Employee

Sorry , For the  USER CODE END , I have this result using your ioc file:

 /* USER CODE BEGIN enableScratchBuffer */

/* USER CODE END enableScratchBuffer */

/* USER CODE END enableScratchBuffer */​

Khouloud ZEMMELI
ST Employee

/* USER CODE BEGIN enableScratchBuffer */

/* #define ENABLE_SCRATCH_BUFFER */

/* USER CODE END enableScratchBuffer */

@PHlin.1​ 

​Please forget about the latest comment, it's related to an other issue.

Regards,

Khouloud

Hi @Khouloud ZEMMELI​ ,

Which line are you referring to? The same function is called on multiple places and I'm referring to line 333 in generated source code (it's right below "for (i = 0; i < count; i++) {" . On most places there is indeed uint8_t ret = BSP_SD_ReadBlocks_DMA.... , but on that line is only ret = BSP_SD_ReadBlocks_DMA.

If I look into CubeMX template fatfs_sd_diskio_template_c_2.1.4.ftl , this uint8_t is also missing.

Thanks,

Petr

@Khouloud ZEMMELI​ 

I was referring to enableSDDmaCacheMaintenance, not enableScratchBuffer

/* USER CODE BEGIN enableSDDmaCacheMaintenance */
/* #define ENABLE_SD_DMA_CACHE_MAINTENANCE  1 */
/* USER CODE BEGIN enableSDDmaCacheMaintenance */

​Hi @PHlin.1​ 

The ret is declared in line 278 as indicated in your comment :  uint8_t ret = BSP_SD_ReadBlocks..

If there's any problem in the declaration you will receive a compilation error on it.

Best Regards,

Khouloud