项目作者: lupyuen

项目描述 :
Load a Custom Boot Logo to PineTime Smart Watch
高级语言: Assembly
项目地址: git://github.com/lupyuen/pinetime-logo-loader.git
创建时间: 2020-08-04T01:18:31Z
项目社区:https://github.com/lupyuen/pinetime-logo-loader

开源协议:Apache License 2.0

下载


PineTime Smart Watch Logo Loader

PineTime Logo Loader

Load your Custom Boot Logo to PineTime Smart Watch. Works with the PineTime MCUBoot Bootloader.

  1. If our PineTime is not running on the MCUBoot Bootloader, flash the bootloader with PineTime Updater

  2. Click Fork to fork this repo

  3. In the new repo, click ActionsI Understand My Workflows Enable Them

    Enable GitHub Actions

  4. Click CodeAdd FileUpload Files

    Upload File

  5. Upload a PNG image file with the following format…

    • Filename pinetime-graphic.png

    • 240 x 240 resolution

    • 24-bit RGB color

    • See sample logos in logos

    Sample logos

  6. GitHub Actions will auto-build the firmware (see the workflow)

  7. Click Actions. Click on the latest build.

    GitHub Actions Build

  8. Wait about 5 minutes for the build to complete.

    Click on the Artifact named my_sensor_app.img

    GitHub Actions Artifact

  9. Unzip the downloaded file.

    Flash the unzipped firmware my_sensor_app.img to PineTime via PineTime Updater at address 0x8000

  10. When the firmware runs, it will write the Boot Logo to PineTime’s External SPI Flash.

    PineTime will show Boot Logo Updated

  11. Restore the PineTime firmware by flashing the latest InfiniTime firmware via PineTime Updater

  12. PineTime will now boot with the new Boot Logo stored in External SPI Flash…

First ever Custom Boot Logo created by the PineTime Community

First ever Custom Boot Logo created by the PineTime Community

The Boot Logo format (RGB565) is explained here…

MCUBoot Bootloader for PineTime Smart Watch (nRF52)

The GitHub Actions Workflow calls pinetime-graphic to convert the PNG image to C code (which is embedded in the firmware)…

github.com/lupyuen/pinetime-graphic

This repo is a Custom Firmware Build of pinetime-rust-mynewt

PineTime Smart Watch Firmware with Apache Mynewt and Embedded Rust

PineTime Smart Watch with Apache Mynewt and Embedded Rust

This master branch contains the firmware source code for PineTime Smart Watch with Apache Mynewt and Embedded Rust, with Wireless Firmware Updates. Refer to the articles…

  1. PineTime doesn’t run Linux… But that’s OK!

  2. Visual Rust for PineTime Smart Watch

  3. @ly.lee/build-and-flash-rust-mynewt-firmware-for-pinetime-smart-watch-5e14259c55?source=friends_link&sk=150b2a73b84144e5ef25b985e65aebe9">Build and Flash Rust+Mynewt Firmware for PineTime Smart Watch

  4. @ly.lee/debug-rust-mynewt-firmware-for-pinetime-on-raspberry-pi-4b9ac2d093a9?source=friends_link&sk=edb508c31e43d3ec40ecd8554f3405f6">Debug Rust+Mynewt Firmware for PineTime on Raspberry Pi

  5. Sneak Peek of PineTime Smart Watch… And why it’s perfect for teaching IoT

  6. @ly.lee/building-a-rust-driver-for-pinetimes-touch-controller-cbc1a5d5d3e9?source=friends_link&sk=d8cf73fc943d9c0e960627d768f309cb">Building a Rust Driver for PineTime’s Touch Controller

  7. @ly.lee/porting-druid-rust-widgets-to-pinetime-smart-watch-7e1d5a5d977a?source=friends_link&sk=09b153c68483f7fa9e63350efd167b07">Porting [druid] Rust Widgets to PineTime Smart Watch

  8. @ly.lee/optimising-pinetimes-display-driver-with-rust-and-mynewt-3ba269ea2f5c?source=friends_link&sk=4d2cbd2e6cd2343eed62d214814f7b81">Optimising PineTime’s Display Driver with Rust and Mynewt

  9. @ly.lee/openocd-on-raspberry-pi-better-with-swd-on-spi-7dea9caeb590?source=friends_link&sk=df399bfd913d3e262447d28aa5af6b63">OpenOCD on Raspberry Pi: Better with SWD on SPI

  10. CHIP-8 Game Emulator in Rust for PineTime Smart Watch

  11. Firmware Update over Bluetooth Low Energy on PineTime Smart Watch

  12. Configure Mynewt for SPI Flash on PineTime Smart Watch (nRF52)

  13. MCUBoot Bootloader for PineTime Smart Watch (nRF52)

  14. Wireless Firmware Update In Action on PineTime Smart Watch (nRF52)

  15. Porting MicroPython and wasp-os to Mynewt on PineTime Smart Watch (nRF52)

  16. Your First Bluetooth Low Energy App with Flutter

  17. Convert Go to Flutter and Dart for PineTime Companion App

  18. Your First GTK App with Go and VSCodium

  19. Flutter State Management with Bloc for PineTime Companion App

  20. Auto Convert Go to Dart with an Abstract Syntax Tree

  21. @ly.lee/my-first-week-as-embedded-foss-advocate-106d625deae?source=friends_link&sk=4128d2bb8a7098658fafc462a1531d34">My First Week As Embedded FOSS Advocate

  22. Rust Documentation

