2025-12-12 9:28 PM
Hey Folks,
Description:
I am using STM32N6570-DK with Azure RTOS (ThreadX + FileX) to store camera frames on an SD card using SDMMC2.
Use case:
Capture camera frames (RGB565, 320×240) using DCMIPP
Display frames via LTDC
Continuously write frames to SD card using fx_file_write()
Issue:
Small file read/write (text file) works correctly.
When continuously writing video frames (~153 KB per frame), FileX fails after 2–3 frames.
FileX returns FX_IO_ERROR (144).
Failure occurs during media flush / directory update, not directly in application code.
Configuration:
From fx_stm32_sd_driver.h:
#define FX_STM32_SD_DMA_API 1
#define FX_STM32_SD_CACHE_MAINTENANCE 0
#define FX_STM32_SD_MAX_TRANSFER_SECTOR 16
#define FX_STM32_SD_DEFAULT_SECTOR_SIZE 512
FX_STM32_SD_WRITE_CPLT_NOTIFY() waits on a ThreadX semaphore.
SDMMC2 interrupt enabled.
GPDMA interrupts currently not enabled.
NVIC priority for SDMMC2 was initially 0
Additional Observations:
Indicates possible DMA/cache/interrupt contention between:
SDMMC2
Camera (DCMIPP)
LTDC
Questions:
For STM32N6 + FileX + SDMMC2, when FX_STM32_SD_DMA_API = 1:
Is GPDMA mandatory?
Which GPDMA IRQs must be enabled?
If SD driver uses polling or IT mode, should FileX still wait on a semaphore in
FX_STM32_SD_WRITE_CPLT_NOTIFY()?
Is there a recommended maximum sector count per SD write for STM32N6?
Are there recommended NVIC priorities for:
GPDMA
DCMIPP / LTDC
when using ThreadX + FileX?
Is there any reference design for high-throughput SD writes (video logging) on STM32N6?
NOTE: Any Assistance will be appreciable.....
Thankyou.
Best Regards,
Aashritha
2026-01-02 12:46 AM
Hello @Aashritha_Vuda ,
Is GPDMA mandatory when FX_STM32_SD_DMA_API = 1?
Not necessarily. The STM32N6 example uses HAL_SD_WriteBlocks_DMA() without enabling any GPDMA IRQ in the MSP, and completion is signalled via SDMMC2_IRQn. So on N6, the SD DMA mode can work through the SDMMC’s own DMA/IDMA mechanism (depending on the CubeMX configuration) with SDMMC2_IRQn only.
However, if your CubeMX configuration routes SDMMC2 through GPDMA channels, then yes: you must enable the IRQs for the corresponding GPDMA RX/TX channels; otherwise, the semaphore will never be given.
Which IRQs should be enabled?
If the driver is in polling/IT mode, should FX_STM32_SD_WRITE_CPLT_NOTIFY() wait on a semaphore?
Recommended maximum transfer size (number of sectors)
16 sectors (8 KB) is conservative. For sequential logging, 32 or 64 sectors can improve throughput, provided you do not hit timeouts and your buffers are DMA-safe (alignment + cache constraints). In practice, the main limitations come from:
Recommended NVIC priorities (SDMMC / DMA / DCMIPP / LTDC)
In the example, SDMMC2_IRQn is set to priority 5 (and SD_DETECT EXTI to 14). The practical guidelines are:
A reasonable starting point is:
Reference design for “high throughput video logging”
The ST example does not implement video streaming, but it demonstrates the correct building blocks for N6: DMA + semaphore + SDMMC2 IRQ + MPU (non-cacheable) / or proper cache maintenance.
GitHub reference:
STM32CubeN6/Projects/STM32N6570-DK/Applications/FileX/Fx_uSD_File_Edit at main · STMicroelectronics/STM32CubeN6
Regards,
Maher