/pinetime-rust-mynewt

PineTime Smart Watch firmware based on Rust and Apache Mynewt OS

Primary LanguageAssemblyApache License 2.0Apache-2.0

PineTime Smart Watch Firmware with Apache Mynewt and Embedded Rust

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

  1. Build and Flash Rust+Mynewt Firmware for PineTime Smart Watch

  2. Debug Rust+Mynewt Firmware for PineTime on Raspberry Pi

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

  4. Building a Rust Driver for PineTime’s Touch Controller

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

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

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

Coding nRF52 with Rust and Apache Mynewt on Visual Studio Code

Build Instructions

If you are building from this repository from scratch instead of the Released Packages, here are the steps:

  1. Install rustup with support for nightly target thumbv7em-none-eabihf. Also install Arm toolchain gcc-arm-none-eabi and the newt build tool for Mynewt. Refer to this script...

    scripts/install-pi.sh

  2. repos folder should contain the Mynewt source code, installed by the newt install command:

    cd pinetime-rust-mynewt
    newt install

    Ignore the error Error: Error updating "mcuboot"

  3. Check the rust folder for additional sub-repositories that should be cloned in order to build this project.

  4. Build the bootloader...

    cd pinetime-rust-mynewt
    scripts/nrf52/build-boot.sh
  5. Build the application...

    scripts/build-app.sh

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

  6. Create the application firmware image...

    scripts/nrf52/image-app.sh
  7. Flash the bootloader...

    scripts/nrf52-pi/flash-boot.sh
  8. Flash the application and run it...

    scripts/nrf52-pi/flash-app.sh
  9. Check this article in case of problems...

    Build and Flash Rust+Mynewt Firmware for PineTime Smart Watch

Fixes for Mynewt type conversion build warnings

These fixes should be applied manually when upgrading Mynewt or installing Mynewt from scratch. They suppress the compiler warning messages that stop the Mynewt build for C++ source files.

1️⃣ repos/apache-mynewt-core/kernel/os/include/os/os_mutex.h line 122

    return mu->mu_level;

Change to

    return (os_error_t) mu->mu_level;

2️⃣ repos/apache-mynewt-core/hw/sensor/include/sensor/sensor.h line 847

    return (sensor->s_types & sensor->s_mask & type);

Change to

    return (sensor_type_t) (sensor->s_types & sensor->s_mask & type);

3️⃣ repos/apache-mynewt-core/encoding/tinycbor/include/tinycbor/cbor.h line 201

    {   return encoder->writer->bytes_written; }

Change to

    {   return (CborError) encoder->writer->bytes_written; }

Installation, Build, Flash and Debug Logs

Sample logs for 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

View Rust Documentation

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