RSS Feed

The code structure is similar to the earlier article on nRF52…

@ly.lee/coding-nrf52-with-rust-and-apache-mynewt-on-visual-studio-code-9521bcba6004?source=friends_link&sk=bb4e2523b922d0870259ab3fa696c7da">Coding nRF52 with Rust and Apache Mynewt on Visual Studio Code

Automated Build with GitHub Actions

The MCUBoot Bootloader and Rust+Mynewt Firmware are built automatically in the GitHub Cloud.

Just fork this repo, update the source code and the built firmware will be available for download under “Actions”.

The Automated Build is performed according to the following GitHub Actions Workflow

.github/workflows/main.yml

The Worklow is similar to the one described in this article…

Build PineTime Firmware in the Cloud with GitHub Actions

Build Instructions

If you are building from this repository from scratch instead of the Released Packages, here are the steps for Linux (including Raspberry Pi) and macOS…

Install Build Tools

  1. Install OpenOCD from The xPack OpenOCD. Older versions of OpenOCD are known to have problems flashing with ST-Link.

    Download and unzip OpenOCD for macOS: gnu-mcu-eclipse-openocd-0.10.0-11-20190118-1134-macos.tgz

    For Raspberry Pi: Install openocd-spi according to the instructions here…

    @ly.lee/openocd-on-raspberry-pi-better-with-swd-on-spi-7dea9caeb590?source=friends_link&sk=df399bfd913d3e262447d28aa5af6b63">“OpenOCD on Raspberry Pi: Better with SWD on SPI”

  2. Install GCC and Python build tools for Linux (or the macOS equivalent)…

    1. sudo apt install gcc gcc-arm-none-eabi python3 make

    For Majaro and Arch Linux…

    1. sudo pacman -S arm-none-eabi-gcc
  3. Install rustup with support for nightly target thumbv7em-none-eabihf.

    Follow the instructions at https://rustup.rs/

    Press Enter to select 1) Proceed with installation (default)

    Then execute…

    1. # Latest nightly-2020-04-20 fails with asm error, so we use nightly-2020-02-16
    2. source $HOME/.cargo/env
    3. rustup update
    4. rustup default nightly
    5. rustup target add thumbv7em-none-eabihf
  4. Install the newt build tool for Mynewt. Refer to these scripts…

