altos/micropeak-v2.0: Finish hardware bring-up
authorKeith Packard <keithp@keithp.com>
Tue, 23 Jun 2020 23:22:21 +0000 (16:22 -0700)
committerKeith Packard <keithp@keithp.com>
Sat, 8 Aug 2020 03:30:11 +0000 (20:30 -0700)
All of the hardware is working:

 * serial
 * SPI
 * ms56067
 * ADC
 * flash
 * clocking
 * timer

Now we just need an application

Signed-off-by: Keith Packard <keithp@keithp.com>
src/micropeak-v2.0/Makefile
src/micropeak-v2.0/ao_micro.c
src/micropeak-v2.0/ao_pins.h
src/test/ao_micropeak_test.c

index d6c8f8c398b7b1f9588268d272017cb1e668b0c7..350061a3e92b08f92ace0cd9328431861083d513 100644 (file)
@@ -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
index ae5d96c38ba4cc8ad1343a04ee66f6dc4af6e1ba..26daa5209936b6941c7ab980548bfa58bed9547e 100644 (file)
 #include <ao.h>
 #include <ao_exti.h>
 #include <ao_micropeak.h>
+#include <ao_adc_stm32l0.h>
+
+
+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();
        }
 }
index 69e8eb64bd4fc6f135aa1aee901016ba5bd5a0f0..bfccfa10f45b09c9c0543d8907114a72791310b0 100644 (file)
 
 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_ */
index 059c22843d2fd138c1a668b5196c1ff14204b811..952460d0c2831c2daf12808037ffa947ee019171 100644 (file)
@@ -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() {