summaryrefslogtreecommitdiff
path: root/src/stm
diff options
context:
space:
mode:
Diffstat (limited to 'src/stm')
-rw-r--r--src/stm/Makefile-flash.defs4
-rw-r--r--src/stm/Makefile.defs4
-rw-r--r--src/stm/ao_arch.h3
-rw-r--r--src/stm/ao_boot.h39
-rw-r--r--src/stm/ao_boot_chain.c2
-rw-r--r--src/stm/ao_boot_pin.c2
-rw-r--r--src/stm/ao_fast_timer.c8
-rw-r--r--src/stm/ao_interrupt.c32
-rw-r--r--src/stm/ao_timer.c10
-rw-r--r--src/stm/ao_usb_stm.c5
-rw-r--r--src/stm/registers.ld5
-rw-r--r--src/stm/stm32l.h57
12 files changed, 115 insertions, 56 deletions
diff --git a/src/stm/Makefile-flash.defs b/src/stm/Makefile-flash.defs
index 3890eff1..dde51a68 100644
--- a/src/stm/Makefile-flash.defs
+++ b/src/stm/Makefile-flash.defs
@@ -1,4 +1,4 @@
-vpath % $(TOPDIR)/stm:$(TOPDIR)/product:$(TOPDIR)/drivers:$(TOPDIR)/core:$(TOPDIR)/util:$(TOPDIR)
+vpath % $(TOPDIR)/stm:$(TOPDIR)/product:$(TOPDIR)/drivers:$(TOPDIR)/kernel:$(TOPDIR)/util:$(TOPDIR)
vpath ao-make-product.5c $(TOPDIR)/util
.SUFFIXES: .elf .ihx
@@ -14,7 +14,7 @@ include $(TOPDIR)/Makedefs
CC=$(ARM_CC)
LIBS=$(PDCLIB_LIBS_M3) -lgcc
-AO_CFLAGS=-I. -I$(TOPDIR)/stm -I$(TOPDIR)/core -I$(TOPDIR)/drivers -I$(TOPDIR)/product -I$(TOPDIR) $(PDCLIB_INCLUDES)
+AO_CFLAGS=-I. -I$(TOPDIR)/stm -I$(TOPDIR)/kernel -I$(TOPDIR)/drivers -I$(TOPDIR)/product -I$(TOPDIR) $(PDCLIB_INCLUDES)
STM_CFLAGS=-std=gnu99 -mlittle-endian -mcpu=cortex-m3 -mthumb -ffreestanding -nostdlib $(AO_CFLAGS) $(SAT_CFLAGS)
LDFLAGS=-L$(TOPDIR)/stm -Wl,-Taltos-loader.ld
diff --git a/src/stm/Makefile.defs b/src/stm/Makefile.defs
index 42adfd09..c3d2707f 100644
--- a/src/stm/Makefile.defs
+++ b/src/stm/Makefile.defs
@@ -1,4 +1,4 @@
-vpath % ../stm:../product:../drivers:../core:../util:../kalman:../aes:../math:..
+vpath % ../stm:../product:../drivers:../kernel:../util:../kalman:../aes:../math:..
vpath make-altitude ../util
vpath make-kalman ../util
vpath kalman.5c ../kalman
@@ -26,7 +26,7 @@ LIBS=$(PDCLIB_LIBS_M3) -lgcc
WARN_FLAGS=-Wall -Wextra -Werror
-AO_CFLAGS=-I. -I../stm -I../core -I../drivers -I../math -I.. $(PDCLIB_INCLUDES)
+AO_CFLAGS=-I. -I../stm -I../kernel -I../drivers -I../math -I.. $(PDCLIB_INCLUDES)
STM_CFLAGS=-std=gnu99 -mlittle-endian -mcpu=cortex-m3 -mthumb \
-ffreestanding -nostdlib $(AO_CFLAGS) $(WARN_FLAGS)
diff --git a/src/stm/ao_arch.h b/src/stm/ao_arch.h
index 76fa9194..a6276c5a 100644
--- a/src/stm/ao_arch.h
+++ b/src/stm/ao_arch.h
@@ -139,7 +139,8 @@ ao_adc_init();
#define AO_ADC_MAX 4095
#define AO_BOOT_APPLICATION_BASE ((uint32_t *) 0x08001000)
-#define AO_BOOT_LOADER_BASE ((uint32_t *) 0x0)
+#define AO_BOOT_APPLICATION_BOUND ((uint32_t *) (0x08000000 + stm_flash_size()))
+#define AO_BOOT_LOADER_BASE ((uint32_t *) 0x08000000)
#define HAS_BOOT_LOADER 1
#endif /* _AO_ARCH_H_ */
diff --git a/src/stm/ao_boot.h b/src/stm/ao_boot.h
deleted file mode 100644
index e0ed4de7..00000000
--- a/src/stm/ao_boot.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright © 2013 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; version 2 of the License.
- *
- * 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.
- */
-
-#ifndef _AO_BOOT_H_
-#define _AO_BOOT_H_
-
-void
-ao_boot_chain(uint32_t *base);
-
-void
-ao_boot_check_pin(void);
-
-/* Return true to switch to application (if present) */
-int
-ao_boot_check_chain(void);
-
-void
-ao_boot_reboot(uint32_t *base);
-
-static inline void
-ao_boot_loader(void) {
- ao_boot_reboot(AO_BOOT_LOADER_BASE);
-}
-
-#endif /* _AO_BOOT_H_ */
diff --git a/src/stm/ao_boot_chain.c b/src/stm/ao_boot_chain.c
index 6a3864a7..bcebf033 100644
--- a/src/stm/ao_boot_chain.c
+++ b/src/stm/ao_boot_chain.c
@@ -50,7 +50,7 @@ ao_boot_check_chain(void)
if (ao_boot.signal == AO_BOOT_SIGNAL && ao_boot.check == AO_BOOT_CHECK) {
ao_boot.signal = 0;
ao_boot.check = 0;
- if (ao_boot.base == 0)
+ if (ao_boot.base == AO_BOOT_FORCE_LOADER)
return 0;
ao_boot_chain(ao_boot.base);
}
diff --git a/src/stm/ao_boot_pin.c b/src/stm/ao_boot_pin.c
index 1000a65a..e825b618 100644
--- a/src/stm/ao_boot_pin.c
+++ b/src/stm/ao_boot_pin.c
@@ -26,7 +26,7 @@ ao_boot_check_pin(void)
/* Enable power interface clock */
stm_rcc.apb1enr |= (1 << STM_RCC_APB1ENR_PWREN);
-
+
/* Enable the input pin */
ao_enable_input(&AO_BOOT_APPLICATION_GPIO, AO_BOOT_APPLICATION_PIN,
AO_BOOT_APPLICATION_MODE);
diff --git a/src/stm/ao_fast_timer.c b/src/stm/ao_fast_timer.c
index d61b40c9..9a73eb51 100644
--- a/src/stm/ao_fast_timer.c
+++ b/src/stm/ao_fast_timer.c
@@ -88,7 +88,11 @@ void stm_tim6_isr(void)
#define TIMER_23467_SCALER 1
#endif
-#define TIMER_10kHz ((AO_PCLK1 * TIMER_23467_SCALER) / 10000)
+#ifndef FAST_TIMER_FREQ
+#define FAST_TIMER_FREQ 10000
+#endif
+
+#define TIMER_FAST ((AO_PCLK1 * TIMER_23467_SCALER) / FAST_TIMER_FREQ)
void
ao_fast_timer_init(void)
@@ -100,7 +104,7 @@ ao_fast_timer_init(void)
/* Turn on timer 6 */
stm_rcc.apb1enr |= (1 << STM_RCC_APB1ENR_TIM6EN);
- stm_tim6.psc = TIMER_10kHz;
+ stm_tim6.psc = TIMER_FAST;
stm_tim6.arr = 9;
stm_tim6.cnt = 0;
diff --git a/src/stm/ao_interrupt.c b/src/stm/ao_interrupt.c
index 969e6a0f..56cce0c0 100644
--- a/src/stm/ao_interrupt.c
+++ b/src/stm/ao_interrupt.c
@@ -39,6 +39,38 @@ void stm_ignore_isr(void)
const void *stm_interrupt_vector[];
+uint32_t
+stm_flash_size(void) {
+ uint16_t dev_id = stm_dev_id();
+ uint16_t kbytes = 0;
+
+ switch (dev_id) {
+ case 0x416: /* cat 1 */
+ kbytes = stm_flash_size_medium.f_size;
+ break;
+ case 0x429: /* cat 2 */
+ kbytes = stm_flash_size_medium.f_size & 0xff;
+ break;
+ case 0x427: /* cat 3 */
+ kbytes = stm_flash_size_large.f_size;
+ break;
+ case 0x436: /* cat 4 */
+ switch (stm_flash_size_large.f_size) {
+ case 0:
+ kbytes = 256;
+ break;
+ case 1:
+ kbytes = 384;
+ break;
+ }
+ break;
+ case 0x437: /* cat 5 */
+ kbytes = stm_flash_size_large.f_size;
+ break;
+ }
+ return (uint32_t) kbytes * 1024;
+}
+
void start(void)
{
#ifdef AO_BOOT_CHAIN
diff --git a/src/stm/ao_timer.c b/src/stm/ao_timer.c
index d93531fc..8db62e76 100644
--- a/src/stm/ao_timer.c
+++ b/src/stm/ao_timer.c
@@ -17,6 +17,9 @@
#include "ao.h"
#include <ao_task.h>
+#if HAS_FAKE_FLIGHT
+#include <ao_fake_flight.h>
+#endif
#ifndef HAS_TICK
#define HAS_TICK 1
@@ -47,7 +50,12 @@ void stm_systick_isr(void)
#if AO_DATA_ALL
if (++ao_data_count == ao_data_interval) {
ao_data_count = 0;
- ao_adc_poll();
+#if HAS_FAKE_FLIGHT
+ if (ao_fake_flight_active)
+ ao_fake_flight_poll();
+ else
+#endif
+ ao_adc_poll();
#if (AO_DATA_ALL & ~(AO_DATA_ADC))
ao_wakeup((void *) &ao_data_count);
#endif
diff --git a/src/stm/ao_usb_stm.c b/src/stm/ao_usb_stm.c
index 27b82357..4e9d1f14 100644
--- a/src/stm/ao_usb_stm.c
+++ b/src/stm/ao_usb_stm.c
@@ -117,7 +117,7 @@ static uint8_t ao_usb_in_pending;
* but not pulled to the shadow buffer.
*/
static uint8_t ao_usb_out_avail;
-static uint8_t ao_usb_running;
+uint8_t ao_usb_running;
static uint8_t ao_usb_configuration;
#define AO_USB_EP0_GOT_RESET 1
@@ -727,6 +727,9 @@ ao_usb_ep0_handle(uint8_t receive)
if (receive & AO_USB_EP0_GOT_TX_ACK) {
debug ("\tgot tx ack\n");
+#if HAS_FLIGHT && AO_USB_FORCE_IDLE
+ ao_flight_force_idle = 1;
+#endif
/* Wait until the IN packet is received from addr 0
* before assigning our local address
*/
diff --git a/src/stm/registers.ld b/src/stm/registers.ld
index 8318c75a..d40fd90f 100644
--- a/src/stm/registers.ld
+++ b/src/stm/registers.ld
@@ -52,5 +52,10 @@ stm_scb = 0xe000ed00;
stm_mpu = 0xe000ed90;
+stm_dbg_mcu = 0xe0042000;
+
/* calibration data in system memory */
stm_temp_cal = 0x1ff80078;
+stm_flash_size_medium = 0x1ff8004c;
+stm_flash_size_large = 0x1ff800cc;
+stm_device_id = 0x1ff80050;
diff --git a/src/stm/stm32l.h b/src/stm/stm32l.h
index 302f4d24..799cccbd 100644
--- a/src/stm/stm32l.h
+++ b/src/stm/stm32l.h
@@ -176,12 +176,27 @@ stm_gpio_get_all(struct stm_gpio *gpio) {
return gpio->idr;
}
-extern struct stm_gpio stm_gpioa;
-extern struct stm_gpio stm_gpiob;
-extern struct stm_gpio stm_gpioc;
-extern struct stm_gpio stm_gpiod;
-extern struct stm_gpio stm_gpioe;
-extern struct stm_gpio stm_gpioh;
+/*
+ * We can't define these in registers.ld or our fancy
+ * ao_enable_gpio macro will expand into a huge pile of code
+ * as the compiler won't do correct constant folding and
+ * dead-code elimination
+
+ extern struct stm_gpio stm_gpioa;
+ extern struct stm_gpio stm_gpiob;
+ extern struct stm_gpio stm_gpioc;
+ extern struct stm_gpio stm_gpiod;
+ extern struct stm_gpio stm_gpioe;
+ extern struct stm_gpio stm_gpioh;
+
+*/
+
+#define stm_gpioh (*((struct stm_gpio *) 0x40021400))
+#define stm_gpioe (*((struct stm_gpio *) 0x40021000))
+#define stm_gpiod (*((struct stm_gpio *) 0x40020c00))
+#define stm_gpioc (*((struct stm_gpio *) 0x40020800))
+#define stm_gpiob (*((struct stm_gpio *) 0x40020400))
+#define stm_gpioa (*((struct stm_gpio *) 0x40020000))
struct stm_usart {
vuint32_t sr; /* status register */
@@ -1492,6 +1507,36 @@ extern struct stm_temp_cal stm_temp_cal;
#define stm_temp_cal_cold 25
#define stm_temp_cal_hot 110
+struct stm_dbg_mcu {
+ uint32_t idcode;
+};
+
+extern struct stm_dbg_mcu stm_dbg_mcu;
+
+static inline uint16_t
+stm_dev_id(void) {
+ return stm_dbg_mcu.idcode & 0xfff;
+}
+
+struct stm_flash_size {
+ uint16_t f_size;
+};
+
+extern struct stm_flash_size stm_flash_size_medium;
+extern struct stm_flash_size stm_flash_size_large;
+
+/* Returns flash size in bytes */
+extern uint32_t
+stm_flash_size(void);
+
+struct stm_device_id {
+ uint32_t u_id0;
+ uint32_t u_id1;
+ uint32_t u_id2;
+};
+
+extern struct stm_device_id stm_device_id;
+
#define STM_NUM_I2C 2
#define STM_I2C_INDEX(channel) ((channel) - 1)