Download Source Files

  1. Download the source files to ~/pinetime

    1. mkdir ~/pinetime
    2. cd ~/pinetime
    3. git clone --recursive https://github.com/lupyuen/pinetime-rust-mynewt
  2. Update the MCUBoot version number to 1.3.1. Edit ~/pinetime/pinetime-rust-mynewt/project.yml

    Change…

    1. repository.mcuboot:
    2. type: github
    3. vers: 1.5.0

    to…

    1. repository.mcuboot:
    2. type: github
    3. vers: 1.3.1
  3. Download the source code for Mynewt, NimBLE and MCUBoot…

    1. cd ~/pinetime/pinetime-rust-mynewt
    2. newt install

    We should see…

    1. Downloading repository mynewt-core (commit: master) from https://github.com/apache/mynewt-core.git
    2. Downloading repository mynewt-mcumgr (commit: master) from https://github.com/apache/mynewt-mcumgr.git
    3. Downloading repository mynewt-nimble (commit: master) from https://github.com/apache/mynewt-nimble.git
    4. Downloading repository mcuboot (commit: master) from https://github.com/JuulLabs-OSS/mcuboot.git
    5. Making the following changes to the project:
    6. install apache-mynewt-core (1.7.0)
    7. install apache-mynewt-nimble (1.2.0)
    8. install mcuboot (1.3.1)
    9. apache-mynewt-core successfully installed version 1.7.0
    10. apache-mynewt-nimble successfully installed version 1.2.0
    11. Error: Error updating "mcuboot": error: The following untracked working tree files would be overwritten by checkout:
    12. ext/mbedtls/include/mbedtls/check_config.h
    13. ext/mbedtls/include/mbedtls/config.h
    14. Please move or remove them before you switch branches.
    15. Aborting

    Ignore the mcuboot error above and proceed to the next step.

  4. Restore the MCUBoot version number to 1.5.0. Edit ~/pinetime/pinetime-rust-mynewt/project.yml

    Change…

    1. repository.mcuboot:
    2. type: github
    3. vers: 1.3.1

    to…

    1. repository.mcuboot:
    2. type: github
    3. vers: 1.5.0
  5. Download version 1.5.0 of MCUBoot to repos/mcuboot

    1. cd ~/pinetime/pinetime-rust-mynewt/repos
    2. rm -rf mcuboot
    3. git clone --recursive --branch v1.5.0 https://github.com/JuulLabs-OSS/mcuboot

Why are we doing this? Because we are using a more recent version of MCUBoot (1.5.0), but that’s not in sync with the older Mynewt version (1.7.0). This will cause newt install to fail. Hence we do this workaround to force Mynewt to build with the newer MCUBoot.

Build MCUBoot Bootloader

Build the MCUBoot Bootloader…

  1. cd ~/pinetime/pinetime-rust-mynewt
  2. scripts/nrf52/build-boot.sh

We should see…

  1. Linking pinetime/pinetime-rust-mynewt/bin/targets/nrf52_boot/app/boot/mynewt/mynewt.elf
  2. Target successfully built: targets/nrf52_boot
  3. + newt size -v nrf52_boot
  4. Size of Application Image: app
  5. Mem FLASH: 0x0-0x6000
  6. Mem RAM: 0x20000000-0x20010000
  7. FLASH RAM
  8. 90 229 *fill*
  9. 6823 5996 boot_bootutil.a
  10. 124 0 boot_mynewt.a
  11. 18 0 boot_mynewt_flash_map_backend.a
  12. 1182 0 crypto_mbedtls.a
  13. 392 444 hw_bsp_nrf52.a
  14. 52 0 hw_cmsis-core.a
  15. 1280 80 hw_drivers_flash_spiflash.a
  16. 654 1 hw_hal.a
  17. 4192 72 hw_mcu_nordic_nrf52xxx.a
  18. 2006 18776 kernel_os.a
  19. 1930 12 libc_baselibc.a
  20. 1478 256 libs_pinetime_boot.a
  21. 529 40 libs_semihosting_console.a
  22. 544 128 sys_flash_map.a
  23. 2 0 sys_log_modlog.a
  24. 632 29 sys_mfg.a
  25. 30 5 sys_sysinit.a
  26. 48 0 util_mem.a
  27. 100 0 nrf52_boot-sysinit-app.a
  28. 756 0 libgcc.a
  29. Loading compiler pinetime/pinetime-rust-mynewt/repos/apache-mynewt-core/compiler/arm-none-eabi-m4, buildProfile debug
  30. objsize
  31. text data bss dec hex filename
  32. 22792 132 25504 48428 bd2c pinetime/pinetime-rust-mynewt/bin/targets/nrf52_boot/app/boot/mynewt/mynewt.elf

