altos: Switch micropeak v2.0 to stm32l0
authorKeith Packard <keithp@keithp.com>
Sat, 20 Jun 2020 22:14:26 +0000 (15:14 -0700)
committerKeith Packard <keithp@keithp.com>
Sat, 8 Aug 2020 03:30:11 +0000 (20:30 -0700)
The stm32f042 takes too much power for micropeak. Try the stm32l0
instead.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/micropeak-v2.0/Makefile
src/micropeak-v2.0/ao_micro.c [new file with mode: 0644]
src/micropeak-v2.0/ao_micropeak.c
src/micropeak-v2.0/ao_pins.h
src/micropeak-v2.0/micropeak.ld

index 5949ec0963f63324a5c87f6d97bd3c931ff874e6..d6c8f8c398b7b1f9588268d272017cb1e668b0c7 100644 (file)
@@ -3,7 +3,7 @@
 #
 #
 
-include ../stmf0/Makefile.defs
+include ../stm32l0/Makefile.defs
 
 PUBLISH_DIR=$(HOME)/altusmetrumllc/Binaries
 PUBLISH_HEX=$(PUBLISH_DIR)/$(HEX)
@@ -14,7 +14,7 @@ MICRO_SRC=\
        ao_microflight.c \
        ao_microkalman.c
 
-ALTOS_SRC = \
+ALTOS_SRC_ = \
        ao_micropeak.c \
        ao_spi_stm.c \
        ao_dma_stm.c \
@@ -54,13 +54,23 @@ INC=\
        ao_micropeak.h \
        altitude-pa.h \
        ao_product.h \
-       stm32f0.h
+       stm32l0.h
+
+ALTOS_SRC = \
+       ao_interrupt.c \
+       ao_panic.c \
+       ao_micro.c \
+       ao_stdio.c \
+       ao_notask.c \
+       ao_serial_stm.c \
+       ao_timer.c \
+       ao_led.c
 
 IDPRODUCT=0x14
 PRODUCT=MicroPeak-v2.0
 PRODUCT_DEF=-DMICROPEAK
 
-CFLAGS = $(PRODUCT_DEF) $(STMF0_CFLAGS)
+CFLAGS = $(PRODUCT_DEF) $(STML0_CFLAGS)
 
 PROGNAME=micropeak-v2.0
 PROG=$(PROGNAME)-$(VERSION).elf
@@ -71,7 +81,7 @@ OBJ=$(SRC:.c=.o)
 
 all: $(PROG) $(HEX)
 
-LDFLAGS=-nostartfiles $(CFLAGS) -L$(TOPDIR)/stmf0 -Tmicropeak.ld -n
+LDFLAGS=-nostartfiles $(CFLAGS) -L$(TOPDIR)/stm32l0 -Taltos.ld -n
 
 $(PROG): Makefile $(OBJ) micropeak.ld
        $(call quiet,CC) $(LDFLAGS) -o $(PROG) $(OBJ) $(LIBS) -Wl,-Map=$(PROGNAME)-$(VERSION).map
diff --git a/src/micropeak-v2.0/ao_micro.c b/src/micropeak-v2.0/ao_micro.c
new file mode 100644 (file)
index 0000000..ae5d96c
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright © 2020 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+#include <ao.h>
+#include <ao_exti.h>
+#include <ao_micropeak.h>
+
+int
+main(void)
+{
+       ao_timer_init();
+
+       ao_led_init();
+       ao_led_on(AO_LED_ORANGE);
+
+       ao_serial_init();
+
+       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");
+       }
+}
index a4de48543a70d2cbf24dbad2f184fd73f2cc4870..c6c1e221880c0fc38e158e15dbcb4b36bb66ed5a 100644 (file)
@@ -56,7 +56,7 @@ ao_pips(void)
 }
 
 void
