Stefano Mammolito
/
mbed-os-bootloader-F411
Simple F411 bootloader.
Revision 0:cd3dd72a93f5, committed 2018-04-10
- Comitter:
- stema
- Date:
- Tue Apr 10 08:52:17 2018 +0000
- Commit message:
- Simple F411 SD bootloader.
Changed in this revision
diff -r 000000000000 -r cd3dd72a93f5 .gitignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.gitignore Tue Apr 10 08:52:17 2018 +0000 @@ -0,0 +1,4 @@ +.build +.mbed +projectfiles +*.py*
diff -r 000000000000 -r cd3dd72a93f5 README.md --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.md Tue Apr 10 08:52:17 2018 +0000 @@ -0,0 +1,57 @@ +# Getting started with Blinky on mbed OS + +This guide reviews the steps required to get Blinky working on an mbed OS platform. + +Please install [mbed CLI](https://github.com/ARMmbed/mbed-cli#installing-mbed-cli). + +## Import the example application + +From the command-line, import the example: + +``` +mbed import mbed-os-example-blinky +cd mbed-os-example-blinky +``` + +### Now compile + +Invoke `mbed compile`, and specify the name of your platform and your favorite toolchain (`GCC_ARM`, `ARM`, `IAR`). For example, for the ARM Compiler 5: + +``` +mbed compile -m K64F -t ARM +``` + +Your PC may take a few minutes to compile your code. At the end, you see the following result: + +``` +[snip] ++----------------------------+-------+-------+------+ +| Module | .text | .data | .bss | ++----------------------------+-------+-------+------+ +| Misc | 13939 | 24 | 1372 | +| core/hal | 16993 | 96 | 296 | +| core/rtos | 7384 | 92 | 4204 | +| features/FEATURE_IPV4 | 80 | 0 | 176 | +| frameworks/greentea-client | 1830 | 60 | 44 | +| frameworks/utest | 2392 | 512 | 292 | +| Subtotals | 42618 | 784 | 6384 | ++----------------------------+-------+-------+------+ +Allocated Heap: unknown +Allocated Stack: unknown +Total Static RAM memory (data + bss): 7168 bytes +Total RAM memory (data + bss + heap + stack): 7168 bytes +Total Flash memory (text + data + misc): 43402 bytes +Image: .\.build\K64F\ARM\mbed-os-example-blinky.bin +``` + +### Program your board + +1. Connect your mbed device to the computer over USB. +1. Copy the binary file to the mbed device. +1. Press the reset button to start the program. + +The LED on your platform turns on and off. + +## Troubleshooting + +If you have problems, you can review the [documentation](https://os.mbed.com/docs/latest/tutorials/debugging.html) for suggestions on what could be wrong and how to fix it.
diff -r 000000000000 -r cd3dd72a93f5 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Apr 10 08:52:17 2018 +0000 @@ -0,0 +1,100 @@ +#include "SDBlockDevice.h" +#include "FATFileSystem.h" + +#define SD_MOUNT_PATH "sd" +#define FULL_UPDATE_FILE_PATH "/" SD_MOUNT_PATH "/blinky.bin" + +#define POST_APPLICATION_ADDR 0x08020000 + +#if !defined(POST_APPLICATION_ADDR) +#error "target.restrict_size must be set for your target in mbed_app.json" +#endif + +//Pin order: MOSI, MISO, SCK, CS +SDBlockDevice sd(SPI_MOSI, SPI_MISO, + SPI_SCK, SPI_CS); +FATFileSystem fs(SD_MOUNT_PATH); +FlashIAP flash; + +void apply_update(FILE *file, uint32_t address); + +int main() +{ + sd.init(); + fs.mount(&sd); + + FILE *file = fopen(FULL_UPDATE_FILE_PATH, "rb"); + if (file != NULL) { + printf("Firmware update found\r\n"); + + apply_update(file, POST_APPLICATION_ADDR); + + fclose(file); + remove(FULL_UPDATE_FILE_PATH); + } else { + printf("No update found to apply\r\n"); + } + + fs.unmount(); + sd.deinit(); + + printf("Starting application\r\n"); + + mbed_start_application(POST_APPLICATION_ADDR); +} + +void apply_update(FILE *file, uint32_t address) +{ + fseek(file, 0, SEEK_END); + long len = ftell(file); + printf("Firmware size is %ld bytes\r\n", len); + fseek(file, 0, SEEK_SET); + + flash.init(); + + const uint32_t page_size = flash.get_page_size(); + char *page_buffer = new char[page_size]; + uint32_t addr = address; + uint32_t next_sector = addr + flash.get_sector_size(addr); + bool sector_erased = false; + size_t pages_flashed = 0; + uint32_t percent_done = 0; + while (true) { + + // Read data for this page + memset(page_buffer, 0, sizeof(page_buffer)); + int size_read = fread(page_buffer, 1, page_size, file); + if (size_read <= 0) { + break; + } + + // Erase this page if it hasn't been erased + if (!sector_erased) { + flash.erase(addr, flash.get_sector_size(addr)); + sector_erased = true; + } + + // Program page + flash.program(page_buffer, addr, page_size); + + addr += page_size; + if (addr >= next_sector) { + next_sector = addr + flash.get_sector_size(addr); + sector_erased = false; + } + + if (++pages_flashed % 3 == 0) { + uint32_t percent_done_new = ftell(file) * 100 / len; + if (percent_done != percent_done_new) { + percent_done = percent_done_new; + printf("Flashed %3ld%%\r", percent_done); + } + } + } + printf("Flashed 100%%\r\n"); + + delete[] page_buffer; + + flash.deinit(); +} +
diff -r 000000000000 -r cd3dd72a93f5 mbed-os.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Tue Apr 10 08:52:17 2018 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/mbed-os/#addec7ba10054be03849eff58a1d17f157391e7d
diff -r 000000000000 -r cd3dd72a93f5 sd-driver.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sd-driver.lib Tue Apr 10 08:52:17 2018 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/coverxit/code/sd-driver/#0df98d0fd2a5