ADC with DMA on the STM32F769I Discovery
Hello guys,
I want to share my experience with using HAL Examples (STM32CubeF7 Firmware Package). I have STM32F769I Discovery board
In my program I needed UART and ADC. I implemented UART6 in interrupt mode (Rx, Tx). After many problems with receiving variable length data it was settled. Then I wanted to use analog to digital conversion of one channel on one analog pin. I used ADC1, ADC_CHANNEL_6, ADC_SAMPLETIME_56CYCLES, continous conversion mode. MCU is on max. frequency 216 MHz, ADC has PRESCALER_PCLK_DIV8.
For ADC I was inspired with example project file ADC_TemperatureSensor, it uses DMA2_Stream0, DMA_CHANNEL_0, circular mode. Interruption is done with DMA2_Stream0_IRQn. (I found that this example program does not crash when I remove MPU_Config().)
I copied configuration of the ADC (changed channel and little things) and add it to my program with the UART communication. First I started without MPU_Config(); and CPU_CACHE_Enable(); and after build and run, it ended in the HardFault (HardFault_Handler). It crashed during conversion process HAL_ADC_Start_DMA(&AdcHandle, (uint32_t*)&ConvertedValue, 1); I was not able to find the cause for a couple of days. AN4031 (about DMA) did not help me. After a lot of searching I found AN4667. Part of the setting of the MPU (default) was
MPU_InitStruct.BaseAddress = 0x20010000;
MPU_InitStruct.Size = MPU_REGION_SIZE_256KB;
According to AN4667 (later I found it also in the reference manual RM0410, first it was not so obvious) I found the base address for the MPU is maybe wrong. I changed the address to
MPU_InitStruct.BaseAddress = 0x20020000;
and now the program is running. For the STM32F76xxx/STM32F77xxx DTCM is from 0x2000 0000 to 0x2001 FFFF and SRAM1 is from 0x20020000 to 0x2007 BFFF.
Still I don’t understand when it is needed to use CPU_CACHE_Enable() or MPU_Config(). I read MPU should be used when 2 masters can be in the conflict on the bus or in the RAM. Can someone explain to me why I need to use MPU and use it for SRAM1 region for example?
vt23