X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fstm-flash%2Fao_stm_flash.c;h=df06bb098accb473efa3d12e8723448ee9c262ee;hb=2e092b383d55bcf9e2a230ccfe85052adb18b254;hp=2988a9375345c947665cc8972b87083da28e004e;hpb=b1a43ce313c85cb7f8f16f7f0647d9d4320ba692;p=fw%2Faltos diff --git a/src/stm-flash/ao_stm_flash.c b/src/stm-flash/ao_stm_flash.c index 2988a937..df06bb09 100644 --- a/src/stm-flash/ao_stm_flash.c +++ b/src/stm-flash/ao_stm_flash.c @@ -26,16 +26,110 @@ ao_panic(uint8_t reason) for (;;); } +void +ao_put_string(__code char *s) +{ + char c; + while ((c = *s++)) + putchar(c); +} + void ao_application(void) { ao_boot_reboot(AO_BOOT_APPLICATION_BASE); } -__code struct ao_cmds ao_flash_cmds[] = { - { ao_application, "A\0Switch to application" }, - { 0, NULL }, -}; +static uint32_t +ao_get_hex32(void) +{ + int8_t n; + uint32_t v = 0; + + for (;;) { + n = 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 = 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] = 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++; + 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); +} + +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 @@ -43,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; }