altos/stm: Shrink stm flash loader to < 4kB
authorKeith Packard <keithp@keithp.com>
Tue, 23 Apr 2013 01:32:18 +0000 (20:32 -0500)
committerKeith Packard <keithp@keithp.com>
Wed, 8 May 2013 04:30:26 +0000 (21:30 -0700)
Saves 4kB of flash space for applications.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/stm-flash/Makefile
src/stm-flash/ao_pins.h
src/stm-flash/ao_stm_flash.c
src/stm/altos-loader.ld

index 46bc61af4786ba13381fa3a5f5bb6b1514a16ea3..a4dd5ab8f452e192a155caa0a6148d88080bccca 100644 (file)
@@ -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
index 048fc8282ad0d077c9dbb6c75a49664b680f9b8f..6779fc42ca8a211d47567bd5cad97cb609b65cef 100644 (file)
@@ -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
 
index 344bceb91f064249f988aafd4b169073e919a41d..f0abe7fb8bd6aab35ddfabcd21743d11e9fe5d0f 100644 (file)
@@ -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 <addr>\0Erase block." },
-       { ao_block_write, "W <addr>\0Write block. 256 binary bytes follow newline" },
-       { ao_block_read, "R <addr>\0Read block. Returns 256 binary bytes" },
-       { ao_block_read_hex, "H <addr>\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;
 }
index 14b45351d3ce8876fa2c96562df417af5cd8ed53..78649be2ca6557b8c4de4afc63b7e676d5a82e2e 100644 (file)
@@ -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 */