cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F769-DISCO Fatfs not working with SRAM1 and SRAM2 configuration.

tushar_tp
Associate III

Hello,

Hardware : STM32F769-DISCO

Compiler: Atollic 9.3.0

I am trying to merge the Fatfs with mbedtls example from cube 1.15

mbedtls has tx and rx buffers at SRAM2 region.

Fatfs sample program fails to write and read a file.

Can anyone look at the linker script and MPU_Config() function in main.c if I am doing it correctly.

I am attaching the project folder.

PS: simple fatfs program without any linker file modification works OK.

Thanks,

Tushar

1 ACCEPTED SOLUTION

Accepted Solutions

Hello Clive,

I managed to get it working on the SRAM1 and SRAM2 configuration.

Changed the function to this

static void MPU_Config(void)

{

 MPU_Region_InitTypeDef MPU_InitStruct;

 /* Disable the MPU */

 HAL_MPU_Disable();

 MPU_InitStruct.Enable = MPU_REGION_ENABLE;

 MPU_InitStruct.BaseAddress = 0x20020000;

 MPU_InitStruct.Size = MPU_REGION_SIZE_512KB;

 MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;

 MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;

 MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE;

 MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;

 MPU_InitStruct.Number = MPU_REGION_NUMBER0;

 MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;

 MPU_InitStruct.SubRegionDisable = 0x00;

 MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;

 HAL_MPU_ConfigRegion(&MPU_InitStruct);

 /* Configure the MPU as Normal Non Cacheable for Ethernet Buffers in the SRAM2 */

 MPU_InitStruct.Enable = MPU_REGION_ENABLE;

 MPU_InitStruct.BaseAddress = 0x2007C000;

 MPU_InitStruct.Size = MPU_REGION_SIZE_16KB;

 MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;

 MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;

 MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;

 MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;

 MPU_InitStruct.Number = MPU_REGION_NUMBER1;

 MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL1;

 MPU_InitStruct.SubRegionDisable = 0x00;

 MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;

 HAL_MPU_ConfigRegion(&MPU_InitStruct);

 /* Configure the MPU as Device for Ethernet Descriptors in the SRAM2 */

 MPU_InitStruct.Enable = MPU_REGION_ENABLE;

 MPU_InitStruct.BaseAddress = 0x2007C000;

 MPU_InitStruct.Size = MPU_REGION_SIZE_256B;

 MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;

 MPU_InitStruct.IsBufferable = MPU_ACCESS_BUFFERABLE;

 MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;

 MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;

 MPU_InitStruct.Number = MPU_REGION_NUMBER2;

 MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;

 MPU_InitStruct.SubRegionDisable = 0x00;

 MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;

 HAL_MPU_ConfigRegion(&MPU_InitStruct);

 /* Enable the MPU */

 HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);

}

and uncomment the ENABLE_SD_DMA_CACHE_MAINTENANCE in the sd_diskio.c

Thanks,

Tushar

View solution in original post

4 REPLIES 4

You've got 128KB of DTCMRAM, use that for buffering, avoids all the caching issues with DMA.

Polled operation shouldn't have issues, well at least beyond the overrun/underrun and interrupt ones.

Otherwise you've got to use cache management. ST has some workable "ByAddr" sample drivers under the FatFs middleware directories.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
tushar_tp
Associate III

Hello Clive,

128KB would not be enough as I would need 160KB of heap for my FreeRTOS. as my final application would need lots of RAM.

Can you please comment if I can use the fatfs on SRAM1 ? is there any modification needed in my project files?

Tushar Patel

You can use whatever memory you want, I'm suggesting using the DTCMRAM for buffers used for fread/fwrite operations surrounding SDIO/FATFS, which for efficiencies sake really should be sector/cluster aligned.

See

STM32Cube_XYZ\Middlewares\Third_Party\FatFs\src\drivers\sd_diskio_dma_rtos_template.c

ENABLE_SD_DMA_CACHE_MAINTENANCE

>>is there any modification needed in my project files?

If it is not working, then clearly.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Hello Clive,

I managed to get it working on the SRAM1 and SRAM2 configuration.

Changed the function to this

static void MPU_Config(void)

{

 MPU_Region_InitTypeDef MPU_InitStruct;

 /* Disable the MPU */

 HAL_MPU_Disable();

 MPU_InitStruct.Enable = MPU_REGION_ENABLE;

 MPU_InitStruct.BaseAddress = 0x20020000;

 MPU_InitStruct.Size = MPU_REGION_SIZE_512KB;

 MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;

 MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;

 MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE;

 MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;

 MPU_InitStruct.Number = MPU_REGION_NUMBER0;

 MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;

 MPU_InitStruct.SubRegionDisable = 0x00;

 MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;

 HAL_MPU_ConfigRegion(&MPU_InitStruct);

 /* Configure the MPU as Normal Non Cacheable for Ethernet Buffers in the SRAM2 */

 MPU_InitStruct.Enable = MPU_REGION_ENABLE;

 MPU_InitStruct.BaseAddress = 0x2007C000;

 MPU_InitStruct.Size = MPU_REGION_SIZE_16KB;

 MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;

 MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;

 MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;

 MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;

 MPU_InitStruct.Number = MPU_REGION_NUMBER1;

 MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL1;

 MPU_InitStruct.SubRegionDisable = 0x00;

 MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;

 HAL_MPU_ConfigRegion(&MPU_InitStruct);

 /* Configure the MPU as Device for Ethernet Descriptors in the SRAM2 */

 MPU_InitStruct.Enable = MPU_REGION_ENABLE;

 MPU_InitStruct.BaseAddress = 0x2007C000;

 MPU_InitStruct.Size = MPU_REGION_SIZE_256B;

 MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;

 MPU_InitStruct.IsBufferable = MPU_ACCESS_BUFFERABLE;

 MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;

 MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;

 MPU_InitStruct.Number = MPU_REGION_NUMBER2;

 MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;

 MPU_InitStruct.SubRegionDisable = 0x00;

 MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;

 HAL_MPU_ConfigRegion(&MPU_InitStruct);

 /* Enable the MPU */

 HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);

}

and uncomment the ENABLE_SD_DMA_CACHE_MAINTENANCE in the sd_diskio.c

Thanks,

Tushar