summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/attiny/ao_arch.h2
-rw-r--r--src/avr-demo/ao_demo.c2
-rw-r--r--src/avr/ao_avr_stdio.c11
-rw-r--r--src/core/ao.h5
-rw-r--r--src/core/ao_cmd.c46
-rw-r--r--src/core/ao_notask.c (renamed from src/micropeak/ao_notask.c)2
-rw-r--r--src/core/ao_notask.h27
-rw-r--r--src/core/ao_stdio.c17
-rw-r--r--src/core/ao_task.c2
-rw-r--r--src/core/ao_task.h4
-rw-r--r--src/megadongle-v0.1/Makefile1
-rw-r--r--src/product/ao_teledongle.c2
-rw-r--r--src/product/ao_telelaunch.c2
-rw-r--r--src/product/ao_telemetrum.c2
-rw-r--r--src/product/ao_telemini.c2
-rw-r--r--src/product/ao_telenano.c2
-rw-r--r--src/product/ao_telepyro.c2
-rw-r--r--src/product/ao_telescience.c2
-rw-r--r--src/product/ao_teleterra.c2
-rw-r--r--src/product/ao_teleterra_0_2.c2
-rw-r--r--src/product/ao_test.c2
-rw-r--r--src/product/ao_tidongle.c3
-rw-r--r--src/spiradio-v0.1/ao_spiradio.c2
-rw-r--r--src/stm-bringup/ao.h2
-rw-r--r--src/stm-demo/Makefile11
-rw-r--r--src/stm-demo/ao_demo.c3
-rw-r--r--src/stm-demo/ao_pins.h2
-rw-r--r--src/stm-flash/Makefile59
-rw-r--r--src/stm-flash/ao_pins.h79
-rw-r--r--src/stm-flash/ao_stm_flash.c151
-rw-r--r--src/stm/Makefile.defs5
-rw-r--r--src/stm/altos-loader.ld89
-rw-r--r--src/stm/altos.ld35
-rw-r--r--src/stm/ao_arch.h5
-rw-r--r--src/stm/ao_arch_funcs.h25
-rw-r--r--src/stm/ao_boot.h39
-rw-r--r--src/stm/ao_boot_chain.c67
-rw-r--r--src/stm/ao_boot_pin.c43
-rw-r--r--src/stm/ao_flash_stm.c127
-rw-r--r--src/stm/ao_flash_stm.h27
-rw-r--r--src/stm/ao_interrupt.c15
-rw-r--r--src/stm/ao_romconfig.c6
-rw-r--r--src/stm/ao_timer.c11
-rw-r--r--src/stm/ao_usb_stm.c237
-rw-r--r--src/stm/stm32l.h3
-rw-r--r--src/teleballoon-v1.1/ao_teleballoon.c2
-rw-r--r--src/telebt-v1.0/ao_telebt.c3
-rw-r--r--src/telefire-v0.1/ao_telefire.c2
-rw-r--r--src/telegps-v0.1/Makefile1
-rw-r--r--src/telelco-v0.1/Makefile1
-rw-r--r--src/telelco-v0.1/ao_telelco.c2
-rw-r--r--src/telemega-v0.1/Makefile1
-rw-r--r--src/telescience-v0.2/Makefile1
-rw-r--r--src/telescience-v0.2/ao_telescience.c4
-rw-r--r--src/teleshield-v0.1/ao_teleshield.c1
55 files changed, 1044 insertions, 159 deletions
diff --git a/src/attiny/ao_arch.h b/src/attiny/ao_arch.h
index 52bed981..8140dd30 100644
--- a/src/attiny/ao_arch.h
+++ b/src/attiny/ao_arch.h
@@ -55,7 +55,7 @@
#define putchar(c) ao_putchar(c)
#define getchar ao_getchar
-#define ao_arch_cpu_idle() do { \
+#define ao_arch_wait_interrupt() do { \
sleep_enable(); \
sei(); \
sleep_cpu(); \
diff --git a/src/avr-demo/ao_demo.c b/src/avr-demo/ao_demo.c
index 756dd0d4..e35babb3 100644
--- a/src/avr-demo/ao_demo.c
+++ b/src/avr-demo/ao_demo.c
@@ -34,6 +34,8 @@ main(void)
{
ao_clock_init();
+ ao_task_init();
+
ao_serial_init();
ao_led_init(LEDS_AVAILABLE);
diff --git a/src/avr/ao_avr_stdio.c b/src/avr/ao_avr_stdio.c
index 2765853a..f9c0f88c 100644
--- a/src/avr/ao_avr_stdio.c
+++ b/src/avr/ao_avr_stdio.c
@@ -20,16 +20,7 @@
int
stdio_put(char c, FILE *stream)
{
- if (ao_cur_task && ao_num_stdios)
- putchar(c);
- else
- {
- if (c == '\n')
- stdio_put('\r', stream);
- loop_until_bit_is_set(UCSR1A, UDRE1);
- UDR1 = c;
- }
-
+ putchar(c);
return 0;
}
diff --git a/src/core/ao.h b/src/core/ao.h
index 977e10b8..f12ca9a5 100644
--- a/src/core/ao.h
+++ b/src/core/ao.h
@@ -45,6 +45,8 @@
#if HAS_TASK
#include <ao_task.h>
+#else
+#include <ao_notask.h>
#endif
/*
@@ -145,6 +147,9 @@ extern __pdata char ao_cmd_lex_c;
extern __pdata enum ao_cmd_status ao_cmd_status;
void
+ao_put_string(__code char *s);
+
+void
ao_cmd_lex(void);
void
diff --git a/src/core/ao_cmd.c b/src/core/ao_cmd.c
index 3d086a57..16cde919 100644
--- a/src/core/ao_cmd.c
+++ b/src/core/ao_cmd.c
@@ -16,6 +16,7 @@
*/
#include "ao.h"
+#include "ao_task.h"
__pdata uint16_t ao_cmd_lex_i;
__pdata uint32_t ao_cmd_lex_u32;
@@ -28,8 +29,8 @@ static __xdata char cmd_line[CMD_LEN];
static __pdata uint8_t cmd_len;
static __pdata uint8_t cmd_i;
-static void
-put_string(__code char *s)
+void
+ao_put_string(__code char *s)
{
char c;
while ((c = *s++))
@@ -39,7 +40,7 @@ put_string(__code char *s)
static void
backspace(void)
{
- put_string ("\010 \010");
+ ao_put_string ("\010 \010");
}
static void
@@ -47,7 +48,7 @@ readline(void)
{
char c;
if (ao_echo())
- put_string("> ");
+ ao_put_string("> ");
cmd_len = 0;
for (;;) {
flush();
@@ -262,6 +263,11 @@ ao_reboot(void)
ao_panic(AO_PANIC_REBOOT);
}
+#ifndef HAS_VERSION
+#define HAS_VERSION 1
+#endif
+
+#if HAS_VERSION
static void
version(void)
{
@@ -289,6 +295,7 @@ version(void)
#endif
printf("software-version %s\n", ao_version);
}
+#endif
#ifndef NUM_CMDS
#define NUM_CMDS 11
@@ -303,13 +310,21 @@ help(void)
__pdata uint8_t cmds;
__pdata uint8_t cmd;
__code struct ao_cmds * __pdata cs;
- const char *h;
+ __code char *h;
+ uint8_t e;
for (cmds = 0; cmds < ao_ncmds; cmds++) {
cs = ao_cmds[cmds];
for (cmd = 0; cs[cmd].func; cmd++) {
h = cs[cmd].help;
- printf("%-45s %s\n", h, h + 1 + strlen(h));
+ ao_put_string(h);
+ e = strlen(h);
+ h += e + 1;
+ e = 45 - e;
+ while (e--)
+ putchar(' ');
+ ao_put_string(h);
+ putchar('\n');
}
}
}
@@ -370,14 +385,33 @@ ao_cmd(void)
}
}
+#if HAS_BOOT_LOADER
+
+#include <ao_boot.h>
+
+static void
+ao_loader(void)
+{
+ flush();
+ ao_boot_loader();
+}
+#endif
+
__xdata struct ao_task ao_cmd_task;
__code struct ao_cmds ao_base_cmds[] = {
{ help, "?\0Help" },
+#if HAS_TASK_INFO
{ ao_task_info, "T\0Tasks" },
+#endif
{ echo, "E <0 off, 1 on>\0Echo" },
{ ao_reboot, "r eboot\0Reboot" },
+#if HAS_VERSION
{ version, "v\0Version" },
+#endif
+#if HAS_BOOT_LOADER
+ { ao_loader, "X\0Switch to boot loader" },
+#endif
{ 0, NULL },
};
diff --git a/src/micropeak/ao_notask.c b/src/core/ao_notask.c
index 0aef9cf3..a41712d2 100644
--- a/src/micropeak/ao_notask.c
+++ b/src/core/ao_notask.c
@@ -24,7 +24,7 @@ ao_sleep(__xdata void *wchan)
{
#if 1
ao_wchan = wchan;
- ao_arch_cpu_idle();
+ ao_arch_wait_interrupt();
#else
uint8_t sreg;
diff --git a/src/core/ao_notask.h b/src/core/ao_notask.h
new file mode 100644
index 00000000..6b6b5bb8
--- /dev/null
+++ b/src/core/ao_notask.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright © 2012 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_NOTASK_H_
+#define _AO_NOTASK_H_
+
+uint8_t
+ao_sleep(__xdata void *wchan);
+
+void
+ao_wakeup(__xdata void *wchan);
+
+#endif /* _AO_NOTASK_H_ */
diff --git a/src/core/ao_stdio.c b/src/core/ao_stdio.c
index 977d74b1..cd144d6b 100644
--- a/src/core/ao_stdio.c
+++ b/src/core/ao_stdio.c
@@ -66,8 +66,15 @@
#define AO_NUM_STDIOS (HAS_USB + PACKET_HAS_SLAVE + USE_SERIAL_STDIN)
__xdata struct ao_stdio ao_stdios[AO_NUM_STDIOS];
+
+#if AO_NUM_STDIOS > 1
__pdata int8_t ao_cur_stdio;
__pdata int8_t ao_num_stdios;
+#else
+__pdata int8_t ao_cur_stdio;
+#define ao_cur_stdio 0
+#define ao_num_stdios 0
+#endif
void
putchar(char c)
@@ -107,12 +114,16 @@ getchar(void) __reentrant
c = ao_stdios[stdio]._pollchar();
if (c != AO_READ_AGAIN)
break;
+#if AO_NUM_STDIOS > 1
if (++stdio == ao_num_stdios)
stdio = 0;
if (stdio == ao_cur_stdio)
+#endif
ao_sleep(&ao_stdin_ready);
}
+#if AO_NUM_STDIOS > 1
ao_cur_stdio = stdio;
+#endif
ao_arch_release_interrupts();
return c;
}
@@ -128,11 +139,17 @@ ao_add_stdio(int (*_pollchar)(void),
void (*putchar)(char),
void (*flush)(void)) __reentrant
{
+#if AO_NUM_STDIOS > 1
if (ao_num_stdios == AO_NUM_STDIOS)
ao_panic(AO_PANIC_STDIO);
+#endif
ao_stdios[ao_num_stdios]._pollchar = _pollchar;
ao_stdios[ao_num_stdios].putchar = putchar;
ao_stdios[ao_num_stdios].flush = flush;
ao_stdios[ao_num_stdios].echo = 1;
+#if AO_NUM_STDIOS > 1
return ao_num_stdios++;
+#else
+ return 0;
+#endif
}
diff --git a/src/core/ao_task.c b/src/core/ao_task.c
index 9cb074b5..e1d35d67 100644
--- a/src/core/ao_task.c
+++ b/src/core/ao_task.c
@@ -512,6 +512,7 @@ ao_exit(void)
/* we'll never get back here */
}
+#if HAS_TASK_INFO
void
ao_task_info(void)
{
@@ -528,6 +529,7 @@ ao_task_info(void)
ao_task_validate();
#endif
}
+#endif
void
ao_start_scheduler(void)
diff --git a/src/core/ao_task.h b/src/core/ao_task.h
index 50bfb220..1a4b5b6b 100644
--- a/src/core/ao_task.h
+++ b/src/core/ao_task.h
@@ -21,6 +21,10 @@
#include <ao_list.h>
#endif
+#ifndef HAS_TASK_INFO
+#define HAS_TASK_INFO 1
+#endif
+
/* An AltOS task */
struct ao_task {
__xdata void *wchan; /* current wait channel (NULL if running) */
diff --git a/src/megadongle-v0.1/Makefile b/src/megadongle-v0.1/Makefile
index fe392ce1..7f12963f 100644
--- a/src/megadongle-v0.1/Makefile
+++ b/src/megadongle-v0.1/Makefile
@@ -28,6 +28,7 @@ INC = \
#STACK_GUARD_DEF=-DHAS_STACK_GUARD=1
ALTOS_SRC = \
+ ao_boot_chain.c \
ao_interrupt.c \
ao_product.c \
ao_romconfig.c \
diff --git a/src/product/ao_teledongle.c b/src/product/ao_teledongle.c
index 25ebe73e..8bfd8b84 100644
--- a/src/product/ao_teledongle.c
+++ b/src/product/ao_teledongle.c
@@ -26,6 +26,8 @@ main(void)
/* Turn on the LED until the system is stable */
ao_led_init(LEDS_AVAILABLE);
ao_led_on(AO_LED_RED);
+ ao_task_init();
+
ao_timer_init();
ao_cmd_init();
ao_usb_init();
diff --git a/src/product/ao_telelaunch.c b/src/product/ao_telelaunch.c
index b6e4bfc1..dde66090 100644
--- a/src/product/ao_telelaunch.c
+++ b/src/product/ao_telelaunch.c
@@ -27,6 +27,8 @@ main(void)
ao_led_init(LEDS_AVAILABLE);
ao_led_on(AO_LED_RED);
+ ao_task_init();
+
ao_timer_init();
ao_adc_init();
ao_beep_init();
diff --git a/src/product/ao_telemetrum.c b/src/product/ao_telemetrum.c
index ea77f5af..221498d6 100644
--- a/src/product/ao_telemetrum.c
+++ b/src/product/ao_telemetrum.c
@@ -42,6 +42,8 @@ main(void)
while (P1_3 == 0)
;
}
+ ao_task_init();
+
ao_timer_init();
ao_adc_init();
ao_beep_init();
diff --git a/src/product/ao_telemini.c b/src/product/ao_telemini.c
index 21551ee9..a0d8e18a 100644
--- a/src/product/ao_telemini.c
+++ b/src/product/ao_telemini.c
@@ -46,6 +46,8 @@ main(void)
;
}
+ ao_task_init();
+
ao_timer_init();
ao_adc_init();
ao_cmd_init();
diff --git a/src/product/ao_telenano.c b/src/product/ao_telenano.c
index d91983d0..77750efd 100644
--- a/src/product/ao_telenano.c
+++ b/src/product/ao_telenano.c
@@ -28,6 +28,8 @@ main(void)
ao_led_init(LEDS_AVAILABLE);
ao_led_on(AO_LED_RED);
+ ao_task_init();
+
ao_timer_init();
ao_adc_init();
ao_cmd_init();
diff --git a/src/product/ao_telepyro.c b/src/product/ao_telepyro.c
index 79454fb7..6f09be64 100644
--- a/src/product/ao_telepyro.c
+++ b/src/product/ao_telepyro.c
@@ -25,6 +25,8 @@ main(void)
PORTE |= (1 << 6);
DDRE |= (1 << 6);
+ ao_task_init();
+
ao_avr_stdio_init();
ao_timer_init();
ao_cmd_init();
diff --git a/src/product/ao_telescience.c b/src/product/ao_telescience.c
index d448d318..2888c266 100644
--- a/src/product/ao_telescience.c
+++ b/src/product/ao_telescience.c
@@ -28,6 +28,8 @@ main(void)
PORTE |= (1 << 6);
DDRE |= (1 << 6);
+ ao_task_init();
+
ao_avr_stdio_init();
ao_timer_init();
ao_cmd_init();
diff --git a/src/product/ao_teleterra.c b/src/product/ao_teleterra.c
index d696b914..e739ae0b 100644
--- a/src/product/ao_teleterra.c
+++ b/src/product/ao_teleterra.c
@@ -26,6 +26,8 @@ main(void)
/* Turn on the red LED until the system is stable */
ao_led_init(AO_LED_RED|AO_LED_GREEN);
ao_led_on(AO_LED_RED);
+ ao_task_init();
+
ao_timer_init();
ao_beep_init();
ao_cmd_init();
diff --git a/src/product/ao_teleterra_0_2.c b/src/product/ao_teleterra_0_2.c
index 68f02596..4f7530f7 100644
--- a/src/product/ao_teleterra_0_2.c
+++ b/src/product/ao_teleterra_0_2.c
@@ -23,6 +23,8 @@ main(void)
{
ao_clock_init();
+ ao_task_init();
+
ao_timer_init();
ao_beep_init();
ao_cmd_init();
diff --git a/src/product/ao_test.c b/src/product/ao_test.c
index 14c2eb75..273a73b5 100644
--- a/src/product/ao_test.c
+++ b/src/product/ao_test.c
@@ -102,6 +102,8 @@ main(void)
{
ao_clock_init();
+ ao_task_init();
+
// ao_add_task(&blink_0_task, blink_0);
// ao_add_task(&blink_1_task, blink_1);
// ao_add_task(&wakeup_task, wakeup);
diff --git a/src/product/ao_tidongle.c b/src/product/ao_tidongle.c
index cba0b122..b1a96bdd 100644
--- a/src/product/ao_tidongle.c
+++ b/src/product/ao_tidongle.c
@@ -27,6 +27,9 @@ main(void)
/* Turn on the LED until the system is stable */
ao_led_init(AO_LED_RED);
ao_led_on(AO_LED_RED);
+
+ ao_task_init();
+
ao_timer_init();
ao_cmd_init();
ao_usb_init();
diff --git a/src/spiradio-v0.1/ao_spiradio.c b/src/spiradio-v0.1/ao_spiradio.c
index d3647cc7..de9ea706 100644
--- a/src/spiradio-v0.1/ao_spiradio.c
+++ b/src/spiradio-v0.1/ao_spiradio.c
@@ -25,6 +25,8 @@ main(void)
ao_led_init(LEDS_AVAILABLE);
+ ao_task_init();
+
ao_serial_init();
ao_timer_init();
ao_cmd_init();
diff --git a/src/stm-bringup/ao.h b/src/stm-bringup/ao.h
index 27204fae..2c7d5282 100644
--- a/src/stm-bringup/ao.h
+++ b/src/stm-bringup/ao.h
@@ -16,3 +16,5 @@
*/
#define ao_panic(n) for(;;);
+
+#define AO_BOOT_LOADER_BASE ((uint32_t *) 0x0)
diff --git a/src/stm-demo/Makefile b/src/stm-demo/Makefile
index 3b1b671b..d1f825db 100644
--- a/src/stm-demo/Makefile
+++ b/src/stm-demo/Makefile
@@ -17,6 +17,7 @@ INC = \
#
ALTOS_SRC = \
ao_interrupt.c \
+ ao_boot_chain.c \
ao_product.c \
ao_romconfig.c \
ao_cmd.c \
@@ -46,17 +47,19 @@ IDPRODUCT=0x000a
CFLAGS = $(PRODUCT_DEF) $(STM_CFLAGS) -g -Os
-PROG=stm-demo
+PROG=stm-demo-$(VERSION)
+ELF=$(PROG).elf
+IHX=$(PROG).ihx
SRC=$(ALTOS_SRC) ao_demo.c
OBJ=$(SRC:.c=.o)
-all: $(PROG)
+all: $(ELF) $(IHX)
LDFLAGS=-L../stm -Wl,-Taltos.ld
-$(PROG): Makefile $(OBJ)
- $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(OBJ) $(SAT_CLIB) -lgcc
+$(ELF): Makefile $(OBJ)
+ $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $@ $(OBJ) $(SAT_CLIB) -lgcc
ao_product.h: ao-make-product.5c ../Version
$(call quiet,NICKLE,$<) $< -m altusmetrum.org -i $(IDPRODUCT) -p $(PRODUCT) -v $(VERSION) > $@
diff --git a/src/stm-demo/ao_demo.c b/src/stm-demo/ao_demo.c
index b82cb735..5677cdf4 100644
--- a/src/stm-demo/ao_demo.c
+++ b/src/stm-demo/ao_demo.c
@@ -20,6 +20,7 @@
#include <ao_event.h>
#include <ao_quadrature.h>
#include <ao_button.h>
+#include <ao_boot.h>
struct ao_task demo_task;
@@ -183,6 +184,8 @@ main(void)
{
ao_clock_init();
+ ao_task_init();
+
ao_serial_init();
ao_timer_init();
ao_dma_init();
diff --git a/src/stm-demo/ao_pins.h b/src/stm-demo/ao_pins.h
index 07b4a19d..40e48a36 100644
--- a/src/stm-demo/ao_pins.h
+++ b/src/stm-demo/ao_pins.h
@@ -68,6 +68,8 @@
#define HAS_BEEP 0
#define PACKET_HAS_SLAVE 0
+#define AO_BOOT_CHAIN 1
+
#define LOW_LEVEL_DEBUG 1
#define LED_PORT_ENABLE STM_RCC_AHBENR_GPIOBEN
diff --git a/src/stm-flash/Makefile b/src/stm-flash/Makefile
new file mode 100644
index 00000000..1ea35581
--- /dev/null
+++ b/src/stm-flash/Makefile
@@ -0,0 +1,59 @@
+#
+# AltOS build
+#
+#
+
+include ../stm/Makefile.defs
+
+INC = \
+ ao.h \
+ ao_arch.h \
+ ao_arch_funcs.h \
+ ao_pins.h \
+ ao_product.h
+
+#
+# Common AltOS sources
+#
+ALTOS_SRC = \
+ ao_interrupt.c \
+ ao_boot_chain.c \
+ ao_boot_pin.c \
+ ao_product.c \
+ ao_notask.c \
+ ao_timer.c \
+ ao_usb_stm.c \
+ ao_flash_stm.c
+
+PRODUCT=AltosFlash-$(VERSION)
+PRODUCT_DEF=-DALTOS_FLASH
+IDPRODUCT=0x000a
+
+CFLAGS = $(PRODUCT_DEF) $(STM_CFLAGS) -g -Os
+
+PROG=altos-flash-$(VERSION).elf
+
+SRC=$(ALTOS_SRC) ao_stm_flash.c
+OBJ=$(SRC:.c=.o)
+
+all: $(PROG)
+
+LDFLAGS=-L../stm -Wl,-Taltos-loader.ld
+
+$(PROG): Makefile $(OBJ)
+ $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(OBJ) $(SAT_CLIB) -lgcc
+
+ao_product.h: ao-make-product.5c ../Version
+ $(call quiet,NICKLE,$<) $< -m altusmetrum.org -i $(IDPRODUCT) -p $(PRODUCT) -v $(VERSION) > $@
+
+$(OBJ): $(INC)
+
+distclean: clean
+
+clean:
+ rm -f *.o $(PROG)
+ rm -f ao_product.h
+
+install:
+
+uninstall:
diff --git a/src/stm-flash/ao_pins.h b/src/stm-flash/ao_pins.h
new file mode 100644
index 00000000..d6c72653
--- /dev/null
+++ b/src/stm-flash/ao_pins.h
@@ -0,0 +1,79 @@
+/*
+ * 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_PINS_H_
+#define _AO_PINS_H_
+
+#define HAS_TASK_QUEUE 0
+
+/* Bridge SB17 on the board and use the MCO from the other chip */
+#define AO_HSE 8000000
+#define AO_HSE_BYPASS 1
+
+/* PLLVCO = 96MHz (so that USB will work) */
+#define AO_PLLMUL 12
+#define AO_RCC_CFGR_PLLMUL (STM_RCC_CFGR_PLLMUL_12)
+
+/* SYSCLK = 32MHz */
+#define AO_PLLDIV 3
+#define AO_RCC_CFGR_PLLDIV (STM_RCC_CFGR_PLLDIV_3)
+
+/* HCLK = 32MHZ (CPU clock) */
+#define AO_AHB_PRESCALER 1
+#define AO_RCC_CFGR_HPRE_DIV STM_RCC_CFGR_HPRE_DIV_1
+
+/* Run APB1 at HCLK/1 */
+#define AO_APB1_PRESCALER 1
+#define AO_RCC_CFGR_PPRE1_DIV STM_RCC_CFGR_PPRE2_DIV_1
+
+/* Run APB2 at HCLK/1 */
+#define AO_APB2_PRESCALER 1
+#define AO_RCC_CFGR_PPRE2_DIV STM_RCC_CFGR_PPRE2_DIV_1
+
+#define HAS_USB 1
+#define USE_USB_STDIO 0
+#define HAS_BEEP 0
+#define HAS_TASK 0
+#define HAS_ECHO 0
+#define HAS_TICK 0
+
+#define PACKET_HAS_SLAVE 0
+
+#define LED_PORT_ENABLE STM_RCC_AHBENR_GPIOCEN
+#define LED_PORT (&stm_gpiob)
+#define LED_PIN_RED 6
+#define LED_PIN_GREEN 7
+#define AO_LED_RED (1 << LED_PIN_RED)
+#define AO_LED_GREEN (1 << LED_PIN_GREEN)
+
+#define LEDS_AVAILABLE (AO_LED_RED | AO_LED_GREEN)
+
+#define AO_TICK_TYPE uint32_t
+#define AO_TICK_SIGNED int32_t
+
+#define HAS_TASK_INFO 0
+#define HAS_VERSION 0
+
+#define AO_BOOT_CHAIN 1
+#define AO_BOOT_PIN 1
+
+#define AO_BOOT_APPLICATION_GPIO stm_gpiod
+#define AO_BOOT_APPLICATION_PIN 2
+#define AO_BOOT_APPLICATION_VALUE 1
+#define AO_BOOT_APPLICATION_MODE AO_EXTI_MODE_PULL_UP
+
+#endif /* _AO_PINS_H_ */
diff --git a/src/stm-flash/ao_stm_flash.c b/src/stm-flash/ao_stm_flash.c
new file mode 100644
index 00000000..e6db565d
--- /dev/null
+++ b/src/stm-flash/ao_stm_flash.c
@@ -0,0 +1,151 @@
+/*
+ * Copyright © 2011 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.
+ */
+
+#include "ao.h"
+#include <ao_exti.h>
+#include <ao_boot.h>
+#include <ao_flash_stm.h>
+
+void
+ao_panic(uint8_t reason)
+{
+ for (;;);
+}
+
+void
+ao_put_string(__code char *s)
+{
+ char c;
+ while ((c = *s++)) {
+ if (c == '\n')
+ ao_usb_putchar('\r');
+ ao_usb_putchar(c);
+ }
+}
+
+void
+ao_application(void)
+{
+ ao_boot_reboot(AO_BOOT_APPLICATION_BASE);
+}
+
+static uint32_t
+ao_get_hex32(void)
+{
+ int8_t n;
+ uint32_t v = 0;
+
+ for (;;) {
+ n = ao_usb_getchar();
+ if (n != ' ')
+ break;
+ }
+ for(;;) {
+ if ('0' <= n && n <= '9')
+ n = n - '0';
+ else if ('a' <= n && n <= 'f')
+ n = n - ('a' - 10);
+ else if ('A' <= n && n <= 'F')
+ n = n - ('A' - 10);
+ else
+ break;
+ v = (v << 4) | n;
+ n = ao_usb_getchar();
+ }
+ return v;
+}
+
+void
+ao_block_erase(void)
+{
+ uint32_t addr = ao_get_hex32();
+ uint32_t *p = (uint32_t *) addr;
+
+ ao_flash_erase_page(p);
+}
+
+void
+ao_block_write(void)
+{
+ uint32_t addr = ao_get_hex32();
+ uint32_t *p = (uint32_t *) addr;
+ union {
+ uint8_t data8[256];
+ uint32_t data32[64];
+ } u;
+ uint16_t i;
+
+ if (addr < (uint32_t) AO_BOOT_APPLICATION_BASE) {
+ ao_put_string("Invalid address\n");
+ return;
+ }
+ for (i = 0; i < 256; i++)
+ u.data8[i] = ao_usb_getchar();
+ ao_flash_page(p, u.data32);
+}
+
+void
+ao_block_read(void)
+{
+ uint32_t addr = ao_get_hex32();
+ uint8_t *p = (uint8_t *) addr;
+ uint16_t i;
+ uint8_t c;
+
+ for (i = 0; i < 256; i++) {
+ c = *p++;
+ ao_usb_putchar(c);
+ }
+}
+
+static void
+ao_show_version(void)
+{
+ ao_put_string("altos-loader");
+ ao_put_string("\nmanufacturer "); ao_put_string(ao_manufacturer);
+ ao_put_string("\nproduct "); ao_put_string(ao_product);
+ ao_put_string("\nsoftware-version "); ao_put_string(ao_version);
+ ao_put_string("\n");
+}
+
+static void
+ao_flash_task(void) {
+ for (;;) {
+ ao_usb_flush();
+ switch (ao_usb_getchar()) {
+ case 'v': ao_show_version(); break;
+ case 'a': ao_application(); break;
+ case 'X': ao_block_erase(); break;
+ case 'W': ao_block_write(); break;
+ case 'R': ao_block_read(); break;
+ }
+ }
+}
+
+int
+main(void)
+{
+ ao_clock_init();
+
+// ao_timer_init();
+// ao_dma_init();
+// ao_exti_init();
+ ao_usb_init();
+
+ ao_flash_task();
+ return 0;
+}
diff --git a/src/stm/Makefile.defs b/src/stm/Makefile.defs
index 1480f0b3..c8bb7d70 100644
--- a/src/stm/Makefile.defs
+++ b/src/stm/Makefile.defs
@@ -7,6 +7,11 @@ vpath load_csv.5c ../kalman
vpath matrix.5c ../kalman
vpath ao-make-product.5c ../util
+.SUFFIXES: .elf .ihx
+
+.elf.ihx:
+ objcopy -O ihex $*.elf $@
+
CC=arm-none-eabi-gcc
SAT=/opt/cortex
SAT_CLIB=$(SAT)/lib/pdclib-cortex-m3.a
diff --git a/src/stm/altos-loader.ld b/src/stm/altos-loader.ld
new file mode 100644
index 00000000..5e10e5ba
--- /dev/null
+++ b/src/stm/altos-loader.ld
@@ -0,0 +1,89 @@
+/*
+ * Copyright © 2012 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.
+ */
+
+MEMORY {
+ rom : ORIGIN = 0x08000000, LENGTH = 4K
+ ram : ORIGIN = 0x20000000, LENGTH = 16K
+}
+
+INCLUDE registers.ld
+
+EXTERN (stm_interrupt_vector)
+
+SECTIONS {
+ /*
+ * Rom contents
+ */
+
+ .text : {
+ __text_start__ = .;
+ *(.interrupt) /* Interrupt vectors */
+ *(.romconfig*)
+ *(.text) /* Executable code */
+ . = ALIGN(4);
+ *(.rodata*) /* Constants */
+ . = ALIGN(4);
+ } > rom
+
+ .ARM.exidx : {
+ . = ALIGN(4);
+ *(.ARM.exidx* .gnu.linkonce.armexidx.*)
+ . = ALIGN(4);
+ } > rom
+ __text_end__ = .;
+
+ /* Boot data which must live at the start of ram so that
+ * the application and bootloader share the same addresses.
+ * This must be all uninitialized data
+ */
+ .boot (NOLOAD) : {
+ __boot_start__ = .;
+ *(.boot)
+ . = ALIGN(4);
+ __boot_end__ = .;
+ } >ram
+
+ /* Functions placed in RAM (required for flashing) */
+ .textram : {
+ __data_start__ = .;
+ __text_ram_start__ = .;
+ *(.text.ram)
+ __text_ram_end = .;
+ } >ram AT>rom
+
+ /* Data -- relocated to RAM, but written to ROM
+ */
+ .data : {
+ *(.data) /* initialized data */
+ __data_end__ = .;
+ } >ram AT>rom
+
+
+ .bss : {
+ __bss_start__ = .;
+ *(.bss)
+ *(COMMON)
+ __bss_end__ = .;
+ } >ram
+
+ PROVIDE(__stack__ = ORIGIN(ram) + LENGTH(ram));
+ PROVIDE(end = .);
+}
+
+ENTRY(start);
+
+
diff --git a/src/stm/altos.ld b/src/stm/altos.ld
index f78a45d6..6affc376 100644
--- a/src/stm/altos.ld
+++ b/src/stm/altos.ld
@@ -16,7 +16,7 @@
*/
MEMORY {
- rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K
+ rom (rx) : ORIGIN = 0x08001000, LENGTH = 124K
ram (!w) : ORIGIN = 0x20000000, LENGTH = 16K
}
@@ -35,9 +35,19 @@ SECTIONS {
. = ORIGIN(rom) + 0x100;
+
+ /* Ick. What I want is to specify the
+ * addresses of some global constants so
+ * that I can find them across versions
+ * of the application. I can't figure out
+ * how to make gnu ld do that, so instead
+ * we just load the two files that include
+ * these defines in the right order here and
+ * expect things to 'just work'. Don't change
+ * the contents of those files, ok?
+ */
ao_romconfig.o(.romconfig*)
ao_product.o(.romconfig*)
-
*(.text*) /* Executable code */
*(.rodata*) /* Constants */
@@ -45,21 +55,34 @@ SECTIONS {
.ARM.exidx : {
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
- __text_end__ = .;
} > rom
+ __text_end__ = .;
+
+ /* Boot data which must live at the start of ram so that
+ * the application and bootloader share the same addresses.
+ * This must be all uninitialized data
+ */
+ .boot (NOLOAD) : {
+ __boot_start__ = .;
+ *(.boot)
+ . = ALIGN(4);
+ __boot_end__ = .;
+ } >ram
/* Data -- relocated to RAM, but written to ROM
*/
- .data ORIGIN(ram) : AT (ADDR(.ARM.exidx) + SIZEOF (.ARM.exidx)) {
+ .data : {
__data_start__ = .;
*(.data) /* initialized data */
+ . = ALIGN(4);
__data_end__ = .;
- __bss_start__ = .;
- } >ram
+ } >ram AT>rom
.bss : {
+ __bss_start__ = .;
*(.bss)
*(COMMON)
+ . = ALIGN(4);
__bss_end__ = .;
} >ram
diff --git a/src/stm/ao_arch.h b/src/stm/ao_arch.h
index 007f7e2e..50bff5dd 100644
--- a/src/stm/ao_arch.h
+++ b/src/stm/ao_arch.h
@@ -128,5 +128,10 @@ extern const uint32_t ao_radio_cal;
void
ao_adc_init();
+#define AO_BOOT_APPLICATION_BASE ((uint32_t *) 0x08001000)
+#define AO_BOOT_LOADER_BASE ((uint32_t *) 0x0)
+#define HAS_BOOT_LOADER 1
+
#endif /* _AO_ARCH_H_ */
+
diff --git a/src/stm/ao_arch_funcs.h b/src/stm/ao_arch_funcs.h
index d1779307..e152440a 100644
--- a/src/stm/ao_arch_funcs.h
+++ b/src/stm/ao_arch_funcs.h
@@ -113,6 +113,19 @@ ao_spi_init(void);
stm_rcc.ahbenr |= (1 << STM_RCC_AHBENR_GPIOEEN); \
} while (0)
+#define ao_disable_port(port) do { \
+ if ((port) == &stm_gpioa) \
+ stm_rcc.ahbenr &= ~(1 << STM_RCC_AHBENR_GPIOAEN); \
+ else if ((port) == &stm_gpiob) \
+ stm_rcc.ahbenr &= ~(1 << STM_RCC_AHBENR_GPIOBEN); \
+ else if ((port) == &stm_gpioc) \
+ stm_rcc.ahbenr &= ~(1 << STM_RCC_AHBENR_GPIOCEN); \
+ else if ((port) == &stm_gpiod) \
+ stm_rcc.ahbenr &= ~(1 << STM_RCC_AHBENR_GPIODEN); \
+ else if ((port) == &stm_gpioe) \
+ stm_rcc.ahbenr &= ~(1 << STM_RCC_AHBENR_GPIOEEN); \
+ } while (0)
+
#define ao_gpio_set(port, bit, pin, v) stm_gpio_set(port, bit, v)
@@ -124,9 +137,7 @@ ao_spi_init(void);
stm_moder_set(port, bit, STM_MODER_OUTPUT);\
} while (0)
-#define ao_enable_input(port,bit,mode) do { \
- ao_enable_port(port); \
- stm_moder_set(port, bit, STM_MODER_INPUT); \
+#define ao_gpio_set_mode(port,bit,mode) do { \
if (mode == AO_EXTI_MODE_PULL_UP) \
stm_pupdr_set(port, bit, STM_PUPDR_PULL_UP); \
else if (mode == AO_EXTI_MODE_PULL_DOWN) \
@@ -134,6 +145,12 @@ ao_spi_init(void);
else \
stm_pupdr_set(port, bit, STM_PUPDR_NONE); \
} while (0)
+
+#define ao_enable_input(port,bit,mode) do { \
+ ao_enable_port(port); \
+ stm_moder_set(port, bit, STM_MODER_INPUT); \
+ ao_gpio_set_mode(port, bit, mode); \
+ } while (0)
#define ao_enable_cs(port,bit) do { \
stm_gpio_set((port), bit, 1); \
@@ -250,6 +267,7 @@ ao_arch_memory_barrier() {
asm volatile("" ::: "memory");
}
+#if HAS_TASK
static inline void
ao_arch_init_stack(struct ao_task *task, void *start)
{
@@ -316,6 +334,7 @@ static inline void ao_arch_restore_stack(void) {
/* Return to calling function */
asm("bx lr");
}
+#endif
#define ao_arch_isr_stack()
diff --git a/src/stm/ao_boot.h b/src/stm/ao_boot.h
new file mode 100644
index 00000000..e0ed4de7
--- /dev/null
+++ b/src/stm/ao_boot.h
@@ -0,0 +1,39 @@
+/*
+ * 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
new file mode 100644
index 00000000..6a3864a7
--- /dev/null
+++ b/src/stm/ao_boot_chain.c
@@ -0,0 +1,67 @@
+/*
+ * 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.
+ */
+
+#include <ao.h>
+#include <ao_boot.h>
+
+void
+ao_boot_chain(uint32_t *base)
+{
+ uint32_t sp;
+ uint32_t pc;
+
+ sp = base[0];
+ pc = base[1];
+ if (0x08000100 <= pc && pc <= 0x08200000 && (pc & 1) == 1) {
+ asm ("mov sp, %0" : : "r" (sp));
+ asm ("mov lr, %0" : : "r" (pc));
+ asm ("bx lr");
+ }
+}
+
+#define AO_BOOT_SIGNAL 0x5a5aa5a5
+#define AO_BOOT_CHECK 0xc3c33c3c
+
+struct ao_boot {
+ uint32_t *base;
+ uint32_t signal;
+ uint32_t check;
+};
+
+static struct ao_boot __attribute__ ((section(".boot"))) ao_boot;
+
+int
+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)
+ return 0;
+ ao_boot_chain(ao_boot.base);
+ }
+ return 1;
+}
+
+void
+ao_boot_reboot(uint32_t *base)
+{
+ ao_boot.base = base;
+ ao_boot.signal = AO_BOOT_SIGNAL;
+ ao_boot.check = AO_BOOT_CHECK;
+ ao_arch_reboot();
+}
diff --git a/src/stm/ao_boot_pin.c b/src/stm/ao_boot_pin.c
new file mode 100644
index 00000000..03b0214f
--- /dev/null
+++ b/src/stm/ao_boot_pin.c
@@ -0,0 +1,43 @@
+/*
+ * 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.
+ */
+
+#include <ao.h>
+#include <ao_boot.h>
+#include <ao_exti.h>
+
+void
+ao_boot_check_pin(void)
+{
+ uint16_t v;
+
+ /* 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);
+
+ /* Read the value */
+ v = stm_gpio_get(&AO_BOOT_APPLICATION_GPIO, AO_BOOT_APPLICATION_PIN);
+
+ /* Reset the chip to turn off the port and the power interface clock */
+ ao_gpio_set_mode(&AO_BOOT_APPLICATION_GPIO, AO_BOOT_APPLICATION_PIN, 0);
+ ao_disable_port(&AO_BOOT_APPLICATION_GPIO);
+ stm_rcc.apb1enr &= ~(1 << STM_RCC_APB1ENR_PWREN);
+ if (v == AO_BOOT_APPLICATION_VALUE)
+ ao_boot_chain(AO_BOOT_APPLICATION_BASE);
+}
diff --git a/src/stm/ao_flash_stm.c b/src/stm/ao_flash_stm.c
new file mode 100644
index 00000000..b4d47024
--- /dev/null
+++ b/src/stm/ao_flash_stm.c
@@ -0,0 +1,127 @@
+/*
+ * 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.
+ */
+
+#include <ao.h>
+#include <ao_flash_stm.h>
+
+static uint8_t
+ao_flash_pecr_is_locked(void)
+{
+ return (stm_flash.pecr & (1 << STM_FLASH_PECR_PELOCK)) != 0;
+}
+
+static uint8_t
+ao_flash_pgr_is_locked(void)
+{
+ return (stm_flash.pecr & (1 << STM_FLASH_PECR_PRGLOCK)) != 0;
+}
+
+static void
+ao_flash_pecr_unlock(void)
+{
+ if (!ao_flash_pecr_is_locked())
+ return;
+
+ /* Unlock Data EEPROM and FLASH_PECR register */
+ stm_flash.pekeyr = STM_FLASH_PEKEYR_PEKEY1;
+ stm_flash.pekeyr = STM_FLASH_PEKEYR_PEKEY2;
+ if (ao_flash_pecr_is_locked())
+ ao_panic(AO_PANIC_FLASH);
+}
+
+static void
+ao_flash_pgr_unlock(void)
+{
+ if (!ao_flash_pgr_is_locked())
+ return;
+
+ /* Unlock program memory */
+ stm_flash.prgkeyr = STM_FLASH_PRGKEYR_PRGKEY1;
+ stm_flash.prgkeyr = STM_FLASH_PRGKEYR_PRGKEY2;
+ if (ao_flash_pgr_is_locked())
+ ao_panic(AO_PANIC_FLASH);
+}
+
+static void
+ao_flash_lock(void)
+{
+ stm_flash.pecr |= (1 << STM_FLASH_PECR_OPTLOCK) | (1 << STM_FLASH_PECR_PRGLOCK) | (1 << STM_FLASH_PECR_PELOCK);
+}
+
+static void
+ao_flash_wait_bsy(void)
+{
+ while (stm_flash.sr & (1 << STM_FLASH_SR_BSY))
+ ;
+}
+
+static void __attribute__ ((section(".text.ram"),noinline))
+_ao_flash_erase_page(uint32_t *page)
+{
+ stm_flash.pecr |= (1 << STM_FLASH_PECR_ERASE) | (1 << STM_FLASH_PECR_PROG);
+
+ *page = 0x00000000;
+
+ while (stm_flash.sr & (1 << STM_FLASH_SR_BSY))
+ ;
+}
+
+void
+ao_flash_erase_page(uint32_t *page)
+{
+ ao_flash_pecr_unlock();
+ ao_flash_pgr_unlock();
+
+ _ao_flash_erase_page(page);
+
+ ao_flash_lock();
+}
+
+static void __attribute__ ((section(".text.ram"), noinline))
+_ao_flash_half_page(uint32_t *dst, uint32_t *src)
+{
+ uint8_t i;
+
+ stm_flash.pecr |= (1 << STM_FLASH_PECR_FPRG);
+ stm_flash.pecr |= (1 << STM_FLASH_PECR_PROG);
+
+ while (stm_flash.sr & (1 << STM_FLASH_SR_BSY))
+ ;
+
+ for (i = 0; i < 32; i++) {
+ *dst++ = *src++;
+ }
+
+ while (stm_flash.sr & (1 << STM_FLASH_SR_BSY))
+ ;
+}
+
+void
+ao_flash_page(uint32_t *page, uint32_t *src)
+{
+ uint8_t h;
+
+ ao_flash_erase_page(page);
+ ao_flash_pecr_unlock();
+ ao_flash_pgr_unlock();
+ for (h = 0; h < 2; h++) {
+ _ao_flash_half_page(page, src);
+ page += 32;
+ src += 32;
+ }
+ ao_flash_lock();
+}
diff --git a/src/stm/ao_flash_stm.h b/src/stm/ao_flash_stm.h
new file mode 100644
index 00000000..09ca5ac1
--- /dev/null
+++ b/src/stm/ao_flash_stm.h
@@ -0,0 +1,27 @@
+/*
+ * 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_FLASH_STM_H_
+#define _AO_FLASH_STM_H_
+
+void
+ao_flash_erase_page(uint32_t *page);
+
+void
+ao_flash_page(uint32_t *page, uint32_t *src);
+
+#endif /* _AO_FLASH_STM_H_ */
diff --git a/src/stm/ao_interrupt.c b/src/stm/ao_interrupt.c
index a423d8b1..969e6a0f 100644
--- a/src/stm/ao_interrupt.c
+++ b/src/stm/ao_interrupt.c
@@ -18,6 +18,7 @@
#include <ao.h>
#include "stm32l.h"
#include <string.h>
+#include <ao_boot.h>
extern void main(void);
extern char __stack__;
@@ -36,7 +37,19 @@ void stm_ignore_isr(void)
{
}
-void start(void) {
+const void *stm_interrupt_vector[];
+
+void start(void)
+{
+#ifdef AO_BOOT_CHAIN
+ if (ao_boot_check_chain()) {
+#ifdef AO_BOOT_PIN
+ ao_boot_check_pin();
+#endif
+ }
+#endif
+ /* Set interrupt vector table offset */
+ stm_nvic.vto = (uint32_t) &stm_interrupt_vector;
memcpy(&__data_start__, &__text_end__, &__data_end__ - &__data_start__);
memset(&__bss_start__, '\0', &__bss_end__ - &__bss_start__);
main();
diff --git a/src/stm/ao_romconfig.c b/src/stm/ao_romconfig.c
index cbb922ec..5da15072 100644
--- a/src/stm/ao_romconfig.c
+++ b/src/stm/ao_romconfig.c
@@ -20,6 +20,8 @@
AO_ROMCONFIG_SYMBOL (0) uint16_t ao_romconfig_version = AO_ROMCONFIG_VERSION;
AO_ROMCONFIG_SYMBOL (0) uint16_t ao_romconfig_check = ~AO_ROMCONFIG_VERSION;
AO_ROMCONFIG_SYMBOL (0) uint16_t ao_serial_number = 0;
-#ifdef AO_RADIO_CAL_DEFAULT
-AO_ROMCONFIG_SYMBOL (0) uint32_t ao_radio_cal = AO_RADIO_CAL_DEFAULT;
+#ifndef AO_RADIO_CAL_DEFAULT
+#define AO_RADIO_CAL_DEFAULT 0x01020304
#endif
+AO_ROMCONFIG_SYMBOL (0) uint32_t ao_radio_cal = AO_RADIO_CAL_DEFAULT;
+
diff --git a/src/stm/ao_timer.c b/src/stm/ao_timer.c
index 8b7c2327..ff477a03 100644
--- a/src/stm/ao_timer.c
+++ b/src/stm/ao_timer.c
@@ -18,6 +18,11 @@
#include "ao.h"
#include <ao_task.h>
+#ifndef HAS_TICK
+#define HAS_TICK 1
+#endif
+
+#if HAS_TICK
volatile AO_TICK_TYPE ao_tick_count;
AO_TICK_TYPE
@@ -31,10 +36,6 @@ volatile __data uint8_t ao_data_interval = 1;
volatile __data uint8_t ao_data_count;
#endif
-void
-ao_debug_out(char c);
-
-
void stm_tim6_isr(void)
{
if (stm_tim6.sr & (1 << STM_TIM67_SR_UIF)) {
@@ -110,6 +111,8 @@ ao_timer_init(void)
(1 << STM_TIM67_CR1_CEN));
}
+#endif
+
void
ao_clock_init(void)
{
diff --git a/src/stm/ao_usb_stm.c b/src/stm/ao_usb_stm.c
index e29abc87..11dde92e 100644
--- a/src/stm/ao_usb_stm.c
+++ b/src/stm/ao_usb_stm.c
@@ -23,6 +23,16 @@
#define USB_DEBUG_DATA 0
#define USB_ECHO 0
+#ifndef USE_USB_STDIO
+#define USE_USB_STDIO 1
+#endif
+
+#if USE_USB_STDIO
+#define AO_USB_OUT_SLEEP_ADDR (&ao_stdin_ready)
+#else
+#define AO_USB_OUT_SLEEP_ADDR (&ao_usb_out_avail)
+#endif
+
#if USB_DEBUG
#define debug(format, args...) printf(format, ## args);
#else
@@ -35,8 +45,6 @@
#define debug_data(format, args...)
#endif
-struct ao_task ao_usb_task;
-
struct ao_usb_setup {
uint8_t dir_type_recip;
uint8_t request;
@@ -398,81 +406,6 @@ static uint16_t in_count;
static uint16_t out_count;
static uint16_t reset_count;
-void
-stm_usb_lp_isr(void)
-{
- uint32_t istr = stm_usb.istr;
-
- if (istr & (1 << STM_USB_ISTR_CTR)) {
- uint8_t ep = istr & STM_USB_ISTR_EP_ID_MASK;
- uint32_t epr, epr_write;
-
- /* Preserve the SW write bits, don't mess with most HW writable bits,
- * clear the CTR_RX and CTR_TX bits
- */
- epr = stm_usb.epr[ep];
- epr_write = epr;
- epr_write &= STM_USB_EPR_PRESERVE_MASK;
- epr_write |= STM_USB_EPR_INVARIANT;
- epr_write &= ~(1 << STM_USB_EPR_CTR_RX);
- epr_write &= ~(1 << STM_USB_EPR_CTR_TX);
- stm_usb.epr[ep] = epr_write;
-
- switch (ep) {
- case 0:
- ++control_count;
- if (ao_usb_epr_ctr_rx(epr)) {
- if (ao_usb_epr_setup(epr))
- ao_usb_ep0_receive |= AO_USB_EP0_GOT_SETUP;
- else
- ao_usb_ep0_receive |= AO_USB_EP0_GOT_RX_DATA;
- }
- if (ao_usb_epr_ctr_tx(epr))
- ao_usb_ep0_receive |= AO_USB_EP0_GOT_TX_ACK;
- ao_wakeup(&ao_usb_ep0_receive);
- break;
- case AO_USB_OUT_EPR:
- ++out_count;
- if (ao_usb_epr_ctr_rx(epr)) {
- _rx_dbg1("RX ISR", epr);
- ao_usb_out_avail = 1;
- _rx_dbg0("out avail set");
- ao_wakeup(&ao_stdin_ready);
- _rx_dbg0("stdin awoken");
- }
- break;
- case AO_USB_IN_EPR:
- ++in_count;
- _tx_dbg1("TX ISR", epr);
- if (ao_usb_epr_ctr_tx(epr)) {
- ao_usb_in_pending = 0;
- ao_wakeup(&ao_usb_in_pending);
- }
- break;
- case AO_USB_INT_EPR:
- ++int_count;
- if (ao_usb_epr_ctr_tx(epr))
- _ao_usb_set_stat_tx(AO_USB_INT_EPR, STM_USB_EPR_STAT_TX_NAK);
- break;
- }
- return;
- }
-
- if (istr & (1 << STM_USB_ISTR_RESET)) {
- ++reset_count;
- stm_usb.istr &= ~(1 << STM_USB_ISTR_RESET);
- ao_usb_ep0_receive |= AO_USB_EP0_GOT_RESET;
- ao_wakeup(&ao_usb_ep0_receive);
- }
-}
-
-void
-stm_usb_fs_wkup(void)
-{
- /* USB wakeup, just clear the bit for now */
- stm_usb.istr &= ~(1 << STM_USB_ISTR_WKUP);
-}
-
/* The USB memory holds 16 bit values on 32 bit boundaries
* and must be accessed only in 32 bit units. Sigh.
*/
@@ -772,55 +705,117 @@ ao_usb_ep0_setup(void)
ao_usb_ep0_in_start(ao_usb_setup.length);
}
-/* End point 0 receives all of the control messages. */
static void
-ao_usb_ep0(void)
+ao_usb_ep0_handle(uint8_t receive)
{
- uint8_t intx, udint;
-
- debug ("usb task started\n");
- ao_usb_ep0_state = AO_USB_EP0_IDLE;
- for (;;) {
- uint8_t receive;
- ao_arch_critical(
- while (!(receive = ao_usb_ep0_receive))
- ao_sleep(&ao_usb_ep0_receive);
- ao_usb_ep0_receive = 0;
- );
-
- if (receive & AO_USB_EP0_GOT_RESET) {
- debug ("\treset\n");
- ao_usb_set_ep0();
- continue;
- }
- if (receive & AO_USB_EP0_GOT_SETUP) {
- debug ("\tsetup\n");
- ao_usb_ep0_setup();
- }
- if (receive & AO_USB_EP0_GOT_RX_DATA) {
- debug ("\tgot rx data\n");
- if (ao_usb_ep0_state == AO_USB_EP0_DATA_OUT) {
- ao_usb_ep0_fill();
- if (ao_usb_ep0_out_len == 0) {
- ao_usb_ep0_state = AO_USB_EP0_DATA_IN;
- ao_usb_ep0_in_start(0);
- }
+ ao_usb_ep0_receive = 0;
+ if (receive & AO_USB_EP0_GOT_RESET) {
+ debug ("\treset\n");
+ ao_usb_set_ep0();
+ return;
+ }
+ if (receive & AO_USB_EP0_GOT_SETUP) {
+ debug ("\tsetup\n");
+ ao_usb_ep0_setup();
+ }
+ if (receive & AO_USB_EP0_GOT_RX_DATA) {
+ debug ("\tgot rx data\n");
+ if (ao_usb_ep0_state == AO_USB_EP0_DATA_OUT) {
+ ao_usb_ep0_fill();
+ if (ao_usb_ep0_out_len == 0) {
+ ao_usb_ep0_state = AO_USB_EP0_DATA_IN;
+ ao_usb_ep0_in_start(0);
}
}
- if (receive & AO_USB_EP0_GOT_TX_ACK) {
- debug ("\tgot tx ack\n");
-
- /* Wait until the IN packet is received from addr 0
- * before assigning our local address
- */
- if (ao_usb_address_pending)
- ao_usb_set_address(ao_usb_address);
- if (ao_usb_ep0_state == AO_USB_EP0_DATA_IN)
- ao_usb_ep0_flush();
+ }
+ if (receive & AO_USB_EP0_GOT_TX_ACK) {
+ debug ("\tgot tx ack\n");
+
+ /* Wait until the IN packet is received from addr 0
+ * before assigning our local address
+ */
+ if (ao_usb_address_pending)
+ ao_usb_set_address(ao_usb_address);
+ if (ao_usb_ep0_state == AO_USB_EP0_DATA_IN)
+ ao_usb_ep0_flush();
+ }
+}
+
+void
+stm_usb_lp_isr(void)
+{
+ uint32_t istr = stm_usb.istr;
+
+ if (istr & (1 << STM_USB_ISTR_CTR)) {
+ uint8_t ep = istr & STM_USB_ISTR_EP_ID_MASK;
+ uint32_t epr, epr_write;
+
+ /* Preserve the SW write bits, don't mess with most HW writable bits,
+ * clear the CTR_RX and CTR_TX bits
+ */
+ epr = stm_usb.epr[ep];
+ epr_write = epr;
+ epr_write &= STM_USB_EPR_PRESERVE_MASK;
+ epr_write |= STM_USB_EPR_INVARIANT;
+ epr_write &= ~(1 << STM_USB_EPR_CTR_RX);
+ epr_write &= ~(1 << STM_USB_EPR_CTR_TX);
+ stm_usb.epr[ep] = epr_write;
+
+ switch (ep) {
+ case 0:
+ ++control_count;
+ if (ao_usb_epr_ctr_rx(epr)) {
+ if (ao_usb_epr_setup(epr))
+ ao_usb_ep0_receive |= AO_USB_EP0_GOT_SETUP;
+ else
+ ao_usb_ep0_receive |= AO_USB_EP0_GOT_RX_DATA;
+ }
+ if (ao_usb_epr_ctr_tx(epr))
+ ao_usb_ep0_receive |= AO_USB_EP0_GOT_TX_ACK;
+ ao_usb_ep0_handle(ao_usb_ep0_receive);
+ break;
+ case AO_USB_OUT_EPR:
+ ++out_count;
+ if (ao_usb_epr_ctr_rx(epr)) {
+ _rx_dbg1("RX ISR", epr);
+ ao_usb_out_avail = 1;
+ _rx_dbg0("out avail set");
+ ao_wakeup(AO_USB_OUT_SLEEP_ADDR);
+ _rx_dbg0("stdin awoken");
+ }
+ break;
+ case AO_USB_IN_EPR:
+ ++in_count;
+ _tx_dbg1("TX ISR", epr);
+ if (ao_usb_epr_ctr_tx(epr)) {
+ ao_usb_in_pending = 0;
+ ao_wakeup(&ao_usb_in_pending);
+ }
+ break;
+ case AO_USB_INT_EPR:
+ ++int_count;
+ if (ao_usb_epr_ctr_tx(epr))
+ _ao_usb_set_stat_tx(AO_USB_INT_EPR, STM_USB_EPR_STAT_TX_NAK);
+ break;
}
+ return;
+ }
+
+ if (istr & (1 << STM_USB_ISTR_RESET)) {
+ ++reset_count;
+ stm_usb.istr &= ~(1 << STM_USB_ISTR_RESET);
+ ao_usb_ep0_receive |= AO_USB_EP0_GOT_RESET;
+ ao_usb_ep0_handle(ao_usb_ep0_receive);
}
}
+void
+stm_usb_fs_wkup(void)
+{
+ /* USB wakeup, just clear the bit for now */
+ stm_usb.istr &= ~(1 << STM_USB_ISTR_WKUP);
+}
+
/* Queue the current IN buffer for transmission */
static void
_ao_usb_in_send(void)
@@ -951,7 +946,7 @@ ao_usb_getchar(void)
ao_arch_block_interrupts();
while ((c = _ao_usb_pollchar()) == AO_READ_AGAIN)
- ao_sleep(&ao_stdin_ready);
+ ao_sleep(AO_USB_OUT_SLEEP_ADDR);
ao_arch_release_interrupts();
return c;
}
@@ -1071,7 +1066,7 @@ ao_usb_init(void)
ao_usb_enable();
debug ("ao_usb_init\n");
- ao_add_task(&ao_usb_task, ao_usb_ep0, "usb");
+ ao_usb_ep0_state = AO_USB_EP0_IDLE;
#if USB_ECHO
ao_add_task(&ao_usb_echo_task, ao_usb_echo, "usb echo");
#endif
@@ -1079,8 +1074,10 @@ ao_usb_init(void)
ao_cmd_register(&ao_usb_cmds[0]);
#endif
#if !USB_ECHO
+#if USE_USB_STDIO
ao_add_stdio(_ao_usb_pollchar, ao_usb_putchar, ao_usb_flush);
#endif
+#endif
}
#if TX_DBG || RX_DBG
diff --git a/src/stm/stm32l.h b/src/stm/stm32l.h
index 1d636037..47b443a0 100644
--- a/src/stm/stm32l.h
+++ b/src/stm/stm32l.h
@@ -435,6 +435,9 @@ extern struct stm_flash stm_flash;
#define STM_FLASH_PEKEYR_PEKEY1 0x89ABCDEF
#define STM_FLASH_PEKEYR_PEKEY2 0x02030405
+#define STM_FLASH_PRGKEYR_PRGKEY1 0x8C9DAEBF
+#define STM_FLASH_PRGKEYR_PRGKEY2 0x13141516
+
struct stm_rcc {
vuint32_t cr;
vuint32_t icscr;
diff --git a/src/teleballoon-v1.1/ao_teleballoon.c b/src/teleballoon-v1.1/ao_teleballoon.c
index c8bf7760..867e98ab 100644
--- a/src/teleballoon-v1.1/ao_teleballoon.c
+++ b/src/teleballoon-v1.1/ao_teleballoon.c
@@ -52,6 +52,8 @@ main(void)
while (P1_3 == 0)
;
}
+ ao_task_init();
+
ao_timer_init();
ao_adc_init();
ao_beep_init();
diff --git a/src/telebt-v1.0/ao_telebt.c b/src/telebt-v1.0/ao_telebt.c
index 4a50a9d4..935cde7d 100644
--- a/src/telebt-v1.0/ao_telebt.c
+++ b/src/telebt-v1.0/ao_telebt.c
@@ -25,6 +25,9 @@ main(void)
/* Turn on the LED until the system is stable */
ao_led_init(LEDS_AVAILABLE);
ao_led_on(AO_LED_RED);
+
+ ao_task_init();
+
ao_timer_init();
ao_cmd_init();
ao_usb_init();
diff --git a/src/telefire-v0.1/ao_telefire.c b/src/telefire-v0.1/ao_telefire.c
index cc0f668f..afa09e20 100644
--- a/src/telefire-v0.1/ao_telefire.c
+++ b/src/telefire-v0.1/ao_telefire.c
@@ -27,6 +27,8 @@ main(void)
ao_led_init(LEDS_AVAILABLE);
+ ao_task_init();
+
ao_timer_init();
ao_adc_init();
ao_beep_init();
diff --git a/src/telegps-v0.1/Makefile b/src/telegps-v0.1/Makefile
index aae37660..2c41235b 100644
--- a/src/telegps-v0.1/Makefile
+++ b/src/telegps-v0.1/Makefile
@@ -33,6 +33,7 @@ INC = \
#STACK_GUARD_DEF=-DHAS_STACK_GUARD=1
ALTOS_SRC = \
+ ao_boot_chain.c \
ao_interrupt.c \
ao_product.c \
ao_romconfig.c \
diff --git a/src/telelco-v0.1/Makefile b/src/telelco-v0.1/Makefile
index a4a83d02..24083308 100644
--- a/src/telelco-v0.1/Makefile
+++ b/src/telelco-v0.1/Makefile
@@ -30,6 +30,7 @@ INC = \
#PROFILE_DEF=-DAO_PROFILE=1
ALTOS_SRC = \
+ ao_boot_chain.c \
ao_interrupt.c \
ao_product.c \
ao_romconfig.c \
diff --git a/src/telelco-v0.1/ao_telelco.c b/src/telelco-v0.1/ao_telelco.c
index 080a140b..70665ec6 100644
--- a/src/telelco-v0.1/ao_telelco.c
+++ b/src/telelco-v0.1/ao_telelco.c
@@ -36,6 +36,8 @@ main(void)
ao_led_init(LEDS_AVAILABLE);
ao_led_on(AO_LED_GREEN);
+ ao_task_init();
+
ao_timer_init();
ao_spi_init();
diff --git a/src/telemega-v0.1/Makefile b/src/telemega-v0.1/Makefile
index 16393ea0..a72d08f2 100644
--- a/src/telemega-v0.1/Makefile
+++ b/src/telemega-v0.1/Makefile
@@ -45,6 +45,7 @@ INC = \
#STACK_GUARD_DEF=-DHAS_STACK_GUARD=1
ALTOS_SRC = \
+ ao_boot_chain.c \
ao_interrupt.c \
ao_product.c \
ao_romconfig.c \
diff --git a/src/telescience-v0.2/Makefile b/src/telescience-v0.2/Makefile
index fbeeb75c..f16ef268 100644
--- a/src/telescience-v0.2/Makefile
+++ b/src/telescience-v0.2/Makefile
@@ -28,6 +28,7 @@ INC = \
#STACK_GUARD_DEF=-DHAS_STACK_GUARD=1
ALTOS_SRC = \
+ ao_boot_chain.c \
ao_interrupt.c \
ao_product.c \
ao_romconfig.c \
diff --git a/src/telescience-v0.2/ao_telescience.c b/src/telescience-v0.2/ao_telescience.c
index 2fb3186a..74eef8f4 100644
--- a/src/telescience-v0.2/ao_telescience.c
+++ b/src/telescience-v0.2/ao_telescience.c
@@ -29,9 +29,11 @@ main(void)
ao_mpu_init();
#endif
- ao_task_init();
ao_led_init(LEDS_AVAILABLE);
ao_led_on(AO_LED_GREEN);
+
+ ao_task_init();
+
ao_timer_init();
ao_spi_init();
diff --git a/src/teleshield-v0.1/ao_teleshield.c b/src/teleshield-v0.1/ao_teleshield.c
index 4c32817a..d602f646 100644
--- a/src/teleshield-v0.1/ao_teleshield.c
+++ b/src/teleshield-v0.1/ao_teleshield.c
@@ -29,6 +29,7 @@ main(void)
/* Turn on the LED until the system is stable */
ao_led_init(LEDS_AVAILABLE);
ao_led_on(AO_LED_RED);
+ ao_task_init();
ao_timer_init();
ao_cmd_init();
ao_spi_init();