Edit ~/pinetime/pinetime-rust-mynewt/scripts/config.sh

If we’re using ST-Link v2 for flashing PineTime, set swd_device as follows…

  1. # Select ST-Link v2 as SWD Programmer
  2. swd_device=scripts/nrf52/swd-stlink.ocd

If we’re using @ly.lee/openocd-on-raspberry-pi-better-with-swd-on-spi-7dea9caeb590?source=friends_link&sk=df399bfd913d3e262447d28aa5af6b63">Raspberry Pi SPI for flashing PineTime, set swd_device as follows…

  1. # Select Raspberry Pi as SWD Programmer
  2. swd_device=scripts/nrf52-pi/swd-pi.ocd

Flash MCUBoot Bootloader

  1. Edit ~/pinetime/pinetime-rust-mynewt/scripts/nrf52/flash-boot.sh

  2. Change openocd/bin/openocd to the path of our installed openocd (for ST-Link) or openocd-spi (for Raspberry Pi)…

    1. # Flash the device
    2. openocd/bin/openocd \
    3. -f $swd_device \
    4. -f scripts/nrf52/flash-boot.ocd
  3. The path of the built firmware file is defined in ~/pinetime/pinetime-rust-mynewt/scripts/nrf52/flash-boot.ocd. We shouldn’t need to change this.

    1. # For MCUBoot (debugging not supported):
    2. program bin/targets/nrf52_boot/app/boot/mynewt/mynewt.elf.bin verify 0x00000000
  4. Flash the bootloader…

    1. scripts/nrf52/flash-boot.sh
  5. We should see…

    1. > Executing task in folder pinetime-rust-mynewt: bash -c -l ' scripts/nrf52/flash-boot.sh && echo ✅ ◾ ️Done! ' <
    2. + source scripts/config.sh
    3. ++ swd_device=scripts/nrf52/swd-stlink.ocd
    4. + openocd/bin/openocd -f scripts/nrf52/swd-stlink.ocd -f scripts/nrf52/flash-boot.ocd
    5. GNU MCU Eclipse 64-bit Open On-Chip Debugger 0.10.0+dev-00462-gdd1d90111 (2019-01-15-13:49)
    6. Licensed under GNU GPL v2
    7. For bug reports, read
    8. http://openocd.org/doc/doxygen/bugs.html
    9. debug_level: 0
    10. adapter speed: 1000 kHz
    11. force hard breakpoints
    12. Stopping...
    13. target halted due to breakpoint, current mode: Thread
    14. xPSR: 0x21000000 pc: 0x000023a4 msp: 0x2000ff9c
    15. Flashing Bootloader...
    16. target halted due to debug-request, current mode: Thread
    17. xPSR: 0x01000000 pc: 0x000000d8 msp: 0x20010000
    18. Enabled ARM Semihosting to show debug output
    19. semihosting is enabled
    20. ** Programming Started **
    21. auto erase enabled
    22. target halted due to breakpoint, current mode: Thread
    23. xPSR: 0x61000000 pc: 0x2000001e msp: 0x20010000, semihosting
    24. wrote 24576 bytes from file bin/targets/nrf52_boot/app/boot/mynewt/mynewt.elf.bin in 0.729124s (32.916 KiB/s)
    25. ** Programming Finished **
    26. ** Verify Started **
    27. target halted due to breakpoint, current mode: Thread
    28. xPSR: 0x61000000 pc: 0x2000002e msp: 0x20010000, semihosting
    29. verified 22876 bytes in 0.114145s (195.715 KiB/s)
    30. ** Verified OK **
    31. Restarting...
    32. target halted due to debug-request, current mode: Thread
    33. xPSR: 0x01000000 pc: 0x000000d8 msp: 0x20010000, semihosting
    34. **** Done!
  6. For ST-Link, check that the Adapter Speed is set to 1000 kHz. OpenOCD won’t work at higher speeds.

    1. adapter speed: 1000 kHz
  7. If the flashing fails, check whether any openocd processes are running in the background, and kill them.

