2025-10-09 6:09 AM
Hello ST Community!
I've been trying to recreate the DCMIPP_ContinuousMode example with STM32CubeIDE, but have been running into some issues with the IMX335_Probe function, the ID read by the I2C bus never matches the expected define IMX335_CHIP_ID. The original example runs completely fine in the STM32N6570-DK.
- AXISRAM3 (0x34200000) is being used as the address for the DCMIPP CSI Pipe.
- ISP Middleware does not return any errors in initialization.
- All files regarding IMX335 registers and functions match with the original examples. Same for all the BSP drivers.
- RIF has been configured for all peripherals involved.
- AXISRAM3 has been enabled in the CubeMX configurations, and it's clock has also been enabled.
static void IMX335_Probe(uint32_t Resolution, uint32_t PixelFormat)
{
IMX335_IO_t IOCtx;
uint32_t id;
/* Configure the camera driver */
IOCtx.Address = CAMERA_IMX335_ADDRESS;
IOCtx.Init = BSP_I2C1_Init;
IOCtx.DeInit = BSP_I2C1_DeInit;
IOCtx.ReadReg = BSP_I2C1_ReadReg16;
IOCtx.WriteReg = BSP_I2C1_WriteReg16;
IOCtx.GetTick = BSP_GetTick;
if (IMX335_RegisterBusIO(&IMX335Obj, &IOCtx) != IMX335_OK)
{
Error_Handler();
}
else if (IMX335_ReadID(&IMX335Obj, &id) != IMX335_OK)
{
Error_Handler();
}
else
{
if (id != (uint32_t) IMX335_CHIP_ID)
{
Error_Handler();
}
else
{
if (IMX335_Init(&IMX335Obj, Resolution, PixelFormat) != IMX335_OK)
{
Error_Handler();
}
else if(IMX335_SetFrequency(&IMX335Obj, IMX335_INCK_24MHZ)!= IMX335_OK)
{
Error_Handler();
}
else
{
return;
}
}
}
}
In debug, the execution runs as follows:
IOCtx.Address = CAMERA_IMX335_ADDRESS;
IOCtx.Init = BSP_I2C1_Init;
IOCtx.DeInit = BSP_I2C1_DeInit;
IOCtx.ReadReg = BSP_I2C1_ReadReg16;
IOCtx.WriteReg = BSP_I2C1_WriteReg16;
IOCtx.GetTick = BSP_GetTick;
The IMX335_IO_t temporary variable for the IMX335Obj records the addresses of all the BSP functions correctly, confirmed by running a dissasembly.
if (IMX335_RegisterBusIO(&IMX335Obj, &IOCtx) != IMX335_OK)
{
Error_Handler();
}
IMX335_RegisterBusIO records the correct addresses into the IMX335Obj from the temporary IMX335_IO_t variable, and BSP_I2C1_Init does not return any errors.
else if (IMX335_ReadID(&IMX335Obj, &id) != IMX335_OK)
{
Error_Handler();
}
Now here is where the main issue occurs, again, the pointer in the IMX335Obj is used to initialize I2C, which does not return any errors.
imx335_read_reg(&pObj->Ctx, IMX335_REG_ID, &tmp, 1)
The read register function is then called, which is actually just a wrapper with a return that points to another function.
static int32_t IMX335_ReadRegWrap(void *handle, uint16_t Reg, uint8_t* pData, uint16_t Length)
{
IMX335_Object_t *pObj = (IMX335_Object_t *)handle;
return pObj->IO.ReadReg(pObj->IO.Address, Reg, pData, Length);
}
Finally, the return of IMX335_ReadRegWrap calls a BSP Wrapper of I2C functions:
int32_t BSP_I2C1_ReadReg16(uint16_t DevAddr, uint16_t Reg, uint8_t *pData, uint16_t Length)
{
int32_t ret;
#if defined(BSP_USE_CMSIS_OS)
/* Get semaphore to prevent multiple I2C access */
osSemaphoreWait(BspI2cSemaphore, osWaitForever);
#endif /* BSP_USE_CMSIS_OS */
if (I2C1_ReadReg(DevAddr, Reg, I2C_MEMADD_SIZE_16BIT, pData, Length) == 0)
{
ret = BSP_ERROR_NONE;
}
else
{
if (HAL_I2C_GetError(&hbus_i2c1) == HAL_I2C_ERROR_AF)
{
ret = BSP_ERROR_BUS_ACKNOWLEDGE_FAILURE;
}
else
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
}
#if defined(BSP_USE_CMSIS_OS)
/* Release semaphore to prevent multiple I2C access */
osSemaphoreRelease(BspI2cSemaphore);
#endif /* BSP_USE_CMSIS_OS */
return ret;
}
No error is returned in the HAL_I2C_Mem_Read which is called by I2C1_ReadReg, and the recieved value is '3' instead of 0, making the decimal equivalent of the ID 51 instead of 0.
That said, I could just force the ReadID to be 0, but obviously that would just result in the camera not working.
Is there another parameter related to security I should worry about when using the I2C apart from the RIF? All of the registers and values returned point to this being a security related issue, but at this point I don't know what else to enable.
If anyone has been able to recreate the example in a STM32CubeIDE enviroment I would be grateful if you could share with me your project.