From 6cd015b8b6b02bd8e0ce28f248426ae75c242b53 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 22 Apr 2013 20:32:18 -0500 Subject: [PATCH] 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(-) 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 */ -- 2.30.2