From eea198932b8f12d4729f6138a40489d954d6f93a Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 20 Jun 2020 15:14:26 -0700 Subject: [PATCH] altos: Switch micropeak v2.0 to stm32l0 The stm32f042 takes too much power for micropeak. Try the stm32l0 instead. Signed-off-by: Keith Packard --- src/micropeak-v2.0/Makefile | 20 +++++++++++---- src/micropeak-v2.0/ao_micro.c | 40 +++++++++++++++++++++++++++++ src/micropeak-v2.0/ao_micropeak.c | 8 +++--- src/micropeak-v2.0/ao_pins.h | 42 +++++++++++-------------------- src/micropeak-v2.0/micropeak.ld | 7 +++--- 5 files changed, 76 insertions(+), 41 deletions(-) create mode 100644 src/micropeak-v2.0/ao_micro.c diff --git a/src/micropeak-v2.0/Makefile b/src/micropeak-v2.0/Makefile index 5949ec09..d6c8f8c3 100644 --- a/src/micropeak-v2.0/Makefile +++ b/src/micropeak-v2.0/Makefile @@ -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 index 00000000..ae5d96c3 --- /dev/null +++ b/src/micropeak-v2.0/ao_micro.c @@ -0,0 +1,40 @@ +/* + * Copyright © 2020 Keith Packard + * + * 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 +#include +#include + +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"); + } +} diff --git a/src/micropeak-v2.0/ao_micropeak.c b/src/micropeak-v2.0/ao_micropeak.c index a4de4854..c6c1e221 100644 --- a/src/micropeak-v2.0/ao_micropeak.c +++ b/src/micropeak-v2.0/ao_micropeak.c @@ -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)); diff --git a/src/micropeak-v2.0/ao_pins.h b/src/micropeak-v2.0/ao_pins.h index d3bd2281..69e8eb64 100644 --- a/src/micropeak-v2.0/ao_pins.h +++ b/src/micropeak-v2.0/ao_pins.h @@ -20,12 +20,11 @@ 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); \ diff --git a/src/micropeak-v2.0/micropeak.ld b/src/micropeak-v2.0/micropeak.ld index b4e06a87..93536c48 100644 --- a/src/micropeak-v2.0/micropeak.ld +++ b/src/micropeak-v2.0/micropeak.ld @@ -16,13 +16,12 @@ * 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 -- 2.30.2