From 2cd7ecf437bec322e6a201992d0404f31207bd68 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 23 Jun 2020 16:22:21 -0700 Subject: [PATCH] altos/micropeak-v2.0: Finish hardware bring-up All of the hardware is working: * serial * SPI * ms56067 * ADC * flash * clocking * timer Now we just need an application Signed-off-by: Keith Packard --- src/micropeak-v2.0/Makefile | 17 ++++++++- src/micropeak-v2.0/ao_micro.c | 70 +++++++++++++++++++++++++++++++---- src/micropeak-v2.0/ao_pins.h | 7 +++- src/test/ao_micropeak_test.c | 6 +-- 4 files changed, 86 insertions(+), 14 deletions(-) diff --git a/src/micropeak-v2.0/Makefile b/src/micropeak-v2.0/Makefile index d6c8f8c3..350061a3 100644 --- a/src/micropeak-v2.0/Makefile +++ b/src/micropeak-v2.0/Makefile @@ -64,13 +64,26 @@ ALTOS_SRC = \ ao_notask.c \ ao_serial_stm.c \ ao_timer.c \ - ao_led.c + ao_spi_stm32l0.c \ + ao_adc_stm32l0.c \ + ao_ms5607.c \ + ao_exti_stm.c \ + ao_convert_pa.c \ + ao_led.c \ + ao_cmd.c \ + ao_product.c \ + ao_romconfig.c \ + ao_flash_stm32l0.c \ + ao_storage.c \ + ao_microflight.c \ + ao_log_micro.c \ + ao_microkalman.c IDPRODUCT=0x14 PRODUCT=MicroPeak-v2.0 PRODUCT_DEF=-DMICROPEAK -CFLAGS = $(PRODUCT_DEF) $(STML0_CFLAGS) +CFLAGS = $(PRODUCT_DEF) $(STML0_CFLAGS) -Wl,--gc-sections -ffunction-sections PROGNAME=micropeak-v2.0 PROG=$(PROGNAME)-$(VERSION).elf diff --git a/src/micropeak-v2.0/ao_micro.c b/src/micropeak-v2.0/ao_micro.c index ae5d96c3..26daa520 100644 --- a/src/micropeak-v2.0/ao_micro.c +++ b/src/micropeak-v2.0/ao_micro.c @@ -19,22 +19,76 @@ #include #include #include +#include + + +uint32_t pa; + +static void +ao_msi_init(void) +{ + uint32_t icscr = stm_rcc.icscr; + + /* Set MSI clock to desired range */ + icscr &= ~(STM_RCC_ICSCR_MSIRANGE_MASK << STM_RCC_ICSCR_MSIRANGE); + icscr |= (AO_MSI_RANGE << STM_RCC_ICSCR_MSIRANGE); + stm_rcc.icscr = icscr; + + /* Set vcore to 1.2V */ + uint32_t cr = stm_pwr.cr; + cr &= ~(STM_PWR_CR_VOS_MASK << STM_PWR_CR_VOS); + cr |= (STM_PWR_CR_VOS_1_2 << STM_PWR_CR_VOS); + stm_pwr.cr = cr; +} + +static void +list_flights(void) +{ + printf("flight %d start %x end %x\n", + 1, 0 >> 8, ao_storage_total >> 8); +} + +const struct ao_cmds ao_micro_cmds[] = { + { list_flights, "l\0List flights" }, + {} +}; + +void +ao_pa_get(void) +{ + static struct ao_ms5607_value value; + + ao_ms5607_sample(&ao_ms5607_current); + ao_ms5607_convert(&ao_ms5607_current, &value); + pa = value.pres; +} int main(void) { - ao_timer_init(); + ao_msi_init(); ao_led_init(); ao_led_on(AO_LED_ORANGE); - ao_serial_init(); + ao_timer_init(); + ao_spi_init(); + ao_ms5607_init(); + ao_ms5607_setup(); + ao_storage_init(); + + uint16_t vref = ao_adc_read_vref(); + + uint32_t vdda = 3 * stm_vrefint_cal.vrefint_cal * 1000 / vref; + ao_led_off(AO_LED_ORANGE); - for (;;) { - ao_led_on(AO_LED_ORANGE); - ao_delay(AO_MS_TO_TICKS(500)); - ao_led_off(AO_LED_ORANGE); - ao_delay(AO_MS_TO_TICKS(500)); - printf("hello, world\n"); + /* Power supply > 3.25V means we're on USB power */ + if (vdda > 3250) { + ao_serial_init(); + ao_cmd_init(); + ao_cmd_register(ao_micro_cmds); + ao_cmd(); + } else { + ao_microflight(); } } diff --git a/src/micropeak-v2.0/ao_pins.h b/src/micropeak-v2.0/ao_pins.h index 69e8eb64..bfccfa10 100644 --- a/src/micropeak-v2.0/ao_pins.h +++ b/src/micropeak-v2.0/ao_pins.h @@ -20,7 +20,10 @@ extern uint8_t ao_on_battery; -#define AO_SYSCLK STM_MSI_FREQ +#define HAS_TASK 0 + +#define AO_SYSCLK STM_MSI_FREQ_524288 +#define AO_MSI_RANGE STM_RCC_ICSCR_MSIRANGE_524288 #define LED_0_PORT (&stm_gpioa) #define LED_0_PIN 1 @@ -137,4 +140,6 @@ extern uint32_t __flash_end__[]; #define AO_BOOT_APPLICATION_BOUND ((uint32_t *) __flash__) #define USE_STORAGE_CONFIG 0 +#define HAS_STORAGE_DEBUG 1 + #endif /* _AO_PINS_H_ */ diff --git a/src/test/ao_micropeak_test.c b/src/test/ao_micropeak_test.c index 059c2284..952460d0 100644 --- a/src/test/ao_micropeak_test.c +++ b/src/test/ao_micropeak_test.c @@ -46,10 +46,10 @@ static void ao_led_on(uint8_t led) { static void ao_led_off(uint8_t led) { } -static void ao_delay_until(uint16_t target) { +static void ao_delay_until(AO_TICK_TYPE target) { } -static uint16_t ao_time(void) { +static AO_TICK_TYPE ao_time(void) { return 0; } @@ -57,7 +57,7 @@ static uint16_t ao_time(void) { #include "ao_microkalman.c" #include "ao_convert_pa.c" -uint16_t now; +AO_TICK_TYPE now; uint8_t running; void ao_log_micro_data() { -- 2.30.2