Build Application Firmware

  1. Build the Application Firmware…

    1. scripts/build-app.sh

    If we see the error Undefined main, run scripts/build-app.sh again. It should fix the error.

  2. Create the application firmware image…

    1. scripts/nrf52/image-app.sh

Flash Application Firmware

  1. Edit ~/pinetime/pinetime-rust-mynewt/scripts/nrf52/flash-app.sh

  2. Change openocd/bin/openocd to the path of our installed openocd (for ST-Link) or openocd-spi (for Raspberry Pi)…

    1. # Flash the device
    2. openocd/bin/openocd \
    3. -f $swd_device \
    4. -f scripts/nrf52/flash-app.ocd
  3. The path of the built firmware file is defined in ~/pinetime/pinetime-rust-mynewt/scripts/nrf52/flash-app.ocd. We shouldn’t need to change this.

    1. program bin/targets/nrf52_my_sensor/app/apps/my_sensor_app/my_sensor_app.img verify 0x00008000
  4. Flash the application…

    1. scripts/nrf52/flash-app.sh
  5. We should see…

    1. > Executing task in folder pinetime-rust-mynewt: bash -c -l ' scripts/nrf52/flash-app.sh && echo ✅ ◾ ️Done! ' <
    2. + source scripts/config.sh
    3. ++ swd_device=scripts/nrf52/swd-stlink.ocd
    4. + openocd/bin/openocd -f scripts/nrf52/swd-stlink.ocd -f scripts/nrf52/flash-app.ocd
    5. GNU MCU Eclipse 64-bit Open On-Chip Debugger 0.10.0+dev-00462-gdd1d90111 (2019-01-15-13:49)
    6. Licensed under GNU GPL v2
    7. For bug reports, read
    8. http://openocd.org/doc/doxygen/bugs.html
    9. debug_level: 0
    10. adapter speed: 1000 kHz
    11. force hard breakpoints
    12. Stopping...
    13. target halted due to debug-request, current mode: Thread
    14. xPSR: 0x61000000 pc: 0x000001ca msp: 0x2000ffd8
    15. Flashing Application...
    16. target halted due to debug-request, current mode: Thread
    17. xPSR: 0x01000000 pc: 0x000000d8 msp: 0x20010000
    18. Enabled ARM Semihosting to show debug output
    19. semihosting is enabled
    20. ** Programming Started **
    21. auto erase enabled
    22. target halted due to breakpoint, current mode: Thread
    23. xPSR: 0x61000000 pc: 0x2000001e msp: 0x20010000, semihosting
    24. wrote 143360 bytes from file bin/targets/nrf52_my_sensor/app/apps/my_sensor_app/my_sensor_app.img in 3.606276s (38.821 KiB/s)
    25. ** Programming Finished **
    26. ** Verify Started **
    27. target halted due to breakpoint, current mode: Thread
    28. xPSR: 0x61000000 pc: 0x2000002e msp: 0x20010000, semihosting
    29. verified 139268 bytes in 0.363909s (373.731 KiB/s)
    30. ** Verified OK **
  6. For ST-Link, check that the Adapter Speed is set to 1000 kHz. OpenOCD won’t work at higher speeds.

    1. adapter speed: 1000 kHz
  7. If the flashing fails, check whether any openocd processes are running in the background, and kill them.

  8. PineTime reboots (with the reset init OpenOCD Command)…

    1. Restarting...
    2. target halted due to debug-request, current mode: Thread
    3. xPSR: 0x01000000 pc: 0x000000d8 msp: 0x20010000, semihosting
    4. Enabled ARM Semihosting to show debug output
    5. semihosting is enabled
  9. PineTime starts MCUBoot Bootloader…

    1. **** Done! Press Ctrl-C to exit...
    2. Starting Bootloader...
    3. Displaying image...
    4. Image displayed
    5. Check button: 0
    6. [INF] Primary image: magic=good, swap_type=0x4, copy_done=0x1, image_ok=0x1
    7. [INF] Scratch: magic=bad, swap_type=0x1, copy_done=0x2, image_ok=0x2
    8. [INF] Boot source: none
    9. [INF] Swap type: none
    10. Waiting 5 seconds for button...
    11. Waited for button: 0
    12. Bootloader done
  10. Finally PineTime starts the Application Firmware…

    1. TMP create temp_stub_0
    2. NET hwid 4a f8 cf 95 6a be c1 f6 89 ba 12 1a
    3. NET standalone node

