2025-07-22 1:44 AM - edited 2025-07-22 2:00 AM
Hi all,
I'm working on a custom STM32MP135 SOC hosting a MMC memory. The original firmware creates some tasks by the osThreadNew() function and works correctly.
Now I'm inserting FileX module on the firmware to support a FAT fs on the MMC memory.
The firmware lauch a mmc_init() function to setup the FileX structures:
fx_system_initialize();
UINT status = fx_media_open(&mmc_disk,
MMC_MEDIA_NAME,
fx_stm32_mmc_driver,
(VOID *) 0x00,
(VOID *) media_memory,
sizeof(media_memory));
printf("[mmc_init] Media open status: x%x\r\n", status);
#if FORCE_MMC_FORMAT == 1
status = FX_BOOT_ERROR; //
#endif
if (status != FX_SUCCESS)
{
printf("[mmc_init] Failure: x%x\r\n", status);
// Se l'errore è FX_BOOT_ERROR, proviamo a formattare il media
if (status == FX_BOOT_ERROR) {
printf("[mmc_init] Attempting to format media...\r\n");
status = storage_mmc_format();
if (status != FX_SUCCESS) {
printf("[mmc_init] Format failed: %d\r\n", status);
return 0;
}
printf("[mmc_init] Media formatted successfully\r\n");
status = fx_media_open(&mmc_disk,
MMC_MEDIA_NAME,
fx_stm32_mmc_driver,
(VOID *) 0x00,
(VOID *) media_memory,
sizeof(media_memory));
if (status != FX_SUCCESS) {
printf("[mmc_init] Media open after format failed: x%x\r\n", status);
return 0;
}
} else {
return 0;
}
}
STORAGE_MMC_MediaInfo mmc_info;
if (storage_mmc_get_media_info(&mmc_info) == FX_SUCCESS)
{
printf("[mmc_init] Media info:\r\n");
printf("[mmc_init] Name: '%s'\r\n", mmc_info.media_name);
printf("[mmc_init] Total clusters: %lu\r\n", mmc_info.total_clusters);
printf("[mmc_init] Total sector: %lu\r\n", (ULONG)mmc_info.total_sectors);
}
else
printf("[mmc_init] Error getting media info\r\n");
FILE_INFO file_info;
if (storage_mmc_first_file_info(&file_info) == FX_SUCCESS)
{
printf("[mmc_init] First: '%s' %ld bytes\r\n", file_info.name, file_info.size);
#if 0
while (storage_mmc_next_file_info(&file_info) == FX_SUCCESS)
{
printf("[mmc_init] Next: '%s' %ld bytes\r\n", file_info.name, file_info.size);
}
#endif
}
else
{
printf("[mmc_init] Error getting first file info or no files\r\n");
}
where:
ALIGN_32BYTES (uint32_t media_memory[FX_STM32_MMC_DEFAULT_SECTOR_SIZE / sizeof(uint32_t)]);
is a 512 bytes buffer.
So, it happens that the first call to osThreadNew() after this mmc_init function, regardless the recalled function, crashes in the CDAbtHandler function:
Its parameters are: LR= 0xcccd02B4 (useless?), FS = 5 = FSR_TRANSLATION_FAULT_FIRST.
If I comment out the storage_mmc_first_file_info(..) (only contains fx_directory_first_full_entry_find() function call) the firmware runs correctly.
The same if I call a read or write buffer from/to mmc memory.
My guess is that these functions perform a mmc access, using the related buffers, and something is wrong in there..
Note: the driver level function to read a block (fx_stm32_mmc_read_blocks) is implemented by a BSP_MMC_ReadBlocks() call instead of a BSP_MMC_ReadBlocks_DMA call).
ADDED
Moving the mmc_init call in a earlier time, I always have a crash on the osThreadNew call in the next function: this time the code is landing in CUndefHandler with parameters: opcode = 0xffffffff, state = 4, LR = 0xccccccd4.
Any idea?
Thanks!