mirror of
https://github.com/licsber/micropython.git
synced 2024-09-21 17:40:24 +08:00
7cc6df3303
This changes all uses of pins to use the alias names of the pins. This makes the code easier to understand and will also allow sharing more code with LEGO_HUB_NO7. Signed-off-by: David Lechner <david@pybricks.com>
43 lines
1.4 KiB
Python
43 lines
1.4 KiB
Python
# Application firmware update funcion for LEGO_HUB_NO6.
|
|
# MIT license; Copyright (c) 2022 Damien P. George
|
|
|
|
from micropython import const
|
|
import struct, machine, fwupdate, spiflash
|
|
|
|
_SPIFLASH_UPDATE_KEY_ADDR = const(1020 * 1024)
|
|
_SPIFLASH_UPDATE_KEY_VALUE = const(0x12345678)
|
|
|
|
_FILESYSTEM_ADDR = const(0x8000_0000 + 1024 * 1024)
|
|
_FILESYSTEM_LEN = const(31 * 1024 * 1024)
|
|
|
|
|
|
def update_app(filename):
|
|
print(f"Updating application firmware from {filename}")
|
|
|
|
# Create the elements for the mboot filesystem-load operation.
|
|
elems = fwupdate.update_app_elements(filename, _FILESYSTEM_ADDR, _FILESYSTEM_LEN)
|
|
if not elems:
|
|
return
|
|
|
|
# Create the update key.
|
|
key = struct.pack("<I", _SPIFLASH_UPDATE_KEY_VALUE)
|
|
|
|
# Create a SPI flash object.
|
|
spi = machine.SoftSPI(
|
|
sck=machine.Pin.board.FLASH_SCK,
|
|
mosi=machine.Pin.board.FLASH_MOSI,
|
|
miso=machine.Pin.board.FLASH_MISO,
|
|
baudrate=50_000_000,
|
|
)
|
|
cs = machine.Pin(machine.Pin.board.FLASH_NSS, machine.Pin.OUT, value=1)
|
|
flash = spiflash.SPIFlash(spi, cs)
|
|
|
|
# Write the update key and elements to the SPI flash.
|
|
flash.erase_block(_SPIFLASH_UPDATE_KEY_ADDR)
|
|
flash.write(_SPIFLASH_UPDATE_KEY_ADDR, key + elems)
|
|
|
|
# Enter mboot with a request to do a filesystem-load update.
|
|
# If there is a power failure during the update (eg battery removed) then
|
|
# mboot will read the SPI flash update key and elements and retry.
|
|
machine.bootloader(elems)
|