Quantcast
Channel: Articles on JeeLabs
Viewing all articles
Browse latest Browse all 296

Faster uploads through SPI

$
0
0

It turns out that a ROM-based serial upload with Folie takes about 22 seconds for a standard Embello install (Mecrisp + always/board/core). While this is fine for occasional re-flashing, it adds quite a delay for production, i.e. when an image needs to be loaded onto each new board.

But the STM32L05x series µCs has another trick up its sleeve:

The ROM boot loader also checks for SPI requests on pins PA4..PA7, and on the JeeNode Zero rev4, all these pins are available of the main header. Could we bypass serial and use SPI?

Let’s find out, using a Blue Pill as programmer, since it has two SPI buses (this might come in handy later, with a radio on the other bus, for example).

The “quick loader” code for this is a bit involved, see 1608-forth/qld/dev.fs on GitHub.

We need the following pins connected on a JNZ:

  • power, i.e. +5V and ground
  • SPI, i.e. PA4 .. PA7
  • RESET and BOOT0 on the FTDI header

The latter are needed to start ROM boot mode: keep BOOT0 high, while pulsing RESET low.

This test does a “fake” upload, in that it goes through all the steps, but sends dummy data:

: uploader ( -- f )
  boot-mode
  sof check-ack
  get-cmd hex . decimal
  get-id hex . decimal
  rd-unp
  wr-unp
  512 erase  \ erase all 64 KB ...
  320 0 do   \ ... but program only 40 KB
    0 i 128 * $08000000 + pgm
  loop ;

And to run it, we can run as “boot-init uploader”. The uploader will also fetch and print the boot loader version and µC type ($417). Measuring the time it takes, we get ≈ 5 seconds.

Those 5 seconds are not so bad: according to the datasheet, both erasing and programming one 128-byte flash page takes 3.3..4.0 ms. Worst case, this is: 2 x 512 pages x 4 ms/page = 4 s.

Now we can work out Folie’s inefficiency for this operation: it inserts some delays and going through a 115200 baud link slows down the process a bit, adding ≈ 17 seconds of overhead.

There is one more way to perform fast uploads: through JTAG/SWD. This too bypasses the serial port and needs just a few pins (SWCLK, SWDIO, RESET, and power). Stay tuned…


Viewing all articles
Browse latest Browse all 296

Trending Articles