2020-09-23 01:22 AM
For my master thesis I am trying to receive data over DCMI with the STM32H742. As an image sensor I am using the NOIV2SN1300A. It sends data over 10 data lines, this data differs (so not always `0xA603A603`). To reduce data size I have activated binning and subsampling.
I am using DMA to transfer the data received by DCMI into the internal SRAM at address `0x24000000`. After I receive the whole data, so the whole datalength which i set (of `0xA603A603` data), the uC goes into hard fault and infinite loop. I am not sure why this error occurs. Here is my config for DMA and DCMI:
```
hdcmi.Instance = DCMI;
hdcmi.Init.SynchroMode = DCMI_SYNCHRO_HARDWARE;
hdcmi.Init.PCKPolarity = DCMI_PCKPOLARITY_RISING;
hdcmi.Init.VSPolarity = DCMI_VSPOLARITY_HIGH;
hdcmi.Init.HSPolarity = DCMI_HSPOLARITY_HIGH;
hdcmi.Init.CaptureRate = DCMI_CR_ALL_FRAME;
hdcmi.Init.ExtendedDataMode = DCMI_EXTEND_DATA_10B;
hdcmi.Init.JPEGMode = DCMI_JPEG_DISABLE;
hdcmi.Init.ByteSelectMode = DCMI_BSM_ALL;
hdcmi.Init.ByteSelectStart = DCMI_OEBS_ODD;
hdcmi.Init.LineSelectMode = DCMI_LSM_ALL;
hdcmi.Init.LineSelectStart = DCMI_OELS_ODD;
if (HAL_DCMI_Init(&hdcmi) != HAL_OK)
{
Error_Handler();
}
/*
* Enable all interrupts for DCMI
*/
HAL_NVIC_SetPriority(DCMI_IT_OVR, 1, 0);
HAL_NVIC_EnableIRQ(DCMI_IT_OVR);
HAL_NVIC_SetPriority(DCMI_IT_VSYNC, 1, 0);
HAL_NVIC_EnableIRQ(DCMI_IT_VSYNC);
HAL_NVIC_SetPriority(DCMI_IT_LINE, 1, 0);
HAL_NVIC_EnableIRQ(DCMI_IT_LINE);
HAL_NVIC_SetPriority(DCMI_IT_FRAME, 1, 0);
HAL_NVIC_EnableIRQ(DCMI_IT_FRAME);
HAL_NVIC_SetPriority(DCMI_IRQn, 1, 0);
HAL_NVIC_EnableIRQ(DCMI_IRQn);
/*
* Enable interrupt for DMA1_Stream0
*/
HAL_NVIC_SetPriority(DMA1_Stream0_IRQn, 1, 0);
HAL_NVIC_EnableIRQ(DMA1_Stream0_IRQn);
```
```
hdcmi.Instance = DCMI;
hdcmi.Init.SynchroMode = DCMI_SYNCHRO_HARDWARE;
hdcmi.Init.PCKPolarity = DCMI_PCKPOLARITY_FALLING; //Todo:???
hdcmi.Init.VSPolarity = DCMI_VSPOLARITY_HIGH;
hdcmi.Init.HSPolarity = DCMI_HSPOLARITY_HIGH;
hdcmi.Init.CaptureRate = DCMI_CR_ALL_FRAME;
hdcmi.Init.ExtendedDataMode = DCMI_EXTEND_DATA_10B;
hdcmi.Init.JPEGMode = DCMI_JPEG_DISABLE;
hdcmi.Init.ByteSelectMode = DCMI_BSM_OTHER;//DCMI_BSM_ALL;
hdcmi.Init.ByteSelectStart = DCMI_OEBS_ODD;
hdcmi.Init.LineSelectMode = DCMI_LSM_ALL;
hdcmi.Init.LineSelectStart = DCMI_OELS_ODD;
if (HAL_DCMI_Init(&hdcmi) != HAL_OK)
{
Error_Handler();
}
```
```
uint32_t DataSizeImageSensor = 0xB160;
```
```
DMA_BUFFER uint32_t AddressFrameBuffer[0x1620C];
```
```
HAL_DCMI_Start_DMA(&hdcmi, DCMI_MODE_SNAPSHOT, (uint32_t)AddressFrameBuffer, DataSizeImageSensor);
```
```
void MPU_Config (void)
{
MPU_Region_InitTypeDef MPU_InitStruct;
/* Disable the MPU */
HAL_MPU_Disable();
/* Configure the MPU attributes for SDRAM */
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
MPU_InitStruct.BaseAddress = 0x24000000;
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_NOT_CACHEABLE; //Cache is incoherent with CPU for DMA usage
MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
MPU_InitStruct.Number = MPU_REGION_NUMBER0;
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL1;
MPU_InitStruct.SubRegionDisable = 0x00;
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_DISABLE;
HAL_MPU_ConfigRegion(&MPU_InitStruct);
/* Enable the MPU */
HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
}
```
Any idea why this error occurs? Like I said, I receive data, I am sure the sensor sends viable data (so something else then `0xA603A603`), but I get only the same data by DCMI before hard fault. At this current setup I receive all the data and the data is in the buffer as expected. But directly after the last write in the buffer, the hard fault occurs.
Furthermore I disabled the cache for the SRAM1, as there are problems regarding cache/DMA/CPU coherence. I am not quite sure how to proceed, as it looks to me like it is a setup error. Maybe an overrun by DCMI?
Note: The code above doesn't actually occur in this order. That are just the relevant parts (at least from what I expect to be relevant).
I found other posts about this problem, where the error was a slow system clock. As my system clock is 475 MHz and the HCLK3 Clock (which is used by DCMI for sampling) is 237.5 MHz I can rule out a Clock problem. The datasheet says the HCLK Clock has to be 2.5 times faster then DCMI Clock (which is set by the image sensor with 62 Mhz).
Furthermore I implemented a Hard Fault Handler which gives more information about the error. Following this https://blog.frankvh.com/2011/12/07/cortex-m3-m4-hard-fault-handler/. The Problem is, none of the registers are set (so no BusFault register or something like that). Also the Fault Analyzer of the STMCubeIDE says no fault was detected.
Also, none of my interrupts for DCMI or DMA are called. At least none of my breakpoints is being entered there. Which is kinda strange for me.
Solved! Go to Solution.
2020-09-24 02:13 AM
Found the solution. It was an interrupt which I activated for the DCMI, but the interrupt is not allowed for the mode, in which I used the DCMI
2020-09-23 06:32 AM
So it hard faults yet none of the hard fault registers are populated? What IRQ does it think it's in (ICSR_VECTACTIVE)?
2020-09-24 02:13 AM
Found the solution. It was an interrupt which I activated for the DCMI, but the interrupt is not allowed for the mode, in which I used the DCMI