-ao_delay_until(uint16_t target) {
+ao_delay_until(AO_TICK_TYPE target) {
        int16_t delay = target - ao_time();
        if (delay > 0) {
                ao_sleep_for(ao_delay_until, delay);
@@ -145,10 +145,10 @@ ao_battery_fini(void)
        stm_rcc.apb2enr &= ~(1 << STM_RCC_APB2ENR_ADCEN);
 }
 
-static uint16_t
+static AO_TICK_TYPE
 ao_battery_voltage(void)
 {
-       uint16_t        vrefint;
+       AO_TICK_TYPE    vrefint;
 
        ao_battery_init();
 
@@ -212,7 +212,7 @@ ao_show_bat(void)
 uint8_t
 ao_log_present(void)
 {
-       uint16_t        n_samples;
+       AO_TICK_TYPE    n_samples;
 
        ao_eeprom_read(N_SAMPLES_OFFSET, &n_samples, sizeof (n_samples));
 
index d3bd22814a46f0264669237de7c06bf2beb87efb..69e8eb64bd4fc6f135aa1aee901016ba5bd5a0f0 100644 (file)
 
 extern uint8_t ao_on_battery;
 
-#define AO_SYSCLK      (ao_on_battery ? STM_HSI_FREQ : 48000000)
+#define AO_SYSCLK      STM_MSI_FREQ
 
-#define LED_PORT_ENABLE        STM_RCC_AHBENR_IOPAEN
-#define LED_PORT       (&stm_gpioa)
-#define LED_PIN_ORANGE 2
-#define AO_LED_ORANGE  (1 << LED_PIN_ORANGE)
+#define LED_0_PORT     (&stm_gpioa)
+#define LED_0_PIN      1
+#define AO_LED_ORANGE  (1 << 0)
 #define AO_LED_REPORT  AO_LED_ORANGE
 #define AO_LED_PANIC   AO_LED_ORANGE
 
@@ -33,32 +32,22 @@ extern uint8_t ao_on_battery;
 
 #define AO_POWER_MANAGEMENT    0
 
-/* 48MHz clock based on USB */
-#define AO_HSI48       1
-/* Need HSI running to flash */
-#define AO_NEED_HSI    1
+/* HCLK = MSI (2.097MHz) */
+#define AO_AHB_PRESCALER       (1)
+#define AO_RCC_CFGR_HPRE_DIV   (STM_RCC_CFGR_HPRE_DIV_1)
 
-/* HCLK = 12MHz usb / 2MHz battery */
-#define AO_AHB_PRESCALER       (ao_on_battery ? 16 : 1)
-#define AO_RCC_CFGR_HPRE_DIV   (ao_on_battery ? STM_RCC_CFGR_HPRE_DIV_16 : STM_RCC_CFGR_HPRE_DIV_1)
-
-/* APB = 12MHz usb / 2MHz battery */
-#define AO_APB_PRESCALER       (ao_on_battery ? 2 : 1)
-#define AO_RCC_CFGR_PPRE_DIV   (ao_on_battery ? STM_RCC_CFGR_PPRE_DIV_2 : STM_RCC_CFGR_PPRE_DIV_1)
-
-#define HAS_USB                        1
-#define AO_PA11_PA12_RMP       1
+/* APB = MSI */
+#define AO_APB1_PRESCALER      (1)
+#define AO_APB2_PRESCALER      (1)
+#define AO_RCC_CFGR_PPRE_DIV   (STM_RCC_CFGR_PPRE_DIV_1)
 
 #define PACKET_HAS_SLAVE       0
 #define HAS_SERIAL_1           0
 #define HAS_SERIAL_2           1
-#define USE_SERIAL_2_STDIN     0
+#define USE_SERIAL_2_STDIN     1
 #define USE_SERIAL_2_FLOW      0
 #define USE_SERIAL_2_SW_FLOW   0
-#define SERIAL_2_PA2_PA3       1
-#define SERIAL_2_PA14_PA15     0
-#define USE_SERIAL2_FLOW       0
-#define USE_SERIAL2_SW_FLOW    0
+#define SERIAL_2_PA9_PA10      1
 
 #define IS_FLASH_LOADER                0
 
@@ -109,9 +98,8 @@ typedef int32_t alt_t;
 
 #define AO_ALT_VALUE(x)                ((x) * (alt_t) 10)
 
-#define AO_DATA_RING           32
-
 #define HAS_ADC                        0
+#define HAS_AO_DELAY           1
 
 static inline void
 ao_power_off(void) __attribute((noreturn));
@@ -124,8 +112,6 @@ ao_power_off(void) {
 
 extern alt_t ao_max_height;
 
-void ao_delay_until(uint16_t target);
-
 #define ao_async_stop() do {                                   \
                ao_serial2_drain();                             \
                stm_moder_set(&stm_gpioa, 2, STM_MODER_OUTPUT); \
index b4e06a877708bd7cbdbe446b4262a5b1d5265856..93536c48967bb37aea03c89201c791f08c59e62f 100644 (file)
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-__flash = 0x08001000;
-__flash_size = 22K;
+__flash = 0x08000000;
+__flash_size = 10K;
 __flash__ = __flash + __flash_size;
 __flash_end__ = __flash__ + 6K;
 __ram = 0x20000000;
-__ram_size = 6K;
+__ram_size = 2K;
 __stack_size = 512;
 
-INCLUDE registers.ld
 INCLUDE picolibc.ld