Skip to content

lupyuen/pinetime-logo-loader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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. Build and Flash Rust+Mynewt Firmware for PineTime Smart Watch

  4. 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. Building a Rust Driver for PineTime’s Touch Controller

  7. Porting [druid] Rust Widgets to PineTime Smart Watch

  8. Optimising PineTime’s Display Driver with Rust and Mynewt

  9. 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. My First Week As Embedded FOSS Advocate

  22. Rust Documentation

RSS Feed

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

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...

    "OpenOCD on Raspberry Pi: Better with SWD on SPI"

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

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

    For Majaro and Arch Linux...

    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...

    # Latest nightly-2020-04-20 fails with asm error, so we use nightly-2020-02-16
    source $HOME/.cargo/env
    rustup update
    rustup default nightly
    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...

    mkdir ~/pinetime
    cd ~/pinetime
    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...

    repository.mcuboot:
        type: github
        vers: 1.5.0

    to...

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

    cd ~/pinetime/pinetime-rust-mynewt
    newt install

    We should see...

    Downloading repository mynewt-core (commit: master) from https://github.com/apache/mynewt-core.git
    Downloading repository mynewt-mcumgr (commit: master) from https://github.com/apache/mynewt-mcumgr.git
    Downloading repository mynewt-nimble (commit: master) from https://github.com/apache/mynewt-nimble.git
    Downloading repository mcuboot (commit: master) from https://github.com/JuulLabs-OSS/mcuboot.git
    Making the following changes to the project:
        install apache-mynewt-core (1.7.0)
        install apache-mynewt-nimble (1.2.0)
        install mcuboot (1.3.1)
    apache-mynewt-core successfully installed version 1.7.0
    apache-mynewt-nimble successfully installed version 1.2.0
    Error: Error updating "mcuboot": error: The following untracked working tree files would be overwritten by checkout:
            ext/mbedtls/include/mbedtls/check_config.h
            ext/mbedtls/include/mbedtls/config.h
    Please move or remove them before you switch branches.
    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...

    repository.mcuboot:
        type: github
        vers: 1.3.1

    to...

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

    cd ~/pinetime/pinetime-rust-mynewt/repos
    rm -rf mcuboot
    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...

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

We should see...

Linking pinetime/pinetime-rust-mynewt/bin/targets/nrf52_boot/app/boot/mynewt/mynewt.elf
Target successfully built: targets/nrf52_boot
+ newt size -v nrf52_boot
Size of Application Image: app
Mem FLASH: 0x0-0x6000
Mem RAM: 0x20000000-0x20010000
  FLASH     RAM 
     90     229 *fill*
   6823    5996 boot_bootutil.a
    124       0 boot_mynewt.a
     18       0 boot_mynewt_flash_map_backend.a
   1182       0 crypto_mbedtls.a
    392     444 hw_bsp_nrf52.a
     52       0 hw_cmsis-core.a
   1280      80 hw_drivers_flash_spiflash.a
    654       1 hw_hal.a
   4192      72 hw_mcu_nordic_nrf52xxx.a
   2006   18776 kernel_os.a
   1930      12 libc_baselibc.a
   1478     256 libs_pinetime_boot.a
    529      40 libs_semihosting_console.a
    544     128 sys_flash_map.a
      2       0 sys_log_modlog.a
    632      29 sys_mfg.a
     30       5 sys_sysinit.a
     48       0 util_mem.a
    100       0 nrf52_boot-sysinit-app.a
    756       0 libgcc.a
Loading compiler pinetime/pinetime-rust-mynewt/repos/apache-mynewt-core/compiler/arm-none-eabi-m4, buildProfile debug

objsize
   text    data     bss     dec     hex filename
  22792     132   25504   48428    bd2c pinetime/pinetime-rust-mynewt/bin/targets/nrf52_boot/app/boot/mynewt/mynewt.elf

Select the OpenOCD Interface: ST-Link or Raspberry Pi SPI

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

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

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

If we're using Raspberry Pi SPI for flashing PineTime, set swd_device as follows...

#  Select Raspberry Pi as SWD Programmer
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)...

    #  Flash the device
    openocd/bin/openocd \
        -f $swd_device \
        -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.

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

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

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

    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...

    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...

    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)...

    #  Flash the device
    openocd/bin/openocd \
        -f $swd_device \
        -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.

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

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

    > Executing task in folder pinetime-rust-mynewt: bash -c -l ' scripts/nrf52/flash-app.sh && echo ✅ ◾ ️Done! ' <
    
    + source scripts/config.sh
    ++ swd_device=scripts/nrf52/swd-stlink.ocd
    + openocd/bin/openocd -f scripts/nrf52/swd-stlink.ocd -f scripts/nrf52/flash-app.ocd
    GNU MCU Eclipse 64-bit Open On-Chip Debugger 0.10.0+dev-00462-gdd1d90111 (2019-01-15-13:49)
    Licensed under GNU GPL v2
    For bug reports, read
            http://openocd.org/doc/doxygen/bugs.html
    debug_level: 0
    adapter speed: 1000 kHz
    force hard breakpoints
    Stopping...
    target halted due to debug-request, current mode: Thread 
    xPSR: 0x61000000 pc: 0x000001ca msp: 0x2000ffd8
    
    Flashing Application...
    target halted due to debug-request, current mode: Thread 
    xPSR: 0x01000000 pc: 0x000000d8 msp: 0x20010000
    Enabled ARM Semihosting to show debug output
    semihosting is enabled
    ** Programming Started **
    auto erase enabled
    target halted due to breakpoint, current mode: Thread 
    xPSR: 0x61000000 pc: 0x2000001e msp: 0x20010000, semihosting
    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)
    ** Programming Finished **
    ** Verify Started **
    target halted due to breakpoint, current mode: Thread 
    xPSR: 0x61000000 pc: 0x2000002e msp: 0x20010000, semihosting
    verified 139268 bytes in 0.363909s (373.731 KiB/s)
    ** Verified OK **
    
  6. For ST-Link, check that the Adapter Speed is set to 1000 kHz. OpenOCD won't work at higher speeds.

    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)...

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

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

    TMP create temp_stub_0
    NET hwid 4a f8 cf 95 6a be c1 f6 89 ba 12 1a 
    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

cd /mnt/c
newt new stm32bluepill-mynewt-sensor
cd stm32bluepill-mynewt-sensor
cat project.yml

newt install
newt pkg new -t app apps/my_sensor_app
newt pkg new -t lib libs/semihosting_console

newt target create bluepill_boot
newt target set bluepill_boot bsp=@apache-mynewt-core/hw/bsp/bluepill
newt target set bluepill_boot app=@apache-mynewt-core/apps/boot
newt target set bluepill_boot build_profile=optimized

newt target create bluepill_my_sensor
newt target set bluepill_my_sensor bsp=@apache-mynewt-core/hw/bsp/bluepill
newt target set bluepill_my_sensor app=apps/my_sensor_app
newt target set bluepill_my_sensor build_profile=debug

project.yml should contain

project.name: "my_project"

project.repositories:
    - apache-mynewt-core

repository.apache-mynewt-core:
    type: github
    vers: 1.7.0
    user: apache
    repo: mynewt-core