2025-08-07 2:53 AM - edited 2025-08-08 6:37 AM
Hi,
I’ve been struggling to get an image from an image sensor using DCMI via GPDMA on an STM32U595.
The sensor outputs a 1280x800 image in 12-bit RGGB Bayer format, which I’ve configured correctly. That gives 12 bits per pixel, and I want to capture the full frame at that resolution.
DCIMI interface :
DCMI_PIXCLK is 64MHz.
12 bit data (D0-11) and DCMI_HSYNC and DCMI_VSYNC
I've used the AN5020 as a reference for setting up the code, configured I2C communication, DCMI in slave 12-bit external sync mode, and set the DCMI polarities to match the sensor's output. I’ve also verified that VSYNC and HSYNC polarities are correct based on the sensor’s datasheet (AR0144CS).
When I capture an image without accessing any other peripherals like USB (USB_OTG_HS) or GPIO ports (Port B, D, E), it works fine. No DCMI or DMA overrun errors occur, and the buffer gets filled correctly with 1,024,000 bytes (1280x800x2).
However, the moment I access USB or any of the GPIOs, I start seeing DCMI/DMA overrun errors, no more HAL_DCMI_FRAME_EVENT not data.
I suspect the issue might be due to AHB2 bus contention, since DCMI, USB, and GPIOs all sit on the AHB2 bus?
I checked with an oscilloscope—VSYNC, HSYNC, and data lines all look fine, so the signal itself seems okay.
I’ve attached the .ioc file I used to generate the code.
For context, I'm using ThreadX RTOS along with USBX, FileX, and TouchGFX (though I haven’t used TouchGFX in code yet). In main.c, I’m calling:
#define FRAME_BUFFER_SIZE ((1280*800)>>1))
uint32_t frame[FRAME_BUFFER_SIZE];//global
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_GPDMA1_Init();
MX_DCMI_Init();
MX_FDCAN1_Init();
MX_FMC_Init();
MX_SPI1_Init();
MX_SPI2_Init();
MX_I2C2_Init();
MX_TIM1_Init();
MX_TIM2_Init();
MX_TIM3_Init();
MX_TIM5_Init();
MX_ICACHE_Init();
MX_CRC_Init();
MX_FLASH_Init();
MX_DMA2D_Init();
/* Call PreOsInit function */
MX_TouchGFX_PreOSInit();
/* USER CODE BEGIN 2 */
MX_USB_OTG_HS_HCD_Init();
HAL_DCMI_RegisterCallback(&hdcmi,HAL_DCMI_FRAME_EVENT_CB_ID, CMOS_FrameOkCallabck);
HAL_DCMI_RegisterCallback(&hdcmi, HAL_DCMI_ERROR_CB_ID,CMOS_FrameErrorCallback);
CMOS_sensor_init();//inittialize CMOS sensor over I2C
HAL_DCMI_Start_DMA(&hdcmi, DCMI_MODE_CONTINUOUS,&frame[0], (1280 * 800 *2 )/4);
/* USER CODE END 2 */
MX_ThreadX_Init();
/* We should never get here as control is now taken by the scheduler */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
Outside of this I have 2 other threads runnnig
1. Read GPIO buttons and then triggering USB write event.
2. USB thread to manage the USBx event and writing image to USB device where i check if USB drive is inserted if yes, access frame buffer and write image data to USB drive.
USB_OTG interrupt enabled, which handeld by USBx.
2025-08-15 6:26 AM - edited 2025-08-27 8:18 AM
Hello @KKato.2 ,
Are you using the latest STM32CubeU5 version?
Could you please try to use "1" for DCMI interrupt priority and let me know if the issue is solved or not?
Thanks and best regards,
Kaouthar
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.