From 4551be8b03a795ece94fd303a1f556c63c0a0096 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 24 Mar 2013 15:14:12 -0700 Subject: altos: Call ao_task_init before initializing any drivers When using task queues, the sleep queues must be initialized before any invocation of ao_wakeup or the OS will crash. Just make sure ao_task_init is always invoked early in the task process to get that done. Signed-off-by: Keith Packard --- src/stm-flash/ao_stm_flash.c | 137 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 src/stm-flash/ao_stm_flash.c (limited to 'src/stm-flash') diff --git a/src/stm-flash/ao_stm_flash.c b/src/stm-flash/ao_stm_flash.c new file mode 100644 index 00000000..df466d85 --- /dev/null +++ b/src/stm-flash/ao_stm_flash.c @@ -0,0 +1,137 @@ +/* + * Copyright © 2011 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; 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 +#include +#include + +void +ao_panic(uint8_t reason) +{ + for (;;); +} + +void +ao_application(void) +{ + ao_boot_reboot(AO_BOOT_APPLICATION_BASE); +} + +static uint32_t +ao_cmd_hex32(void) +{ + __pdata uint8_t r = ao_cmd_lex_error; + int8_t n; + uint32_t v = 0; + + ao_cmd_white(); + for(;;) { + n = ao_cmd_hexchar(ao_cmd_lex_c); + if (n < 0) + break; + v = (v << 4) | n; + r = ao_cmd_success; + ao_cmd_lex(); + } + if (r != ao_cmd_success) + ao_cmd_status = r; + return v; +} + +void +ao_block_erase(void) +{ + uint32_t addr = ao_cmd_hex32(); + uint32_t *p = (uint32_t *) addr; + + ao_flash_erase_page(p); +} + +void +ao_block_write(void) +{ + uint32_t addr = ao_cmd_hex32(); + uint32_t *p = (uint32_t *) addr; + union { + uint8_t data8[256]; + uint32_t data32[64]; + } u; + uint16_t i; + + if (addr < 0x08002000 || 0x08200000 <= addr) { + puts("Invalid address"); + return; + } + for (i = 0; i < 256; i++) + u.data8[i] = i; + ao_flash_page(p, u.data32); +} + +static void +puthex(uint8_t c) +{ + c &= 0xf; + if (c < 10) + c += '0'; + else + c += 'a' - 10; + putchar (c); +} + +void +ao_block_read(void) +{ + uint32_t addr = ao_cmd_hex32(); + uint8_t *p = (uint8_t *) addr; + uint16_t i; + uint8_t c; + + for (i = 0; i < 256; i++) { + c = *p++; + puthex(c); + puthex(c>>4); + if ((i & 0xf) == 0xf) + putchar('\n'); + } +} + +__code struct ao_cmds ao_flash_cmds[] = { + { ao_application, "a\0Switch to application" }, + { ao_block_erase, "e \0Erase block." }, + { ao_block_write, "W \0Write block. 256 binary bytes follow newline" }, + { ao_block_read, "R \0Read block. Returns 256 bytes" }, + { 0, NULL }, +}; + +int +main(void) +{ + ao_clock_init(); + + ao_task_init(); + + ao_timer_init(); +// ao_dma_init(); + ao_cmd_init(); +// ao_exti_init(); + ao_usb_init(); + + ao_cmd_register(&ao_flash_cmds[0]); + ao_start_scheduler(); + return 0; +} -- cgit v1.2.3 From ab99d71c4ba97a28ee463170d10712b2de94dc50 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 28 Apr 2013 23:27:32 -0700 Subject: altos: Add a bunch of .gitignore files Ignore ao_product.h and built binaries Signed-off-by: Keith Packard --- src/stm-flash/.gitignore | 3 +++ src/telelco-v0.2/.gitignore | 2 ++ src/telelco-v0.2/flash-loader/.gitignore | 2 ++ src/telemega-v0.3/.gitignore | 2 ++ 4 files changed, 9 insertions(+) create mode 100644 src/stm-flash/.gitignore create mode 100644 src/telelco-v0.2/.gitignore create mode 100644 src/telelco-v0.2/flash-loader/.gitignore create mode 100644 src/telemega-v0.3/.gitignore (limited to 'src/stm-flash') diff --git a/src/stm-flash/.gitignore b/src/stm-flash/.gitignore new file mode 100644 index 00000000..c046bc2a --- /dev/null +++ b/src/stm-flash/.gitignore @@ -0,0 +1,3 @@ +stm-flash*.elf +ao_product.h +altos-flash*.elf diff --git a/src/telelco-v0.2/.gitignore b/src/telelco-v0.2/.gitignore new file mode 100644 index 00000000..a32ec26e --- /dev/null +++ b/src/telelco-v0.2/.gitignore @@ -0,0 +1,2 @@ +ao_product.h +telelco*.elf diff --git a/src/telelco-v0.2/flash-loader/.gitignore b/src/telelco-v0.2/flash-loader/.gitignore new file mode 100644 index 00000000..a32ec26e --- /dev/null +++ b/src/telelco-v0.2/flash-loader/.gitignore @@ -0,0 +1,2 @@ +ao_product.h +telelco*.elf diff --git a/src/telemega-v0.3/.gitignore b/src/telemega-v0.3/.gitignore new file mode 100644 index 00000000..e67759a2 --- /dev/null +++ b/src/telemega-v0.3/.gitignore @@ -0,0 +1,2 @@ +ao_product.h +telemega-*.elf -- cgit v1.2.3 From a6887032b4d217bca5236ea15389218f10d69545 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 24 Feb 2013 00:18:14 -0800 Subject: Add STM self-flashing loader This allows the real application to get loaded at 0x2000 and jumps to that at startup time if the boot pin is set appropriately Signed-off-by: Keith Packard --- src/stm-flash/Makefile | 60 +++++++++++++++++++++++++++++++++++++ src/stm-flash/ao_pins.h | 71 ++++++++++++++++++++++++++++++++++++++++++++ src/stm-flash/ao_stm_flash.c | 28 +++++++++++++++++ src/stm/ao_arch_funcs.h | 23 ++++++++++++-- src/stm/ao_interrupt.c | 40 +++++++++++++++++++++++++ 5 files changed, 219 insertions(+), 3 deletions(-) create mode 100644 src/stm-flash/Makefile create mode 100644 src/stm-flash/ao_pins.h (limited to 'src/stm-flash') diff --git a/src/stm-flash/Makefile b/src/stm-flash/Makefile new file mode 100644 index 00000000..fbc6603d --- /dev/null +++ b/src/stm-flash/Makefile @@ -0,0 +1,60 @@ +# +# 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_product.c \ + ao_romconfig.c \ + ao_task.c \ + ao_timer.c \ + ao_mutex.c \ + ao_usb_stm.c \ + ao_stdio.c \ + ao_cmd.c + +PRODUCT=StmFlash-v0.0 +PRODUCT_DEF=-DSTM_FLASH +IDPRODUCT=0x000a + +CFLAGS = $(PRODUCT_DEF) $(STM_CFLAGS) -g -Os + +PROG=stm-flash + +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..b232f373 --- /dev/null +++ b/src/stm-flash/ao_pins.h @@ -0,0 +1,71 @@ +/* + * Copyright © 2013 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; 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 + +#define AO_HSE 8000000 + +/* 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_STDIN 1 +#define HAS_BEEP 0 + +#define PACKET_HAS_SLAVE 0 + +#define LED_PORT_ENABLE STM_RCC_AHBENR_GPIOCEN +#define LED_PORT (&stm_gpioc) +#define LED_PIN_RED 8 +#define LED_PIN_GREEN 9 +#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 AO_BOOT_APPLICATION_GPIO stm_gpiob +#define AO_BOOT_APPLICATION_PIN 5 +#define AO_BOOT_APPLICATION_VALUE 0 +#define AO_BOOT_APPLICATION_MODE AO_EXTI_MODE_PULL_UP +#define AO_BOOT_APPLICATION_BASE 0x2000 + +#endif /* _AO_PINS_H_ */ diff --git a/src/stm-flash/ao_stm_flash.c b/src/stm-flash/ao_stm_flash.c index df466d85..81ae86df 100644 --- a/src/stm-flash/ao_stm_flash.c +++ b/src/stm-flash/ao_stm_flash.c @@ -17,6 +17,7 @@ #include "ao.h" #include +<<<<<<< HEAD #include #include @@ -117,21 +118,48 @@ __code struct ao_cmds ao_flash_cmds[] = { { ao_block_read, "R \0Read block. Returns 256 bytes" }, { 0, NULL }, }; +======= + +void +ao_panic(uint8_t c) +{ +} + +void +ao_test(void) +{ + char c; + + for (;;) { + c = ao_usb_getchar(); + ao_usb_putchar(c); + ao_usb_flush(); + } +} + +struct ao_task ao_test_task; +>>>>>>> 5187bb4... Add STM self-flashing loader int main(void) { ao_clock_init(); +<<<<<<< HEAD ao_task_init(); +======= +>>>>>>> 5187bb4... Add STM self-flashing loader ao_timer_init(); // ao_dma_init(); ao_cmd_init(); // ao_exti_init(); ao_usb_init(); +<<<<<<< HEAD ao_cmd_register(&ao_flash_cmds[0]); +======= +>>>>>>> 5187bb4... Add STM self-flashing loader ao_start_scheduler(); return 0; } diff --git a/src/stm/ao_arch_funcs.h b/src/stm/ao_arch_funcs.h index f3d68202..2c0f173c 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); \ diff --git a/src/stm/ao_interrupt.c b/src/stm/ao_interrupt.c index a423d8b1..12763a30 100644 --- a/src/stm/ao_interrupt.c +++ b/src/stm/ao_interrupt.c @@ -36,7 +36,47 @@ void stm_ignore_isr(void) { } +const void *stm_interrupt_vector[]; + +#define BOOT_FETCH(o) (*((uint32_t *) (AO_BOOT_APPLICATION_BASE + (o)))) + +#ifdef AO_BOOT_APPLICATION_PIN +#include +#endif + void start(void) { +#ifdef AO_BOOT_APPLICATION_PIN + 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) + { + uint32_t sp; + uint32_t pc; + + sp = BOOT_FETCH(0); + pc = BOOT_FETCH(4); + asm ("mov sp, %0" : : "r" (sp)); + asm ("mov lr, %0" : : "r" (pc)); + asm ("bx lr"); + } +#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(); -- cgit v1.2.3 From c9c35b100c3fcae661501d2bf89eedc7fceb2e1c Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 10 Mar 2013 21:02:59 -0700 Subject: altos: Make stm-flash capable of switching to application This shrinks the base OS load down a bit as well so that stm-flash fits comfortably in the first 8kB of memory. Signed-off-by: Keith Packard --- src/core/ao_cmd.c | 11 +++++++ src/core/ao_task.c | 2 ++ src/core/ao_task.h | 4 +++ src/stm-demo/Makefile | 2 +- src/stm-flash/ao_pins.h | 13 +++++--- src/stm-flash/ao_stm_flash.c | 28 +---------------- src/stm/altos-application.ld | 72 ++++++++++++++++++++++++++++++++++++++++++++ src/stm/altos-loader.ld | 72 ++++++++++++++++++++++++++++++++++++++++++++ src/stm/ao_boot.h | 24 +++++++++++++++ src/stm/ao_interrupt.c | 44 +++++++++++++++++++++------ 10 files changed, 229 insertions(+), 43 deletions(-) create mode 100644 src/stm/altos-application.ld create mode 100644 src/stm/altos-loader.ld create mode 100644 src/stm/ao_boot.h (limited to 'src/stm-flash') diff --git a/src/core/ao_cmd.c b/src/core/ao_cmd.c index 6eed08d9..7da2384f 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; @@ -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 @@ -382,10 +389,14 @@ __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 { 0, NULL }, }; diff --git a/src/core/ao_task.c b/src/core/ao_task.c index c24c9929..0aad6508 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 #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/stm-demo/Makefile b/src/stm-demo/Makefile index 3b1b671b..ab12f47b 100644 --- a/src/stm-demo/Makefile +++ b/src/stm-demo/Makefile @@ -53,7 +53,7 @@ OBJ=$(SRC:.c=.o) all: $(PROG) -LDFLAGS=-L../stm -Wl,-Taltos.ld +LDFLAGS=-L../stm -Wl,-Taltos-application.ld $(PROG): Makefile $(OBJ) $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(OBJ) $(SAT_CLIB) -lgcc diff --git a/src/stm-flash/ao_pins.h b/src/stm-flash/ao_pins.h index b232f373..ca53d844 100644 --- a/src/stm-flash/ao_pins.h +++ b/src/stm-flash/ao_pins.h @@ -20,7 +20,9 @@ #define HAS_TASK_QUEUE 0 -#define AO_HSE 8000000 +/* 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 @@ -61,11 +63,12 @@ #define AO_TICK_SIGNED int32_t #define HAS_TASK_INFO 0 +#define HAS_VERSION 0 -#define AO_BOOT_APPLICATION_GPIO stm_gpiob -#define AO_BOOT_APPLICATION_PIN 5 -#define AO_BOOT_APPLICATION_VALUE 0 -#define AO_BOOT_APPLICATION_MODE AO_EXTI_MODE_PULL_UP +#define AO_BOOT_APPLICATION_GPIO stm_gpioa +#define AO_BOOT_APPLICATION_PIN 0 +#define AO_BOOT_APPLICATION_VALUE 1 +#define AO_BOOT_APPLICATION_MODE 0 #define AO_BOOT_APPLICATION_BASE 0x2000 #endif /* _AO_PINS_H_ */ diff --git a/src/stm-flash/ao_stm_flash.c b/src/stm-flash/ao_stm_flash.c index 81ae86df..e2d7ec65 100644 --- a/src/stm-flash/ao_stm_flash.c +++ b/src/stm-flash/ao_stm_flash.c @@ -17,7 +17,6 @@ #include "ao.h" #include -<<<<<<< HEAD #include #include @@ -118,48 +117,23 @@ __code struct ao_cmds ao_flash_cmds[] = { { ao_block_read, "R \0Read block. Returns 256 bytes" }, { 0, NULL }, }; -======= -void -ao_panic(uint8_t c) -{ -} - -void -ao_test(void) -{ - char c; - - for (;;) { - c = ao_usb_getchar(); - ao_usb_putchar(c); - ao_usb_flush(); - } -} - -struct ao_task ao_test_task; ->>>>>>> 5187bb4... Add STM self-flashing loader int main(void) { ao_clock_init(); -<<<<<<< HEAD ao_task_init(); -======= ->>>>>>> 5187bb4... Add STM self-flashing loader ao_timer_init(); // ao_dma_init(); ao_cmd_init(); // ao_exti_init(); ao_usb_init(); -<<<<<<< HEAD ao_cmd_register(&ao_flash_cmds[0]); -======= ->>>>>>> 5187bb4... Add STM self-flashing loader + ao_cmd_register(&ao_flash_cmds[0]); ao_start_scheduler(); return 0; } diff --git a/src/stm/altos-application.ld b/src/stm/altos-application.ld new file mode 100644 index 00000000..63a3be00 --- /dev/null +++ b/src/stm/altos-application.ld @@ -0,0 +1,72 @@ +/* + * Copyright © 2012 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; 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 (rx) : ORIGIN = 0x08002000, LENGTH = 120K + ram (!w) : ORIGIN = 0x20000000, LENGTH = 16K +} + +INCLUDE registers.ld + +EXTERN (stm_interrupt_vector) + +SECTIONS { + /* + * Rom contents + */ + + .text ORIGIN(rom) : { + __text_start__ = .; + *(.interrupt) /* Interrupt vectors */ + + . = ORIGIN(rom) + 0x100; + + ao_romconfig.o(.romconfig*) + ao_product.o(.romconfig*) + + *(.text*) /* Executable code */ + *(.rodata*) /* Constants */ + + } > rom + + .ARM.exidx : { + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + __text_end__ = .; + } > rom + + /* Data -- relocated to RAM, but written to ROM + */ + .data ORIGIN(ram) : AT (ADDR(.ARM.exidx) + SIZEOF (.ARM.exidx)) { + __data_start__ = .; + *(.data) /* initialized data */ + __data_end__ = .; + __bss_start__ = .; + } >ram + + .bss : { + *(.bss) + *(COMMON) + __bss_end__ = .; + } >ram + + PROVIDE(__stack__ = ORIGIN(ram) + LENGTH(ram)); + PROVIDE(end = .); +} + +ENTRY(start); + + diff --git a/src/stm/altos-loader.ld b/src/stm/altos-loader.ld new file mode 100644 index 00000000..2d71b4ee --- /dev/null +++ b/src/stm/altos-loader.ld @@ -0,0 +1,72 @@ +/* + * Copyright © 2012 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; 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 (rx) : ORIGIN = 0x08000000, LENGTH = 8K + ram (!w) : ORIGIN = 0x20000000, LENGTH = 16K +} + +INCLUDE registers.ld + +EXTERN (stm_interrupt_vector) + +SECTIONS { + /* + * Rom contents + */ + + .text ORIGIN(rom) : { + __text_start__ = .; + *(.interrupt) /* Interrupt vectors */ + + . = ORIGIN(rom) + 0x100; + + ao_romconfig.o(.romconfig*) + ao_product.o(.romconfig*) + + *(.text*) /* Executable code */ + *(.rodata*) /* Constants */ + + } > rom + + .ARM.exidx : { + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + __text_end__ = .; + } > rom + + /* Data -- relocated to RAM, but written to ROM + */ + .data ORIGIN(ram) : AT (ADDR(.ARM.exidx) + SIZEOF (.ARM.exidx)) { + __data_start__ = .; + *(.data) /* initialized data */ + __data_end__ = .; + __bss_start__ = .; + } >ram + + .bss : { + *(.bss) + *(COMMON) + __bss_end__ = .; + } >ram + + PROVIDE(__stack__ = ORIGIN(ram) + LENGTH(ram)); + PROVIDE(end = .); +} + +ENTRY(start); + + diff --git a/src/stm/ao_boot.h b/src/stm/ao_boot.h new file mode 100644 index 00000000..863d8e05 --- /dev/null +++ b/src/stm/ao_boot.h @@ -0,0 +1,24 @@ +/* + * Copyright © 2013 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; 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_reboot_application(void); + +#endif /* _AO_BOOT_H_ */ diff --git a/src/stm/ao_interrupt.c b/src/stm/ao_interrupt.c index 12763a30..9e756219 100644 --- a/src/stm/ao_interrupt.c +++ b/src/stm/ao_interrupt.c @@ -42,12 +42,45 @@ const void *stm_interrupt_vector[]; #ifdef AO_BOOT_APPLICATION_PIN #include + +#define AO_BOOT_APPLICATION 0x5a5aa5a5 +#define AO_BOOT_APPLICATION_CHECK 0xc3c33c3c + +static uint32_t ao_boot_application; +static uint32_t ao_boot_application_check; + +static void +ao_boot_chain(void) { + uint32_t sp; + uint32_t pc; + + sp = BOOT_FETCH(0); + pc = BOOT_FETCH(4); + asm ("mov sp, %0" : : "r" (sp)); + asm ("mov lr, %0" : : "r" (pc)); + asm ("bx lr"); +} + +void +ao_reboot_application(void) +{ + ao_boot_application = AO_BOOT_APPLICATION; + ao_boot_application_check = AO_BOOT_APPLICATION_CHECK; + ao_arch_reboot(); +} + #endif void start(void) { #ifdef AO_BOOT_APPLICATION_PIN uint16_t v; + if (ao_boot_application == AO_BOOT_APPLICATION && + ao_boot_application_check == AO_BOOT_APPLICATION_CHECK) { + ao_boot_application = 0; + ao_boot_application_check = 0; + ao_boot_chain(); + } /* Enable power interface clock */ stm_rcc.apb1enr |= (1 << STM_RCC_APB1ENR_PWREN); @@ -63,16 +96,7 @@ void start(void) { ao_disable_port(&AO_BOOT_APPLICATION_GPIO); stm_rcc.apb1enr &= ~(1 << STM_RCC_APB1ENR_PWREN); if (v == AO_BOOT_APPLICATION_VALUE) - { - uint32_t sp; - uint32_t pc; - - sp = BOOT_FETCH(0); - pc = BOOT_FETCH(4); - asm ("mov sp, %0" : : "r" (sp)); - asm ("mov lr, %0" : : "r" (pc)); - asm ("bx lr"); - } + ao_boot_chain(); #endif /* Set interrupt vector table offset */ -- cgit v1.2.3 From 56a7cbbf51f5c9ebbfe17d1cc30ed807572af3cc Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 11 Mar 2013 00:01:52 -0700 Subject: altos: Add program flash function And get it loaded to RAM so it can execute correctly. Nothing calls it yet... Signed-off-by: Keith Packard --- src/stm-flash/Makefile | 1 + src/stm/altos-loader.ld | 31 +++++++++------ src/stm/ao_flash_stm.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++++ src/stm/ao_flash_stm.h | 24 +++++++++++ src/stm/stm32l.h | 3 ++ 5 files changed, 151 insertions(+), 11 deletions(-) create mode 100644 src/stm/ao_flash_stm.c create mode 100644 src/stm/ao_flash_stm.h (limited to 'src/stm-flash') diff --git a/src/stm-flash/Makefile b/src/stm-flash/Makefile index fbc6603d..3c7b4966 100644 --- a/src/stm-flash/Makefile +++ b/src/stm-flash/Makefile @@ -24,6 +24,7 @@ ALTOS_SRC = \ ao_mutex.c \ ao_usb_stm.c \ ao_stdio.c \ + ao_flash_stm.c \ ao_cmd.c PRODUCT=StmFlash-v0.0 diff --git a/src/stm/altos-loader.ld b/src/stm/altos-loader.ld index 2d71b4ee..50a425c7 100644 --- a/src/stm/altos-loader.ld +++ b/src/stm/altos-loader.ld @@ -16,8 +16,8 @@ */ MEMORY { - rom (rx) : ORIGIN = 0x08000000, LENGTH = 8K - ram (!w) : ORIGIN = 0x20000000, LENGTH = 16K + rom : ORIGIN = 0x08000000, LENGTH = 8K + ram : ORIGIN = 0x20000000, LENGTH = 16K } INCLUDE registers.ld @@ -29,7 +29,7 @@ SECTIONS { * Rom contents */ - .text ORIGIN(rom) : { + .text : { __text_start__ = .; *(.interrupt) /* Interrupt vectors */ @@ -38,26 +38,35 @@ SECTIONS { ao_romconfig.o(.romconfig*) ao_product.o(.romconfig*) - *(.text*) /* Executable code */ - *(.rodata*) /* Constants */ + *(.text) /* Executable code */ + *(.rodata) /* Constants */ } > rom .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) - __text_end__ = .; } > rom + __text_end__ = .; + + /* Functions placed in RAM (required for flashing) */ + .textram : { + __text_ram_start = .; + __data_start__ = .; + *(.text.ram) + . = ALIGN(4); + } >ram AT>rom + __text_ram_end = .; /* Data -- relocated to RAM, but written to ROM */ - .data ORIGIN(ram) : AT (ADDR(.ARM.exidx) + SIZEOF (.ARM.exidx)) { - __data_start__ = .; + .data : { *(.data) /* initialized data */ - __data_end__ = .; - __bss_start__ = .; - } >ram + . = ALIGN (4); + } >ram AT>rom + __data_end__ = .; .bss : { + __bss_start__ = .; *(.bss) *(COMMON) __bss_end__ = .; diff --git a/src/stm/ao_flash_stm.c b/src/stm/ao_flash_stm.c new file mode 100644 index 00000000..b3ef6a62 --- /dev/null +++ b/src/stm/ao_flash_stm.c @@ -0,0 +1,103 @@ +/* + * Copyright © 2013 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; 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 +#include + +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; +} + +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; +} + +static void +ao_flash_wait_bsy(void) +{ + while (stm_flash.sr & (1 << STM_FLASH_SR_BSY)) + ; +} + +static void +ao_flash_erase_page(uint32_t *page) +{ + ao_flash_pecr_unlock(); + ao_flash_pgr_unlock(); + + stm_flash.pecr |= (1 << STM_FLASH_PECR_ERASE); + stm_flash.pecr |= (1 << STM_FLASH_PECR_PROG); + + ao_flash_wait_bsy(); + + *page = 0x00000000; +} + +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++; +} + +void +ao_flash_page(uint32_t *page, uint32_t *src) +{ + uint8_t h; + + ao_flash_erase_page(page); + for (h = 0; h < 2; h++) { + ao_flash_pecr_unlock(); + ao_flash_pgr_unlock(); + _ao_flash_half_page(page, src); + page += 32; + src += 32; + } +} diff --git a/src/stm/ao_flash_stm.h b/src/stm/ao_flash_stm.h new file mode 100644 index 00000000..b4067d8d --- /dev/null +++ b/src/stm/ao_flash_stm.h @@ -0,0 +1,24 @@ +/* + * Copyright © 2013 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; 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_page(uint32_t *page, uint32_t *src); + +#endif /* _AO_FLASH_STM_H_ */ diff --git a/src/stm/stm32l.h b/src/stm/stm32l.h index 5c0748a6..63bde0f8 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; -- cgit v1.2.3 From b1a43ce313c85cb7f8f16f7f0647d9d4320ba692 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 11 Mar 2013 13:21:04 -0700 Subject: altos: Clean up boot loader support Split out code into separate files. Add support for getting back to boot loader from application. Signed-off-by: Keith Packard --- src/stm-demo/Makefile | 1 + src/stm-demo/ao_demo.c | 9 +++++ src/stm-demo/ao_pins.h | 2 ++ src/stm-flash/Makefile | 2 ++ src/stm-flash/ao_pins.h | 5 ++- src/stm-flash/ao_stm_flash.c | 84 +------------------------------------------- src/stm/altos-application.ld | 17 +++++++-- src/stm/altos-loader.ld | 13 ++++++- src/stm/ao_boot.h | 11 +++++- src/stm/ao_boot_chain.c | 62 ++++++++++++++++++++++++++++++++ src/stm/ao_boot_pin.c | 43 +++++++++++++++++++++++ src/stm/ao_interrupt.c | 64 ++++----------------------------- 12 files changed, 166 insertions(+), 147 deletions(-) create mode 100644 src/stm/ao_boot_chain.c create mode 100644 src/stm/ao_boot_pin.c (limited to 'src/stm-flash') diff --git a/src/stm-demo/Makefile b/src/stm-demo/Makefile index ab12f47b..e6cd55e4 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 \ diff --git a/src/stm-demo/ao_demo.c b/src/stm-demo/ao_demo.c index 9ee0be03..ec572fdc 100644 --- a/src/stm-demo/ao_demo.c +++ b/src/stm-demo/ao_demo.c @@ -20,6 +20,7 @@ #include #include #include +#include struct ao_task demo_task; @@ -168,6 +169,13 @@ ao_event(void) } +static void +ao_boot_loader(void) +{ + flush(); + ao_boot_reboot((uint32_t *) 0); +} + __code struct ao_cmds ao_demo_cmds[] = { { ao_dma_test, "D\0DMA test" }, { ao_spi_write, "W\0SPI write" }, @@ -175,6 +183,7 @@ __code struct ao_cmds ao_demo_cmds[] = { { ao_i2c_write, "i\0I2C write" }, { ao_temp, "t\0Show temp" }, { ao_event, "e\0Monitor event queue" }, + { ao_boot_loader, "L\0Reboot to boot loader" }, { 0, NULL } }; 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 index 3c7b4966..e4a2f321 100644 --- a/src/stm-flash/Makefile +++ b/src/stm-flash/Makefile @@ -17,6 +17,8 @@ INC = \ # ALTOS_SRC = \ ao_interrupt.c \ + ao_boot_chain.c \ + ao_boot_pin.c \ ao_product.c \ ao_romconfig.c \ ao_task.c \ diff --git a/src/stm-flash/ao_pins.h b/src/stm-flash/ao_pins.h index ca53d844..382ef353 100644 --- a/src/stm-flash/ao_pins.h +++ b/src/stm-flash/ao_pins.h @@ -65,10 +65,13 @@ #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_gpioa #define AO_BOOT_APPLICATION_PIN 0 #define AO_BOOT_APPLICATION_VALUE 1 #define AO_BOOT_APPLICATION_MODE 0 -#define AO_BOOT_APPLICATION_BASE 0x2000 +#define AO_BOOT_APPLICATION_BASE ((uint32_t *) 0x2000) #endif /* _AO_PINS_H_ */ diff --git a/src/stm-flash/ao_stm_flash.c b/src/stm-flash/ao_stm_flash.c index e2d7ec65..2988a937 100644 --- a/src/stm-flash/ao_stm_flash.c +++ b/src/stm-flash/ao_stm_flash.c @@ -32,89 +32,8 @@ ao_application(void) ao_boot_reboot(AO_BOOT_APPLICATION_BASE); } -static uint32_t -ao_cmd_hex32(void) -{ - __pdata uint8_t r = ao_cmd_lex_error; - int8_t n; - uint32_t v = 0; - - ao_cmd_white(); - for(;;) { - n = ao_cmd_hexchar(ao_cmd_lex_c); - if (n < 0) - break; - v = (v << 4) | n; - r = ao_cmd_success; - ao_cmd_lex(); - } - if (r != ao_cmd_success) - ao_cmd_status = r; - return v; -} - -void -ao_block_erase(void) -{ - uint32_t addr = ao_cmd_hex32(); - uint32_t *p = (uint32_t *) addr; - - ao_flash_erase_page(p); -} - -void -ao_block_write(void) -{ - uint32_t addr = ao_cmd_hex32(); - uint32_t *p = (uint32_t *) addr; - union { - uint8_t data8[256]; - uint32_t data32[64]; - } u; - uint16_t i; - - if (addr < 0x08002000 || 0x08200000 <= addr) { - puts("Invalid address"); - return; - } - for (i = 0; i < 256; i++) - u.data8[i] = i; - ao_flash_page(p, u.data32); -} - -static void -puthex(uint8_t c) -{ - c &= 0xf; - if (c < 10) - c += '0'; - else - c += 'a' - 10; - putchar (c); -} - -void -ao_block_read(void) -{ - uint32_t addr = ao_cmd_hex32(); - uint8_t *p = (uint8_t *) addr; - uint16_t i; - uint8_t c; - - for (i = 0; i < 256; i++) { - c = *p++; - puthex(c); - puthex(c>>4); - if ((i & 0xf) == 0xf) - putchar('\n'); - } -} - __code struct ao_cmds ao_flash_cmds[] = { - { ao_application, "a\0Switch to application" }, - { ao_block_erase, "e \0Erase block." }, - { ao_block_write, "W \0Write block. 256 binary bytes follow newline" }, - { ao_block_read, "R \0Read block. Returns 256 bytes" }, + { ao_application, "A\0Switch to application" }, { 0, NULL }, }; @@ -132,7 +51,6 @@ main(void) // ao_exti_init(); ao_usb_init(); - ao_cmd_register(&ao_flash_cmds[0]); ao_cmd_register(&ao_flash_cmds[0]); ao_start_scheduler(); return 0; diff --git a/src/stm/altos-application.ld b/src/stm/altos-application.ld index 63a3be00..5110da84 100644 --- a/src/stm/altos-application.ld +++ b/src/stm/altos-application.ld @@ -48,16 +48,27 @@ SECTIONS { __text_end__ = .; } > rom + /* 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 : { + __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 */ __data_end__ = .; - __bss_start__ = .; - } >ram + } >ram AT>rom .bss : { + __bss_start__ = .; *(.bss) *(COMMON) __bss_end__ = .; diff --git a/src/stm/altos-loader.ld b/src/stm/altos-loader.ld index 50a425c7..2e36dce9 100644 --- a/src/stm/altos-loader.ld +++ b/src/stm/altos-loader.ld @@ -48,9 +48,20 @@ SECTIONS { } > 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 : { + __boot_start__ = .; + *(.boot) + . = ALIGN(4); + __boot_end__ = .; + } >ram + /* Functions placed in RAM (required for flashing) */ .textram : { - __text_ram_start = .; + __text_ram_start__ = .; __data_start__ = .; *(.text.ram) . = ALIGN(4); diff --git a/src/stm/ao_boot.h b/src/stm/ao_boot.h index 863d8e05..3e8c50ba 100644 --- a/src/stm/ao_boot.h +++ b/src/stm/ao_boot.h @@ -19,6 +19,15 @@ #define _AO_BOOT_H_ void -ao_reboot_application(void); +ao_boot_chain(uint32_t *base); + +void +ao_boot_check_pin(void); + +void +ao_boot_check_chain(void); + +void +ao_boot_reboot(uint32_t *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..9c63272b --- /dev/null +++ b/src/stm/ao_boot_chain.c @@ -0,0 +1,62 @@ +/* + * Copyright © 2013 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; 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 +#include + +void +ao_boot_chain(uint32_t *base) +{ + uint32_t sp; + uint32_t pc; + + sp = base[0]; + pc = base[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; + +void +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; + ao_boot_chain(ao_boot.base); + } +} + +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 + * + * 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 +#include +#include + +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_interrupt.c b/src/stm/ao_interrupt.c index 9e756219..49156285 100644 --- a/src/stm/ao_interrupt.c +++ b/src/stm/ao_interrupt.c @@ -18,6 +18,7 @@ #include #include "stm32l.h" #include +#include extern void main(void); extern char __stack__; @@ -38,67 +39,14 @@ void stm_ignore_isr(void) const void *stm_interrupt_vector[]; -#define BOOT_FETCH(o) (*((uint32_t *) (AO_BOOT_APPLICATION_BASE + (o)))) - -#ifdef AO_BOOT_APPLICATION_PIN -#include - -#define AO_BOOT_APPLICATION 0x5a5aa5a5 -#define AO_BOOT_APPLICATION_CHECK 0xc3c33c3c - -static uint32_t ao_boot_application; -static uint32_t ao_boot_application_check; - -static void -ao_boot_chain(void) { - uint32_t sp; - uint32_t pc; - - sp = BOOT_FETCH(0); - pc = BOOT_FETCH(4); - asm ("mov sp, %0" : : "r" (sp)); - asm ("mov lr, %0" : : "r" (pc)); - asm ("bx lr"); -} - -void -ao_reboot_application(void) +void start(void) { - ao_boot_application = AO_BOOT_APPLICATION; - ao_boot_application_check = AO_BOOT_APPLICATION_CHECK; - ao_arch_reboot(); -} - +#ifdef AO_BOOT_CHAIN + ao_boot_check_chain(); #endif - -void start(void) { -#ifdef AO_BOOT_APPLICATION_PIN - uint16_t v; - - if (ao_boot_application == AO_BOOT_APPLICATION && - ao_boot_application_check == AO_BOOT_APPLICATION_CHECK) { - ao_boot_application = 0; - ao_boot_application_check = 0; - ao_boot_chain(); - } - /* 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(); +#ifdef AO_BOOT_PIN + ao_boot_check_pin(); #endif - /* Set interrupt vector table offset */ stm_nvic.vto = (uint32_t) &stm_interrupt_vector; memcpy(&__data_start__, &__text_end__, &__data_end__ - &__data_start__); -- cgit v1.2.3 From 4bc55ee8fabc9f4c997c2a515d74baada590c93e Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 11 Mar 2013 18:14:28 -0700 Subject: altos: Add actual flashing functions to stm-flash app Signed-off-by: Keith Packard --- src/stm-flash/ao_stm_flash.c | 50 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'src/stm-flash') diff --git a/src/stm-flash/ao_stm_flash.c b/src/stm-flash/ao_stm_flash.c index 2988a937..4a91ef1f 100644 --- a/src/stm-flash/ao_stm_flash.c +++ b/src/stm-flash/ao_stm_flash.c @@ -32,8 +32,58 @@ ao_application(void) ao_boot_reboot(AO_BOOT_APPLICATION_BASE); } +static uint32_t +ao_cmd_hex32(void) +{ + __pdata uint8_t r = ao_cmd_lex_error; + int8_t n; + uint32_t v = 0; + + ao_cmd_white(); + for(;;) { + n = ao_cmd_hexchar(ao_cmd_lex_c); + if (n < 0) + break; + v = (v << 4) | n; + r = ao_cmd_success; + ao_cmd_lex(); + } + if (r != ao_cmd_success) + ao_cmd_status = r; + return v; +} + +void +ao_block_write(void) +{ + uint32_t addr = ao_cmd_hex32(); + uint32_t *p = (uint32_t *) addr; + union { + uint8_t data8[256]; + uint32_t data32[64]; + } u; + uint16_t i; + + for (i = 0; i < 256; i++) + u.data8[i] = getchar(); + ao_flash_page(p, u.data32); +} + +void +ao_block_read(void) +{ + uint32_t addr = ao_cmd_hex32(); + uint8_t *p = (uint8_t *) addr; + uint16_t i; + + for (i = 0; i < 256; i++) + putchar(*p++); +} + __code struct ao_cmds ao_flash_cmds[] = { { ao_application, "A\0Switch to application" }, + { ao_block_write, "W \0Write block. 256 binary bytes follow newline" }, + { ao_block_read, "R \0Read block. Returns 256 bytes" }, { 0, NULL }, }; -- cgit v1.2.3 From efc0898d824ebd0abe0b088ed9a8b40c34623ab7 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 23 Mar 2013 02:15:35 -0700 Subject: altos: Fix up stm-flash output file name. Use discovery LED pins Include the AltOS version in the file name, just like any other AltOS program. Switch the LEDs to the discovery board as we're using that. Eventually, we'll stop using LEDs entirely. Signed-off-by: Keith Packard --- src/stm-flash/Makefile | 2 +- src/stm-flash/ao_pins.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/stm-flash') diff --git a/src/stm-flash/Makefile b/src/stm-flash/Makefile index e4a2f321..46bc61af 100644 --- a/src/stm-flash/Makefile +++ b/src/stm-flash/Makefile @@ -35,7 +35,7 @@ IDPRODUCT=0x000a CFLAGS = $(PRODUCT_DEF) $(STM_CFLAGS) -g -Os -PROG=stm-flash +PROG=stm-flash-$(VERSION).elf SRC=$(ALTOS_SRC) ao_stm_flash.c OBJ=$(SRC:.c=.o) diff --git a/src/stm-flash/ao_pins.h b/src/stm-flash/ao_pins.h index 382ef353..048fc828 100644 --- a/src/stm-flash/ao_pins.h +++ b/src/stm-flash/ao_pins.h @@ -51,9 +51,9 @@ #define PACKET_HAS_SLAVE 0 #define LED_PORT_ENABLE STM_RCC_AHBENR_GPIOCEN -#define LED_PORT (&stm_gpioc) -#define LED_PIN_RED 8 -#define LED_PIN_GREEN 9 +#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) -- cgit v1.2.3 From 5db4d5e5b1272b161102e889e65b9c7bc7928352 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 23 Mar 2013 02:23:03 -0700 Subject: altos: Add erase command to stm-flash app. Validate addresses. This also leaves the code writing fixed values and printing read data in ascii instead of binary. Useful for debugging, will want changing for the product. Signed-off-by: Keith Packard --- src/stm-flash/ao_stm_flash.c | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) (limited to 'src/stm-flash') diff --git a/src/stm-flash/ao_stm_flash.c b/src/stm-flash/ao_stm_flash.c index 4a91ef1f..51856b46 100644 --- a/src/stm-flash/ao_stm_flash.c +++ b/src/stm-flash/ao_stm_flash.c @@ -53,6 +53,15 @@ ao_cmd_hex32(void) return v; } +void +ao_block_erase(void) +{ + uint32_t addr = ao_cmd_hex32(); + uint32_t *p = (uint32_t *) addr; + + ao_flash_erase_page(p); +} + void ao_block_write(void) { @@ -64,24 +73,46 @@ ao_block_write(void) } u; uint16_t i; + if (addr < 0x08002000 || 0x08200000 <= addr) { + puts("Invalid address"); + return; + } for (i = 0; i < 256; i++) - u.data8[i] = getchar(); + u.data8[i] = i; ao_flash_page(p, u.data32); } +static void +puthex(uint8_t c) +{ + c &= 0xf; + if (c < 10) + c += '0'; + else + c += 'a' - 10; + putchar (c); +} + void ao_block_read(void) { uint32_t addr = ao_cmd_hex32(); uint8_t *p = (uint8_t *) addr; uint16_t i; + uint8_t c; - for (i = 0; i < 256; i++) - putchar(*p++); + for (i = 0; i < 256; i++) { + c = *p++; + puthex(c); + puthex(c>>4); + if ((i & 0xf) == 0xf) + putchar('\n'); + } } __code struct ao_cmds ao_flash_cmds[] = { - { ao_application, "A\0Switch to application" }, + { ao_application, "a\0Switch to application" }, + { ao_block_erase, "e \0Erase block." }, { ao_block_write, "W \0Write block. 256 binary bytes follow newline" }, { ao_block_read, "R \0Read block. Returns 256 bytes" }, { 0, NULL }, -- cgit v1.2.3 From 9362d400d06aa3badfc826d8edbd7c55406b4f7d Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 24 Mar 2013 15:24:42 -0700 Subject: altos: Switch ao_stm_flash to read/write binary blocks Change from development testing code to something that actually reads and writes data from the USB link. Signed-off-by: Keith Packard --- src/stm-flash/ao_stm_flash.c | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) (limited to 'src/stm-flash') diff --git a/src/stm-flash/ao_stm_flash.c b/src/stm-flash/ao_stm_flash.c index 51856b46..344bceb9 100644 --- a/src/stm-flash/ao_stm_flash.c +++ b/src/stm-flash/ao_stm_flash.c @@ -74,11 +74,11 @@ ao_block_write(void) uint16_t i; if (addr < 0x08002000 || 0x08200000 <= addr) { - puts("Invalid address"); + ao_put_string("Invalid address\n"); return; } for (i = 0; i < 256; i++) - u.data8[i] = i; + u.data8[i] = getchar(); ao_flash_page(p, u.data32); } @@ -103,18 +103,43 @@ ao_block_read(void) for (i = 0; i < 256; i++) { c = *p++; - puthex(c); + (*ao_stdios[ao_cur_stdio].putchar)(c); + } +} + +void +ao_block_read_hex(void) +{ + uint32_t addr = ao_cmd_hex32(); + uint8_t *p = (uint8_t *) addr; + uint16_t i; + uint8_t c; + + for (i = 0; i < 256; i++) { + c = *p++; puthex(c>>4); + puthex(c); if ((i & 0xf) == 0xf) putchar('\n'); } } +static void +ao_show_version(void) +{ + puts("altos-loader"); + ao_put_string("manufacturer "); puts(ao_manufacturer); + ao_put_string("product "); puts(ao_product); + ao_put_string("software-version "); puts(ao_version); +} + __code struct ao_cmds ao_flash_cmds[] = { + { ao_show_version, "v\0Version" }, { ao_application, "a\0Switch to application" }, - { ao_block_erase, "e \0Erase block." }, + { ao_block_erase, "X \0Erase block." }, { ao_block_write, "W \0Write block. 256 binary bytes follow newline" }, - { ao_block_read, "R \0Read block. Returns 256 bytes" }, + { ao_block_read, "R \0Read block. Returns 256 binary bytes" }, + { ao_block_read_hex, "H \0Hex read block. Returns 256 bytes in hex" }, { 0, NULL }, }; -- cgit v1.2.3 From 6cd015b8b6b02bd8e0ce28f248426ae75c242b53 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 22 Apr 2013 20:32:18 -0500 Subject: altos/stm: Shrink stm flash loader to < 4kB Saves 4kB of flash space for applications. Signed-off-by: Keith Packard --- src/stm-flash/Makefile | 7 +--- src/stm-flash/ao_pins.h | 3 ++ src/stm-flash/ao_stm_flash.c | 96 ++++++++++++++++++-------------------------- src/stm/altos-loader.ld | 16 +------- 4 files changed, 46 insertions(+), 76 deletions(-) (limited to 'src/stm-flash') diff --git a/src/stm-flash/Makefile b/src/stm-flash/Makefile index 46bc61af..a4dd5ab8 100644 --- a/src/stm-flash/Makefile +++ b/src/stm-flash/Makefile @@ -20,14 +20,11 @@ ALTOS_SRC = \ ao_boot_chain.c \ ao_boot_pin.c \ ao_product.c \ - ao_romconfig.c \ - ao_task.c \ + ao_notask.c \ ao_timer.c \ - ao_mutex.c \ ao_usb_stm.c \ ao_stdio.c \ - ao_flash_stm.c \ - ao_cmd.c + ao_flash_stm.c PRODUCT=StmFlash-v0.0 PRODUCT_DEF=-DSTM_FLASH diff --git a/src/stm-flash/ao_pins.h b/src/stm-flash/ao_pins.h index 048fc828..6779fc42 100644 --- a/src/stm-flash/ao_pins.h +++ b/src/stm-flash/ao_pins.h @@ -47,6 +47,9 @@ #define HAS_USB 1 #define USE_USB_STDIN 1 #define HAS_BEEP 0 +#define HAS_TASK 0 +#define HAS_ECHO 0 +#define HAS_TICK 0 #define PACKET_HAS_SLAVE 0 diff --git a/src/stm-flash/ao_stm_flash.c b/src/stm-flash/ao_stm_flash.c index 344bceb9..f0abe7fb 100644 --- a/src/stm-flash/ao_stm_flash.c +++ b/src/stm-flash/ao_stm_flash.c @@ -26,6 +26,14 @@ ao_panic(uint8_t reason) for (;;); } +void +ao_put_string(__code char *s) +{ + char c; + while ((c = *s++)) + putchar(c); +} + void ao_application(void) { @@ -33,30 +41,35 @@ ao_application(void) } static uint32_t -ao_cmd_hex32(void) +ao_get_hex32(void) { - __pdata uint8_t r = ao_cmd_lex_error; int8_t n; uint32_t v = 0; - ao_cmd_white(); + for (;;) { + n = getchar(); + if (n != ' ') + break; + } for(;;) { - n = ao_cmd_hexchar(ao_cmd_lex_c); - if (n < 0) + 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; - r = ao_cmd_success; - ao_cmd_lex(); + n = getchar(); } - if (r != ao_cmd_success) - ao_cmd_status = r; return v; } void ao_block_erase(void) { - uint32_t addr = ao_cmd_hex32(); + uint32_t addr = ao_get_hex32(); uint32_t *p = (uint32_t *) addr; ao_flash_erase_page(p); @@ -65,7 +78,7 @@ ao_block_erase(void) void ao_block_write(void) { - uint32_t addr = ao_cmd_hex32(); + uint32_t addr = ao_get_hex32(); uint32_t *p = (uint32_t *) addr; union { uint8_t data8[256]; @@ -82,45 +95,17 @@ ao_block_write(void) ao_flash_page(p, u.data32); } -static void -puthex(uint8_t c) -{ - c &= 0xf; - if (c < 10) - c += '0'; - else - c += 'a' - 10; - putchar (c); -} - void ao_block_read(void) { - uint32_t addr = ao_cmd_hex32(); + 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_stdios[ao_cur_stdio].putchar)(c); - } -} - -void -ao_block_read_hex(void) -{ - uint32_t addr = ao_cmd_hex32(); - uint8_t *p = (uint8_t *) addr; - uint16_t i; - uint8_t c; - - for (i = 0; i < 256; i++) { - c = *p++; - puthex(c>>4); - puthex(c); - if ((i & 0xf) == 0xf) - putchar('\n'); + putchar(c); } } @@ -133,15 +118,18 @@ ao_show_version(void) ao_put_string("software-version "); puts(ao_version); } -__code struct ao_cmds ao_flash_cmds[] = { - { ao_show_version, "v\0Version" }, - { ao_application, "a\0Switch to application" }, - { ao_block_erase, "X \0Erase block." }, - { ao_block_write, "W \0Write block. 256 binary bytes follow newline" }, - { ao_block_read, "R \0Read block. Returns 256 binary bytes" }, - { ao_block_read_hex, "H \0Hex read block. Returns 256 bytes in hex" }, - { 0, NULL }, -}; +static void +ao_flash_task(void) { + for (;;) { + switch (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 @@ -149,15 +137,11 @@ main(void) { ao_clock_init(); - ao_task_init(); - - ao_timer_init(); +// ao_timer_init(); // ao_dma_init(); - ao_cmd_init(); // ao_exti_init(); ao_usb_init(); - ao_cmd_register(&ao_flash_cmds[0]); - ao_start_scheduler(); + ao_flash_task(); return 0; } diff --git a/src/stm/altos-loader.ld b/src/stm/altos-loader.ld index 14b45351..78649be2 100644 --- a/src/stm/altos-loader.ld +++ b/src/stm/altos-loader.ld @@ -32,21 +32,7 @@ SECTIONS { .text : { __text_start__ = .; *(.interrupt) /* Interrupt vectors */ - - . = 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*) + *(.romconfig) *(.text) /* Executable code */ *(.rodata) /* Constants */ -- cgit v1.2.3 From 8ded61d59888c79ef1f94e664b5fb770841a801a Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 22 Apr 2013 20:33:33 -0500 Subject: altos/stm: Provide another 4kB of flash space for apps With the flash loader now < 4kB, we can use the spare 4kB for applications Signed-off-by: Keith Packard --- src/stm-flash/ao_pins.h | 2 +- src/stm/altos-application.ld | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/stm-flash') diff --git a/src/stm-flash/ao_pins.h b/src/stm-flash/ao_pins.h index 6779fc42..1c00675b 100644 --- a/src/stm-flash/ao_pins.h +++ b/src/stm-flash/ao_pins.h @@ -75,6 +75,6 @@ #define AO_BOOT_APPLICATION_PIN 0 #define AO_BOOT_APPLICATION_VALUE 1 #define AO_BOOT_APPLICATION_MODE 0 -#define AO_BOOT_APPLICATION_BASE ((uint32_t *) 0x2000) +#define AO_BOOT_APPLICATION_BASE ((uint32_t *) 0x1000) #endif /* _AO_PINS_H_ */ diff --git a/src/stm/altos-application.ld b/src/stm/altos-application.ld index c94c06b8..6affc376 100644 --- a/src/stm/altos-application.ld +++ b/src/stm/altos-application.ld @@ -16,7 +16,7 @@ */ MEMORY { - rom (rx) : ORIGIN = 0x08002000, LENGTH = 120K + rom (rx) : ORIGIN = 0x08001000, LENGTH = 124K ram (!w) : ORIGIN = 0x20000000, LENGTH = 16K } -- cgit v1.2.3 From dfc268e0021e1cd3045f73339a749d292a6a6300 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 22 Apr 2013 20:35:57 -0500 Subject: altos: Use flash loader on all STM products Includes the boot chain stuff Signed-off-by: Keith Packard --- src/core/ao_cmd.c | 15 +++++++ src/megadongle-v0.1/Makefile | 1 + src/stm-demo/Makefile | 2 +- src/stm-demo/ao_demo.c | 8 ---- src/stm-flash/ao_pins.h | 1 - src/stm/altos-application.ld | 95 ------------------------------------------- src/stm/altos.ld | 35 +++++++++++++--- src/stm/ao_arch.h | 5 +++ src/stm/ao_boot.h | 5 +++ src/telegps-v0.1/Makefile | 1 + src/telelco-v0.1/Makefile | 1 + src/telemega-v0.1/Makefile | 1 + src/telescience-v0.2/Makefile | 1 + 13 files changed, 60 insertions(+), 111 deletions(-) delete mode 100644 src/stm/altos-application.ld (limited to 'src/stm-flash') diff --git a/src/core/ao_cmd.c b/src/core/ao_cmd.c index 7da2384f..188b8bb4 100644 --- a/src/core/ao_cmd.c +++ b/src/core/ao_cmd.c @@ -385,6 +385,18 @@ ao_cmd(void) } } +#if HAS_BOOT_LOADER + +#include + +static void +ao_loader(void) +{ + flush(); + ao_boot_loader(); +} +#endif + __xdata struct ao_task ao_cmd_task; __code struct ao_cmds ao_base_cmds[] = { @@ -396,6 +408,9 @@ __code struct ao_cmds ao_base_cmds[] = { { 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/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/stm-demo/Makefile b/src/stm-demo/Makefile index e84a7675..d1f825db 100644 --- a/src/stm-demo/Makefile +++ b/src/stm-demo/Makefile @@ -56,7 +56,7 @@ OBJ=$(SRC:.c=.o) all: $(ELF) $(IHX) -LDFLAGS=-L../stm -Wl,-Taltos-application.ld +LDFLAGS=-L../stm -Wl,-Taltos.ld $(ELF): Makefile $(OBJ) $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $@ $(OBJ) $(SAT_CLIB) -lgcc diff --git a/src/stm-demo/ao_demo.c b/src/stm-demo/ao_demo.c index ec572fdc..5677cdf4 100644 --- a/src/stm-demo/ao_demo.c +++ b/src/stm-demo/ao_demo.c @@ -169,13 +169,6 @@ ao_event(void) } -static void -ao_boot_loader(void) -{ - flush(); - ao_boot_reboot((uint32_t *) 0); -} - __code struct ao_cmds ao_demo_cmds[] = { { ao_dma_test, "D\0DMA test" }, { ao_spi_write, "W\0SPI write" }, @@ -183,7 +176,6 @@ __code struct ao_cmds ao_demo_cmds[] = { { ao_i2c_write, "i\0I2C write" }, { ao_temp, "t\0Show temp" }, { ao_event, "e\0Monitor event queue" }, - { ao_boot_loader, "L\0Reboot to boot loader" }, { 0, NULL } }; diff --git a/src/stm-flash/ao_pins.h b/src/stm-flash/ao_pins.h index 1c00675b..8fb56f7b 100644 --- a/src/stm-flash/ao_pins.h +++ b/src/stm-flash/ao_pins.h @@ -75,6 +75,5 @@ #define AO_BOOT_APPLICATION_PIN 0 #define AO_BOOT_APPLICATION_VALUE 1 #define AO_BOOT_APPLICATION_MODE 0 -#define AO_BOOT_APPLICATION_BASE ((uint32_t *) 0x1000) #endif /* _AO_PINS_H_ */ diff --git a/src/stm/altos-application.ld b/src/stm/altos-application.ld deleted file mode 100644 index 6affc376..00000000 --- a/src/stm/altos-application.ld +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright © 2012 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; 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 (rx) : ORIGIN = 0x08001000, LENGTH = 124K - ram (!w) : ORIGIN = 0x20000000, LENGTH = 16K -} - -INCLUDE registers.ld - -EXTERN (stm_interrupt_vector) - -SECTIONS { - /* - * Rom contents - */ - - .text ORIGIN(rom) : { - __text_start__ = .; - *(.interrupt) /* Interrupt vectors */ - - . = 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 */ - - } > rom - - .ARM.exidx : { - *(.ARM.exidx* .gnu.linkonce.armexidx.*) - } > 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 : { - __data_start__ = .; - *(.data) /* initialized data */ - . = ALIGN(4); - __data_end__ = .; - } >ram AT>rom - - .bss : { - __bss_start__ = .; - *(.bss) - *(COMMON) - . = ALIGN(4); - __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 d218e992..3106cc3b 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 = 15872 stack (!w) : ORIGIN = 0x20003e00, LENGTH = 512 } @@ -36,9 +36,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 */ @@ -46,21 +56,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 27a942f2..cc83eac2 100644 --- a/src/stm/ao_arch.h +++ b/src/stm/ao_arch.h @@ -129,5 +129,10 @@ extern const uint32_t ao_radio_cal; void ao_adc_init(); +#define AO_BOOT_APPLICATION_BASE ((uint32_t *) 0x1000) +#define AO_BOOT_LOADER_BASE ((uint32_t *) 0x0) +#define HAS_BOOT_LOADER 1 + #endif /* _AO_ARCH_H_ */ + diff --git a/src/stm/ao_boot.h b/src/stm/ao_boot.h index 3e8c50ba..862e8755 100644 --- a/src/stm/ao_boot.h +++ b/src/stm/ao_boot.h @@ -30,4 +30,9 @@ 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/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/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 \ -- cgit v1.2.3 From afad5ae893a48785f3b50ff4125dc78648343a2d Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 22 Apr 2013 20:08:35 -0600 Subject: altos/stm-flash: Check target flash address against AO_BOOT_APPLICATION_BASE Allows that value to change Signed-off-by: Keith Packard --- src/stm-flash/ao_stm_flash.c | 2 +- src/stm/ao_arch.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/stm-flash') diff --git a/src/stm-flash/ao_stm_flash.c b/src/stm-flash/ao_stm_flash.c index f0abe7fb..df06bb09 100644 --- a/src/stm-flash/ao_stm_flash.c +++ b/src/stm-flash/ao_stm_flash.c @@ -86,7 +86,7 @@ ao_block_write(void) } u; uint16_t i; - if (addr < 0x08002000 || 0x08200000 <= addr) { + if (addr < (uint32_t) AO_BOOT_APPLICATION_BASE) { ao_put_string("Invalid address\n"); return; } diff --git a/src/stm/ao_arch.h b/src/stm/ao_arch.h index cc83eac2..757b5251 100644 --- a/src/stm/ao_arch.h +++ b/src/stm/ao_arch.h @@ -129,7 +129,7 @@ extern const uint32_t ao_radio_cal; void ao_adc_init(); -#define AO_BOOT_APPLICATION_BASE ((uint32_t *) 0x1000) +#define AO_BOOT_APPLICATION_BASE ((uint32_t *) 0x08001000) #define AO_BOOT_LOADER_BASE ((uint32_t *) 0x0) #define HAS_BOOT_LOADER 1 -- cgit v1.2.3 From f6d6df03826083a244715b88a30ad681f17b4510 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 27 Apr 2013 00:25:36 -0700 Subject: altos: Remove stdio from stm-flash This saves enough memory to fit in under 4kB Signed-off-by: Keith Packard --- src/stm-flash/Makefile | 7 +++---- src/stm-flash/ao_pins.h | 8 ++++---- src/stm-flash/ao_stm_flash.c | 27 ++++++++++++++++----------- 3 files changed, 23 insertions(+), 19 deletions(-) (limited to 'src/stm-flash') diff --git a/src/stm-flash/Makefile b/src/stm-flash/Makefile index a4dd5ab8..1ea35581 100644 --- a/src/stm-flash/Makefile +++ b/src/stm-flash/Makefile @@ -23,16 +23,15 @@ ALTOS_SRC = \ ao_notask.c \ ao_timer.c \ ao_usb_stm.c \ - ao_stdio.c \ ao_flash_stm.c -PRODUCT=StmFlash-v0.0 -PRODUCT_DEF=-DSTM_FLASH +PRODUCT=AltosFlash-$(VERSION) +PRODUCT_DEF=-DALTOS_FLASH IDPRODUCT=0x000a CFLAGS = $(PRODUCT_DEF) $(STM_CFLAGS) -g -Os -PROG=stm-flash-$(VERSION).elf +PROG=altos-flash-$(VERSION).elf SRC=$(ALTOS_SRC) ao_stm_flash.c OBJ=$(SRC:.c=.o) diff --git a/src/stm-flash/ao_pins.h b/src/stm-flash/ao_pins.h index 8fb56f7b..d6c72653 100644 --- a/src/stm-flash/ao_pins.h +++ b/src/stm-flash/ao_pins.h @@ -45,7 +45,7 @@ #define AO_RCC_CFGR_PPRE2_DIV STM_RCC_CFGR_PPRE2_DIV_1 #define HAS_USB 1 -#define USE_USB_STDIN 1 +#define USE_USB_STDIO 0 #define HAS_BEEP 0 #define HAS_TASK 0 #define HAS_ECHO 0 @@ -71,9 +71,9 @@ #define AO_BOOT_CHAIN 1 #define AO_BOOT_PIN 1 -#define AO_BOOT_APPLICATION_GPIO stm_gpioa -#define AO_BOOT_APPLICATION_PIN 0 +#define AO_BOOT_APPLICATION_GPIO stm_gpiod +#define AO_BOOT_APPLICATION_PIN 2 #define AO_BOOT_APPLICATION_VALUE 1 -#define AO_BOOT_APPLICATION_MODE 0 +#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 index df06bb09..f8580735 100644 --- a/src/stm-flash/ao_stm_flash.c +++ b/src/stm-flash/ao_stm_flash.c @@ -30,8 +30,11 @@ void ao_put_string(__code char *s) { char c; - while ((c = *s++)) - putchar(c); + while ((c = *s++)) { + if (c == '\n') + ao_usb_putchar('\r'); + ao_usb_putchar(c); + } } void @@ -47,7 +50,7 @@ ao_get_hex32(void) uint32_t v = 0; for (;;) { - n = getchar(); + n = ao_usb_getchar(); if (n != ' ') break; } @@ -61,7 +64,7 @@ ao_get_hex32(void) else break; v = (v << 4) | n; - n = getchar(); + n = ao_usb_getchar(); } return v; } @@ -91,7 +94,7 @@ ao_block_write(void) return; } for (i = 0; i < 256; i++) - u.data8[i] = getchar(); + u.data8[i] = ao_usb_getchar(); ao_flash_page(p, u.data32); } @@ -105,23 +108,25 @@ ao_block_read(void) for (i = 0; i < 256; i++) { c = *p++; - putchar(c); + ao_usb_putchar(c); } } static void ao_show_version(void) { - puts("altos-loader"); - ao_put_string("manufacturer "); puts(ao_manufacturer); - ao_put_string("product "); puts(ao_product); - ao_put_string("software-version "); puts(ao_version); + 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 (;;) { - switch (getchar()) { + ao_usb_flush(); + switch (ao_usb_getchar()) { case 'v': ao_show_version(); break; case 'a': ao_application(); break; case 'X': ao_block_erase(); break; -- cgit v1.2.3 From 4a90eec4b8ee4a35711aa74c13b3f30d12c0fe08 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 27 Apr 2013 15:33:04 -0700 Subject: altos/stm: Create per-product flash loaders Split the flash loader prototype into pieces so that each product can build a custom flash loader with very little code. Signed-off-by: Keith Packard --- src/Makefile | 7 +- src/megadongle-v0.1/flash-loader/Makefile | 7 ++ src/megadongle-v0.1/flash-loader/ao_pins.h | 34 +++++++ src/product/ao_flash_pins.h | 40 ++++++++ src/product/ao_flash_task.c | 137 ++++++++++++++++++++++++++ src/product/ao_flash_task.h | 24 +++++ src/stm-flash/ao_stm_flash.c | 152 ----------------------------- src/stm/Makefile-flash.defs | 92 +++++++++++++++++ src/stm/altos-loader.ld | 31 +++--- src/stm/ao_arch.h | 4 + src/stm/ao_flash.h | 27 +++++ src/stm/ao_flash_loader_stm.c | 32 ++++++ src/stm/ao_flash_stm.c | 2 +- src/stm/ao_flash_stm.h | 27 ----- src/stm/ao_flash_stm_pins.h | 43 ++++++++ src/telegps-v0.1/flash-loader/Makefile | 8 ++ src/telegps-v0.1/flash-loader/ao_pins.h | 34 +++++++ src/telemega-v0.1/flash-loader/Makefile | 7 ++ src/telemega-v0.1/flash-loader/ao_pins.h | 34 +++++++ src/telemega-v0.3/flash-loader/Makefile | 8 ++ src/telemega-v0.3/flash-loader/ao_pins.h | 34 +++++++ 21 files changed, 590 insertions(+), 194 deletions(-) create mode 100644 src/megadongle-v0.1/flash-loader/Makefile create mode 100644 src/megadongle-v0.1/flash-loader/ao_pins.h create mode 100644 src/product/ao_flash_pins.h create mode 100644 src/product/ao_flash_task.c create mode 100644 src/product/ao_flash_task.h delete mode 100644 src/stm-flash/ao_stm_flash.c create mode 100644 src/stm/Makefile-flash.defs create mode 100644 src/stm/ao_flash.h create mode 100644 src/stm/ao_flash_loader_stm.c delete mode 100644 src/stm/ao_flash_stm.h create mode 100644 src/stm/ao_flash_stm_pins.h create mode 100644 src/telegps-v0.1/flash-loader/Makefile create mode 100644 src/telegps-v0.1/flash-loader/ao_pins.h create mode 100644 src/telemega-v0.1/flash-loader/Makefile create mode 100644 src/telemega-v0.1/flash-loader/ao_pins.h create mode 100644 src/telemega-v0.3/flash-loader/Makefile create mode 100644 src/telemega-v0.3/flash-loader/ao_pins.h (limited to 'src/stm-flash') diff --git a/src/Makefile b/src/Makefile index 90a74166..5ae61a00 100644 --- a/src/Makefile +++ b/src/Makefile @@ -29,7 +29,12 @@ AVRDIRS=\ telescience-v0.1 telescience-pwm telepyro-v0.1 micropeak ARMDIRS=\ - telemega-v0.1 telemega-v0.3 megadongle-v0.1 stm-bringup stm-demo telelco-v0.1 \ + telemega-v0.1 telemega-v0.1/flash-loader \ + telemega-v0.3 telemega-v0.3/flash-loader \ + megadongle-v0.1 megadongle-v0.1/flash-loader \ + telegps-v0.1 telegps-v0.1/flash-loader \ + stm-bringup stm-demo telelco-v0.1 \ + telelco-v0.2 telelco-v0.2/flash-loader \ telescience-v0.2 ifneq ($(shell which sdcc),) diff --git a/src/megadongle-v0.1/flash-loader/Makefile b/src/megadongle-v0.1/flash-loader/Makefile new file mode 100644 index 00000000..adea5786 --- /dev/null +++ b/src/megadongle-v0.1/flash-loader/Makefile @@ -0,0 +1,7 @@ +# +# AltOS flash loader build +# + +TOPDIR=../.. +HARDWARE=megadongle-v0.1 +include $(TOPDIR)/stm/Makefile-flash.defs diff --git a/src/megadongle-v0.1/flash-loader/ao_pins.h b/src/megadongle-v0.1/flash-loader/ao_pins.h new file mode 100644 index 00000000..1af92f13 --- /dev/null +++ b/src/megadongle-v0.1/flash-loader/ao_pins.h @@ -0,0 +1,34 @@ +/* + * Copyright © 2013 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; 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_ + +/* External crystal at 8MHz */ +#define AO_HSE 8000000 + +#include + +/* Companion port cs_companion0 PD0 */ + +#define AO_BOOT_PIN 1 +#define AO_BOOT_APPLICATION_GPIO stm_gpiod +#define AO_BOOT_APPLICATION_PIN 0 +#define AO_BOOT_APPLICATION_VALUE 1 +#define AO_BOOT_APPLICATION_MODE AO_EXTI_MODE_PULL_UP + +#endif /* _AO_PINS_H_ */ diff --git a/src/product/ao_flash_pins.h b/src/product/ao_flash_pins.h new file mode 100644 index 00000000..b774df6d --- /dev/null +++ b/src/product/ao_flash_pins.h @@ -0,0 +1,40 @@ +/* + * Copyright © 2013 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; 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_PINS_H_ +#define _AO_FLASH_PINS_H_ + +/* Common definitions for the USB flash loader */ + +#define HAS_TASK_QUEUE 0 + +#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 HAS_TASK_INFO 0 +#define HAS_VERSION 0 + +#define AO_BOOT_CHAIN 1 +#define AO_BOOT_PIN 1 + +#endif /* _AO_FLASH_PINS_H_ */ diff --git a/src/product/ao_flash_task.c b/src/product/ao_flash_task.c new file mode 100644 index 00000000..fdc4d0aa --- /dev/null +++ b/src/product/ao_flash_task.c @@ -0,0 +1,137 @@ +/* + * Copyright © 2013 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; 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 +#include +#include +#include + +void +ao_panic(uint8_t reason) +{ +} + +void +ao_put_string(__code char *s) +{ + char c; + while ((c = *s++)) { + if (c == '\n') + ao_usb_putchar('\r'); + ao_usb_putchar(c); + } +} + +static 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; +} + +static void +ao_block_erase(void) +{ + uint32_t addr = ao_get_hex32(); + uint32_t *p = (uint32_t *) addr; + + ao_flash_erase_page(p); +} + +static 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); +} + +static 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"); +} + +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; + } + } +} diff --git a/src/product/ao_flash_task.h b/src/product/ao_flash_task.h new file mode 100644 index 00000000..0a2fbb35 --- /dev/null +++ b/src/product/ao_flash_task.h @@ -0,0 +1,24 @@ +/* + * Copyright © 2013 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; 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_TASK_H_ +#define _AO_FLASH_TASK_H_ + +void +ao_flash_task(void); + +#endif /* _AO_FLASH_TASK_H_ */ diff --git a/src/stm-flash/ao_stm_flash.c b/src/stm-flash/ao_stm_flash.c deleted file mode 100644 index f8580735..00000000 --- a/src/stm-flash/ao_stm_flash.c +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright © 2011 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; 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 -#include -#include - -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-flash.defs b/src/stm/Makefile-flash.defs new file mode 100644 index 00000000..016bb7e7 --- /dev/null +++ b/src/stm/Makefile-flash.defs @@ -0,0 +1,92 @@ +vpath % $(TOPDIR)/stm:$(TOPDIR)/product:$(TOPDIR)/drivers:$(TOPDIR)/core:$(TOPDIR)/util:$(TOPDIR) +vpath ao-make-product.5c $(TOPDIR)/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 +SAT_CFLAGS=-I$(SAT)/include + +ifndef VERSION +include $(TOPDIR)/Version +endif + +AO_CFLAGS=-I. -I$(TOPDIR)/stm -I$(TOPDIR)/core -I$(TOPDIR)/drivers -I$(TOPDIR)/product -I$(TOPDIR) +STM_CFLAGS=-std=gnu99 -mlittle-endian -mcpu=cortex-m3 -mthumb -ffreestanding -nostdlib $(AO_CFLAGS) $(SAT_CFLAGS) + +LDFLAGS=-L$(TOPDIR)/stm -Wl,-Taltos-loader.ld + +NICKLE=nickle + +V=0 +# The user has explicitly enabled quiet compilation. +ifeq ($(V),0) +quiet = @printf " $1 $2 $@\n"; $($1) +endif +# Otherwise, print the full command line. +quiet ?= $($1) + +.c.o: + $(call quiet,CC) -c $(CFLAGS) -o $@ $< + +INC = \ + ao.h \ + ao_arch.h \ + ao_arch_funcs.h \ + ao_flash_pins.h \ + ao_flash_stm_pins.h \ + ao_flash_task.h \ + ao_pins.h \ + ao_product.h \ + Makefile + +# +# Common AltOS sources +# +SRC = \ + ao_interrupt.c \ + ao_romconfig.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 \ + ao_flash_task.c \ + ao_flash_loader_stm.c + +OBJ=$(SRC:.c=.o) + +PRODUCT=AltosFlash-$(VERSION) +PRODUCT_DEF=-DALTOS_FLASH +IDPRODUCT=0x000a + +CFLAGS = $(PRODUCT_DEF) $(STM_CFLAGS) -g -Os + +PROGNAME=altos-flash +PROG=$(HARDWARE)-$(PROGNAME)-$(VERSION).elf + +$(PROG): Makefile $(OBJ) altos-loader.ld + $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(OBJ) $(SAT_CLIB) -lgcc + +ao_product.h: ao-make-product.5c $(TOPDIR)/Version + $(call quiet,NICKLE,$<) $< -m altusmetrum.org -i $(IDPRODUCT) -p $(PRODUCT) -v $(VERSION) > $@ + +$(OBJ): $(INC) + +all: $(PROG) + +distclean: clean + +clean: + rm -f *.o $(PROG) + rm -f ao_product.h + +install: + +uninstall: diff --git a/src/stm/altos-loader.ld b/src/stm/altos-loader.ld index 5e10e5ba..2be964f2 100644 --- a/src/stm/altos-loader.ld +++ b/src/stm/altos-loader.ld @@ -32,19 +32,16 @@ SECTIONS { .text : { __text_start__ = .; *(.interrupt) /* Interrupt vectors */ - *(.romconfig*) - *(.text) /* Executable code */ - . = ALIGN(4); - *(.rodata*) /* Constants */ - . = ALIGN(4); - } > rom - .ARM.exidx : { - . = ALIGN(4); + . = ORIGIN(rom) + 0x100; + + ao_romconfig.o(.romconfig*) + ao_product.o(.romconfig*) + *(.text) /* Executable code */ *(.ARM.exidx* .gnu.linkonce.armexidx.*) - . = ALIGN(4); + *(.rodata*) /* Constants */ + __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. @@ -53,12 +50,20 @@ SECTIONS { .boot (NOLOAD) : { __boot_start__ = .; *(.boot) - . = ALIGN(4); __boot_end__ = .; } >ram - /* Functions placed in RAM (required for flashing) */ - .textram : { + /* Functions placed in RAM (required for flashing) + * + * Align to 8 bytes as that's what the ARM likes text + * segment alignments to be, and if we don't, then + * we end up with a mismatch between the location in + * ROM and the desired location in RAM. I don't + * entirely understand this, but at least this appears + * to work... + */ + + .textram BLOCK(8): { __data_start__ = .; __text_ram_start__ = .; *(.text.ram) diff --git a/src/stm/ao_arch.h b/src/stm/ao_arch.h index 757b5251..adc288c3 100644 --- a/src/stm/ao_arch.h +++ b/src/stm/ao_arch.h @@ -88,6 +88,10 @@ extern const uint32_t ao_radio_cal; * For now, we're running at a weird frequency */ +#ifndef AO_HSE +#error High speed frequency undefined +#endif + #if AO_HSE #define AO_PLLSRC AO_HSE #else diff --git a/src/stm/ao_flash.h b/src/stm/ao_flash.h new file mode 100644 index 00000000..09ca5ac1 --- /dev/null +++ b/src/stm/ao_flash.h @@ -0,0 +1,27 @@ +/* + * Copyright © 2013 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; 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_flash_loader_stm.c b/src/stm/ao_flash_loader_stm.c new file mode 100644 index 00000000..2ab548cf --- /dev/null +++ b/src/stm/ao_flash_loader_stm.c @@ -0,0 +1,32 @@ +/* + * Copyright © 2013 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; 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 +#include +#include + +int +main(void) +{ + ao_clock_init(); + + ao_usb_init(); + + ao_flash_task(); + return 0; +} diff --git a/src/stm/ao_flash_stm.c b/src/stm/ao_flash_stm.c index b4d47024..d7a85582 100644 --- a/src/stm/ao_flash_stm.c +++ b/src/stm/ao_flash_stm.c @@ -16,7 +16,7 @@ */ #include -#include +#include static uint8_t ao_flash_pecr_is_locked(void) diff --git a/src/stm/ao_flash_stm.h b/src/stm/ao_flash_stm.h deleted file mode 100644 index 09ca5ac1..00000000 --- a/src/stm/ao_flash_stm.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright © 2013 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; 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_flash_stm_pins.h b/src/stm/ao_flash_stm_pins.h new file mode 100644 index 00000000..d157a226 --- /dev/null +++ b/src/stm/ao_flash_stm_pins.h @@ -0,0 +1,43 @@ +/* + * Copyright © 2013 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; 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_PINS_H_ +#define _AO_FLASH_STM_PINS_H_ + +#include + +/* 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 + +#endif /* _AO_FLASH_STM_PINS_H_ */ diff --git a/src/telegps-v0.1/flash-loader/Makefile b/src/telegps-v0.1/flash-loader/Makefile new file mode 100644 index 00000000..efc98d14 --- /dev/null +++ b/src/telegps-v0.1/flash-loader/Makefile @@ -0,0 +1,8 @@ +# +# AltOS flash loader build +# +# + +TOPDIR=../.. +HARDWARE=telegps-v0.1 +include $(TOPDIR)/stm/Makefile-flash.defs diff --git a/src/telegps-v0.1/flash-loader/ao_pins.h b/src/telegps-v0.1/flash-loader/ao_pins.h new file mode 100644 index 00000000..564e84de --- /dev/null +++ b/src/telegps-v0.1/flash-loader/ao_pins.h @@ -0,0 +1,34 @@ +/* + * Copyright © 2013 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; 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_ + +/* External crystal at 8MHz */ +#define AO_HSE 8000000 + +#include + +/* Telemetry TX pin PB6 */ + +#define AO_BOOT_PIN 1 +#define AO_BOOT_APPLICATION_GPIO stm_gpiob +#define AO_BOOT_APPLICATION_PIN 6 +#define AO_BOOT_APPLICATION_VALUE 1 +#define AO_BOOT_APPLICATION_MODE AO_EXTI_MODE_PULL_UP + +#endif /* _AO_PINS_H_ */ diff --git a/src/telemega-v0.1/flash-loader/Makefile b/src/telemega-v0.1/flash-loader/Makefile new file mode 100644 index 00000000..7aa8549f --- /dev/null +++ b/src/telemega-v0.1/flash-loader/Makefile @@ -0,0 +1,7 @@ +# +# AltOS flash loader build +# + +TOPDIR=../.. +HARDWARE=telemega-v0.1 +include $(TOPDIR)/stm/Makefile-flash.defs diff --git a/src/telemega-v0.1/flash-loader/ao_pins.h b/src/telemega-v0.1/flash-loader/ao_pins.h new file mode 100644 index 00000000..1af92f13 --- /dev/null +++ b/src/telemega-v0.1/flash-loader/ao_pins.h @@ -0,0 +1,34 @@ +/* + * Copyright © 2013 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; 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_ + +/* External crystal at 8MHz */ +#define AO_HSE 8000000 + +#include + +/* Companion port cs_companion0 PD0 */ + +#define AO_BOOT_PIN 1 +#define AO_BOOT_APPLICATION_GPIO stm_gpiod +#define AO_BOOT_APPLICATION_PIN 0 +#define AO_BOOT_APPLICATION_VALUE 1 +#define AO_BOOT_APPLICATION_MODE AO_EXTI_MODE_PULL_UP + +#endif /* _AO_PINS_H_ */ diff --git a/src/telemega-v0.3/flash-loader/Makefile b/src/telemega-v0.3/flash-loader/Makefile new file mode 100644 index 00000000..8fda18cd --- /dev/null +++ b/src/telemega-v0.3/flash-loader/Makefile @@ -0,0 +1,8 @@ +# +# AltOS flash loader build +# +# + +TOPDIR=../.. +HARDWARE=telemega-v0.3 +include $(TOPDIR)/stm/Makefile-flash.defs diff --git a/src/telemega-v0.3/flash-loader/ao_pins.h b/src/telemega-v0.3/flash-loader/ao_pins.h new file mode 100644 index 00000000..1af92f13 --- /dev/null +++ b/src/telemega-v0.3/flash-loader/ao_pins.h @@ -0,0 +1,34 @@ +/* + * Copyright © 2013 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; 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_ + +/* External crystal at 8MHz */ +#define AO_HSE 8000000 + +#include + +/* Companion port cs_companion0 PD0 */ + +#define AO_BOOT_PIN 1 +#define AO_BOOT_APPLICATION_GPIO stm_gpiod +#define AO_BOOT_APPLICATION_PIN 0 +#define AO_BOOT_APPLICATION_VALUE 1 +#define AO_BOOT_APPLICATION_MODE AO_EXTI_MODE_PULL_UP + +#endif /* _AO_PINS_H_ */ -- cgit v1.2.3