attempt actual adc on l4

(insufficient,needs clocks yet)
This commit is contained in:
Karl Palsson 2016-03-04 00:40:08 +00:00
parent 2a05ac3942
commit f4ebd4a603
3 changed files with 23 additions and 5 deletions

View file

@ -6,9 +6,8 @@ BUILD_DIR = bin-$(BOARD)
SHARED_DIR = ../../shared
CFILES = main-$(BOARD).c
# hah, not yet!
#CFILES += adc-power.c
#CFILES += trace.c trace_stdio.c
CFILES += adc-power.c
CFILES += trace.c trace_stdio.c
VPATH += $(SHARED_DIR)

View file

@ -62,6 +62,12 @@ void adc_power_init(void)
rcc_periph_clock_enable(RCC_ADC12);
rcc_adc_prescale(RCC_CFGR2_ADCxPRES_PLL_CLK_DIV_1, RCC_CFGR2_ADCxPRES_PLL_CLK_DIV_1);
adc_enable_regulator(ADC1);
#elif defined (STM32L4)
/* same same but different */
rcc_periph_clock_enable(RCC_ADC1);
ADC_CR(ADC1) &= ~ADC_CR_DEEPPWD;
adc_enable_regulator(ADC1);
#else
rcc_periph_clock_enable(RCC_ADC1);
#if 0

View file

@ -10,6 +10,9 @@
#include <libopencm3/stm32/gpio.h>
#include <libopencm3/stm32/rcc.h>
#include "trace.h"
#include "adc-power.h"
#define LED_DISCO_RED_PORT GPIOB
#define LED_DISCO_RED_PIN GPIO2
#define LED_DISCO_GREEN_PORT GPIOE
@ -20,20 +23,30 @@ int main(void)
{
int i;
int j = 0;
rcc_periph_clock_enable(RCC_GPIOB);
rcc_periph_clock_enable(RCC_GPIOE);
rcc_periph_clock_enable(RCC_GPIOB); // led
rcc_periph_clock_enable(RCC_GPIOE); // led
rcc_periph_clock_enable(RCC_GPIOA); // adcs
rcc_periph_clock_enable(RCC_GPIOC); // adcs
printf("hi guys!\n");
/* green led for ticking */
gpio_mode_setup(LED_DISCO_GREEN_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE,
LED_DISCO_GREEN_PIN);
gpio_mode_setup(LED_DISCO_RED_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE,
LED_DISCO_RED_PIN);
/* ADC 1 channels 1 and 5 */
gpio_mode_setup(GPIOC, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO0);
gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO5);
adc_power_init();
while (1) {
adc_power_task_up();
gpio_toggle(LED_DISCO_GREEN_PORT, LED_DISCO_GREEN_PIN);
for (i = 0; i < 0x10000; i++) { /* Wait a bit. */
__asm__("NOP");
}
adc_power_task_down();
gpio_toggle(LED_DISCO_RED_PORT, LED_DISCO_RED_PIN);
for (i = 0; i < 0x10000; i++) { /* Wait a bit. */
__asm__("NOP");