adc: hacks to get it up and running for L4

This commit is contained in:
Karl Palsson 2016-03-30 17:24:12 +00:00
parent 96bbee9af9
commit bcdf3f8943
2 changed files with 15 additions and 3 deletions

View file

@ -39,7 +39,7 @@
#define SAMPLE_TIME_VREF SAMPLE_TIME_TEMP
#define SEPARATE_VREF 0
#elif defined(STM32L4)
#define SAMPLE_TIME_BASIC ADC_SMPR_SMP_47DOT5CYC
#define SAMPLE_TIME_BASIC ADC_SMPR_SMP_247DOT5CYC
#define SAMPLE_TIME_TEMP ADC_SMPR_SMP_247DOT5CYC
#define SAMPLE_TIME_VREF SAMPLE_TIME_TEMP
#else
@ -68,6 +68,11 @@ void adc_power_init(void)
ADC_CR(ADC1) &= ~ADC_CR_DEEPPWD;
RCC_CCIPR |= 3 << 28; // system clock as adc clock. (with CKMODE == 0)
adc_enable_regulator(ADC1);
ADC_CR(ADC1) &= ~ADC_CR_ADCALDIF;
ADC_CR(ADC1) |= ADC_CR_ADCAL;
while (ADC_CR(ADC1) & ADC_CR_ADCAL);
#else
rcc_periph_clock_enable(RCC_ADC1);
@ -137,7 +142,7 @@ void adc_power_task_up(void) {
* I mean, we're going to do some conversions right? */
adc_set_single_conversion_mode(ADC1);
TIM_CNT(TIMER) = 0;
unsigned int v1 = read_adc_naiive(1);
unsigned int v1 = read_adc_naiive(1); // 8 for l4!
unsigned int v5 = read_adc_naiive(5);
unsigned int temp_adc = read_adc_naiive(ADC_CHANNEL_TEMP);
unsigned int vref_adc = read_adc_naiive(ADC_CHANNEL_VREF);

View file

@ -45,9 +45,16 @@ int main(void)
LED_DISCO_RED_PIN);
/* ADC 1 channels 1 and 5 */
gpio_mode_setup(GPIOC, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO0);
// This is the reset state, so not really necessary.
gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO0);
gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO1);
gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO2);
gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO3);
gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO5);
// This is NOT the reset state! very important!
GPIO_ASCR(GPIOA) |= GPIO0 | GPIO1 | GPIO2 | GPIO3 | GPIO5;
adc_power_init();
while (1) {
adc_power_task_up();