Skip to content

Commit

Permalink
Merge pull request #20360 from maribu/stm32-adc-typo
Browse files Browse the repository at this point in the history
cpu/stm32/periph_adc: fix register access
  • Loading branch information
maribu authored Feb 8, 2024
2 parents c0f233d + 4ed287c commit e191fe2
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions cpu/stm32/periph/adc_f4_f7.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
*/

#include "cpu.h"
#include "irq.h"
#include "mutex.h"
#include "periph/adc.h"
#include "periph_conf.h"
#include "periph/vbat.h"
#include "periph_conf.h"

/**
* @brief Maximum allowed ADC clock speed
Expand Down Expand Up @@ -100,14 +101,20 @@ int adc_init(adc_t line)
}
ADC->CCR = ((clk_div / 2) - 1) << 16;
/* set sampling time to the maximum */
unsigned irq_state = irq_disable();
if (adc_config[line].chan >= 10) {
dev(line)->SMPR1 &= ~(MAX_ADC_SMP << (3 * (adc_config[line].chan - 10)));
dev(line)->SMPR1 |= MAX_ADC_SMP << (3 * (adc_config[line].chan - 10));
uint32_t smpr1 = dev(line)->SMPR1;
smpr1 &= ~(MAX_ADC_SMP << (3 * (adc_config[line].chan - 10)));
smpr1 |= MAX_ADC_SMP << (3 * (adc_config[line].chan - 10));
dev(line)->SMPR1 = smpr1;
}
else {
dev(line)->SMPR1 &= ~(MAX_ADC_SMP << (3 * adc_config[line].chan));
dev(line)->SMPR2 |= MAX_ADC_SMP << (3 * adc_config[line].chan);
uint32_t smpr2 = dev(line)->SMPR2;
smpr2 &= ~(MAX_ADC_SMP << (3 * adc_config[line].chan));
smpr2 |= MAX_ADC_SMP << (3 * adc_config[line].chan);
dev(line)->SMPR2 = smpr2;
}
irq_restore(irq_state);
/* free the device again */
done(line);
return 0;
Expand Down

0 comments on commit e191fe2

Please sign in to comment.