PineTime Updater

Alternatively, flash the following two files to PineTime with PineTime Updater

  1. MCUBoot Bootloader

    File: bin/targets/nrf52_boot/app/boot/mynewt/mynewt.elf

    Address: 0x0

  2. Rust+Mynewt Firmware

    File: bin/targets/nrf52_my_sensor/app/apps/my_sensor_app/my_sensor_app.elf

    Address: 0x8000

Installation, Build, Flash and Debug Logs

Sample logs for Linux, macOS and Windows may be found in the logs folder

Contents

This repository contains…

rust: Rust Application

Cargo.toml: Rust Build Settings

.cargo: Rust Target Settings

my_sensor_app: Mynewt Application Stub

boot_stub: Mynewt Bootloader Stub

adc_stm32f1: Mynewt Driver for ADC on STM32 F103 (Blue Pill). Used by temp_stm32 internal temperature sensor.

adc_stm32l4: Mynewt Driver for ADC on STM32 L476. Used by temp_stm32 internal temperature sensor.

bc95g: Mynewt Driver for Quectel BC95 NB-IoT module

buffered_serial: Buffered Serial Library used by bc95g NB-IoT driver and gps_l70r GPS driver

custom_sensor: Custom Sensor Definitions for Raw Temperature and Geolocation

esp8266: Mynewt Driver for ESP8266 WiFi module

gps_l70r: Mynewt Driver for Quectel L70-R GPS module

hmac_prng: HMAC pseudorandom number generator with entropy based on internal temperature sensor

low_power: Low Power functions for STM32 F103 (Blue Pill)

mynewt_rust: Helper functions for hosting Rust on Mynewt

nrf24l01: Mynewt Driver for nRF24L01

remote_sensor: Mynewt Driver for Remote Sensor

rust_app: Stub library that will be replaced by the compiled Rust application and Rust crates

rust_libcore: Stub library that will be replaced by the Rust Core Library

semihosting_console: Mynewt Console for Arm Semihosting

sensor_coap: Sensor CoAP Library

sensor_network: Sensor Network Library

temp_stm32: Mynewt Driver for Internal Temperature Sensor on STM32

temp_stub: Mynewt Driver for Stub Temperature Sensor that returns a fixed value

tiny_gps_plus: TinyGPS++ Library ported from Arduino. Used by gps_l70r GPS driver.

scripts: Install, build and deploy scripts

.vscode: Visual Studio Code macros for install, build and deploy

How This Application Was Created

The Windows version of the newt command-line tool in newt/newt.exe was created from

github.com/lupyuen/mynewt-newt

The Mynewt application was originally based on:

mynewt.apache.org/latest/tutorials/sensors/sensor_thingy_lis2dh12_onb.html

mynewt.apache.org/latest/tutorials/sensors/sensor_nrf52_bno055.html

  1. cd /mnt/c
  2. newt new stm32bluepill-mynewt-sensor
  3. cd stm32bluepill-mynewt-sensor
  4. cat project.yml
  5. newt install
  6. newt pkg new -t app apps/my_sensor_app
  7. newt pkg new -t lib libs/semihosting_console
  8. newt target create bluepill_boot
  9. newt target set bluepill_boot bsp=@apache-mynewt-core/hw/bsp/bluepill
  10. newt target set bluepill_boot app=@apache-mynewt-core/apps/boot
  11. newt target set bluepill_boot build_profile=optimized
  12. newt target create bluepill_my_sensor
  13. newt target set bluepill_my_sensor bsp=@apache-mynewt-core/hw/bsp/bluepill
  14. newt target set bluepill_my_sensor app=apps/my_sensor_app
  15. newt target set bluepill_my_sensor build_profile=debug

project.yml should contain

  1. project.name: "my_project"
  2. project.repositories:
  3. - apache-mynewt-core
  4. repository.apache-mynewt-core:
  5. type: github
  6. vers: 1.7.0
  7. user: apache
  8. repo: mynewt-core