Skip to content

Commit

Permalink
H7 Fix frozen ADC values (#12439)
Browse files Browse the repository at this point in the history
H7 ADC buffer invalidate cache
  • Loading branch information
klutvott123 committed Mar 3, 2023
1 parent ee77239 commit f59b7e7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/main/drivers/stm32/adc_stm32h7xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,12 @@ void adcInitCalibrationValues(void)
// Need this separate from the main adcValue[] array, because channels are numbered
// by ADC instance order that is different from ADC_xxx numbering.

static volatile DMA_RAM uint16_t adcConversionBuffer[ADC_CHANNEL_COUNT] __attribute__((aligned(32)));
#define ADC_BUF_LENGTH ADC_CHANNEL_COUNT
#define ADC_BUF_BYTES (ADC_BUF_LENGTH * sizeof(uint16_t))
#define ADC_BUF_CACHE_ALIGN_BYTES ((ADC_BUF_BYTES + 0x20) & ~0x1f)
#define ADC_BUF_CACHE_ALIGN_LENGTH (ADC_BUF_CACHE_ALIGN_BYTES / sizeof(uint16_t))

static volatile DMA_RAM uint16_t adcConversionBuffer[ADC_BUF_CACHE_ALIGN_LENGTH] __attribute__((aligned(32)));

void adcInit(const adcConfig_t *config)
{
Expand Down Expand Up @@ -535,8 +540,7 @@ void adcInit(const adcConfig_t *config)
void adcGetChannelValues(void)
{
// Transfer values in conversion buffer into adcValues[]
// Cache coherency should be maintained by MPU facility

SCB_InvalidateDCache_by_Addr((uint32_t*)adcConversionBuffer, ADC_BUF_CACHE_ALIGN_BYTES);
for (int i = 0; i < ADC_CHANNEL_INTERNAL_FIRST_ID; i++) {
if (adcOperatingConfig[i].enabled) {
adcValues[adcOperatingConfig[i].dmaIndex] = adcConversionBuffer[adcOperatingConfig[i].dmaIndex];
Expand Down

0 comments on commit f59b7e7

Please sign in to comment.