Build and Flash Rust+Mynewt Firmware for PineTime Smart Watch

All you need is a Raspberry Pi and a Windows or macOS computer!

UPDATE: This code in this article has been archived in the pre-lvgl branch of pinetime-rust-mynewt. The pinetime-rust-mynewt firmware has been revamped to support Rust Watch Faces on LVGL. Check out the updates

Welcome to the World of Modern IoT Gadgets! If you’re used to old-school IoT gadgets like Arduino Uno that are underpowered and have no networking and display… PineTime Smart Watch will surprise you! (Check out the Pine64 Store)

Raspberry Pi connected to PineTime

PineTime is powered by a Nordic nRF52 Microcontroller with an Arm Cortex-M4F CPU… The same microcontroller found in a high-end gaming mouse!

With built-in colour touchscreen and Bluetooth networking, embedded programming on PineTime becomes really fun and exciting.

Raspberry Pi used for flashing the PineTime firmware

PineTime is a prime example of a real-world, off-the-shelf gadget that’s powerful and yet affordable, because it’s manufactured in huge quantities. But they can be intimidating to newbies who have not programmed such commercial devices.

Today I’ll show you that programming a PineTime is not that hard… All you need is a Raspberry Pi, some wires and a little creativity!

Another view of the improvised Raspberry Pi connection to PineTime


Connect PineTime to Raspberry Pi

Note: This section is obsolete. Please refer to the updated instructions here: https://github.com/lupyuen/visual-embedded-rust/blob/master/README.md

1️⃣ Carefully pry open the PineTime casing. Use tweezers to pivot the shiny battery gently to the side. Be careful not to break the red and black wires that connect the battery to the watch!

Be careful not to break the red and black wires (lower left) that connect the battery to the watch

2️⃣ Just above the battery we see 4 shiny rings. This is the Serial Wire Debug (SWD) Port for PineTime. We’ll use this port to flash our firmware to PineTime. The 4 pins (from left to right) are (Data I/O), (Clock), , .

🛈 What is “flash memory” / “flashing” / “firmware”? Read this

SWD Port at top left: SWDIO, SWDCLK, 3.3V and GND. 5V battery charging pad at lower right. Bent antenna wire is at top centre.

The exposed copper wire at the top centre of the photo is the Bluetooth antenna. Bend it upwards so that it doesn’t come into contact with anything.

Bending the Bluetooth Antenna so that it doesn’t touch anything

3️⃣ At lower right we see a pad marked . We’ll connect this pad to Raspberry Pi to charge the battery. If charging of the battery is not needed during development, we may leave disconnected.

4️⃣ Connect the SWD Port and the 5V Pad (optional) to the Raspberry Pi with Solid-Core Wire (22 AWG) and Female-To-Female Jumper Cables

PineTime Raspberry Pi Wire Colour
SWDIO Header Pin 19 (MOSI) Yellow
SWDCLK Header Pin 23 (SCLK) Blue
3.3V 3.3V Red
GND GND Black
5V 5V Green (Optional)
view raw pi-swd-spi.md hosted with ❤ by GitHub

Some have reported that the SIM Ejector Tool from our phones will also fit perfectly into PineTime’s SWD holes. (Or file the pin down until it fits)

5️⃣ We may use Raspberry Pi Zero, 1, 2, 3 or 4 . The pins on Raspberry Pi to be connected are…

Connecting Raspberry Pi’s SPI port to PineTime. Based on https://pinout.xyz/

Raspberry Pi’s SPI port connected to PineTime. 5V may be disconnected if battery charging is not needed.

6️⃣ The PineTime touchscreen needs to be accessible during development, so I mounted PineTime on a $2 clear box cover from Daiso with Blu Tack and sticky tape.

PineTime and Raspberry Pi mounted on a clear box cover

Be Creative! And send me photos of your PineTime setup…

UPDATE: Check this Reddit Thread for a super-cool Raspberry Pi Zero setup!

Here’s a tip: Colour the Raspberry Pi pins with a marker (one side only) so that we remember which pin to use

Why didn’t I use the SWD cable that was shipped with PineTime? Because the wires were too thin and may lose contact with the SWD connector. Compare that with the Solid Core 22 AWG wire (green), which fits nicely. Also note that the SWD cable is shipped with random colours.


Remove PineTime Flash Protection

Note: This section is obsolete. Please refer to the updated instructions here: https://github.com/lupyuen/visual-embedded-rust/blob/master/README.md

PineTime is shipped with preloaded demo firmware. We need to erase the demo firmware and unprotect PineTime’s flash memory so that we may flash our own firmware.

🛈 What is “flash protection”? Read this

1️⃣ Power on the Raspberry Pi. Open a command prompt and enter the following…

sudo raspi-config

Select

Select

At the command prompt, enter the following…

# Remove folders ~/pinetime-rust-mynewt and ~/openocd-spi (if they exist)
rm -rf ~/pinetime-rust-mynewt
rm -rf ~/openocd-spi
# Download and extract "pinetime-rust-mynewt" folder containing our prebuilt firmware, source files and flashing scripts
sudo apt install -y wget p7zip-full
cd ~
wget https://github.com/lupyuen/pinetime-rust-mynewt/releases/download/v2.0.5/pinetime-rust-mynewt.7z
7z x pinetime-rust-mynewt.7z
rm pinetime-rust-mynewt.7z
# Install build tools for PineTime: VSCode, Rust, gcc, gdb, openocd-spi, newt
cd ~/pinetime-rust-mynewt
scripts/install-pi.sh
# Latest nightly-2020-04-20 fails with asm error, so we use nightly-2020-02-16
source $HOME/.cargo/env
rustup default nightly-2020-02-16
rustup update
rustup target add thumbv7em-none-eabihf
view raw install-pi2.sh hosted with ❤ by GitHub

2️⃣ At the prompt, press Enter to select the default option:

If you see this error…

Cloning into 'openocd-spi/jimtcl'...
fatal: unable to access 'http://repo.or.cz/r/jimtcl.git/': Recv failure: Connection reset by peer
fatal: clone of 'http://repo.or.cz/r/jimtcl.git' into submodule path '/private/tmp/aa/openocd-spi/jimtcl' failed

It means that the sub-repository for one of the dependencies is temporarily down. You may download the pre-built binaries from this link. Then copy the executable to

3️⃣ When the installation has completed, enter the following at the command prompt…

# Remove flash protection from PineTime and erase demo firmware
cd ~/pinetime-rust-mynewt
scripts/nrf52-pi/flash-unprotect.sh

4️⃣ We should see

If you see and nothing else after that…

Info : BCM2835 SPI SWD driver
Info : SWD only mode enabled
Info : clock speed 31200 kHz

Then the connection to the SWD Port is probably loose, check the pins. Also enter and confirm that the SPI port has been enabled.

If you see this instead…

openocd/bin/openocd: cannot execute binary file: Exec format error

Then probably didn’t run correctly. To fix this, copy the executable like this…

cp $HOME/openocd-spi/src/openocd $HOME/pinetime-rust-mynewt/openocd/bin/openocd

5️⃣ Shut down and power off your Raspberry Pi. Wait 30 seconds for the red and green LEDs on your Pi to turn off. Power on your Pi. Enter the same commands at a command prompt…

# Remove flash protection from PineTime and erase demo firmware
cd ~/pinetime-rust-mynewt
scripts/nrf52-pi/flash-unprotect.sh

6️⃣ We should see

PineTime’s demo firmware has been erased and the flash protection has been removed.

🛈 What is OpenOCD? Why Raspberry Pi and not ROCK64 or Nvidia Jetson Nano? Read this


Flash Bootloader and Application to PineTime

We’re now ready to flash our own firmware to PineTime! We’ll be flashing the PineTime firmware that’s based on open-source Apache Mynewt embedded operating system. Mynewt OS contains two components that we shall flash to PineTime…

Mynewt Bootloader: This is the C code that’s run whenever we power on PineTime. The Bootloader executes the Mynewt Application upon startup.

Mynewt Application: Contains a Rust application that controls the PineTime functions, and low-level system functions written in C.

The Bootloader and Application firmware image files may be found at these locations…

Mynewt Component Flash Memory Address Location of Firmware Image
Bootloader 0x0 ~/pinetime-rust-mynewt/bin/targets/nrf52_boot/app/apps/boot_stub/boot_stub.elf.bin
Application 0x8000 ~/pinetime-rust-mynewt/bin/targets/nrf52_my_sensor/app/apps/my_sensor_app/my_sensor_app.img

From https://github.com/lupyuen/pinetime-rust-mynewt/blob/master/hw/bsp/nrf52/bsp.yml

🛈 What is a Bootloader? Read this

1️⃣ To flash Mynewt Bootloader to PineTime, enter the following at the command prompt…

# Flash Mynewt Bootloader to PineTime
cd ~/pinetime-rust-mynewt
scripts/nrf52-pi/flash-boot.sh
view raw flash-boot.sh hosted with ❤ by GitHub

Commands to flash Mynewt Bootloader to PineTime

2️⃣ We should see

pi@raspberrypi:~/pinetime-rust-mynewt $ scripts/nrf52-pi/flash-boot.sh
+ openocd/bin/openocd -f scripts/nrf52-pi/swd-pi.ocd -f scripts/nrf52/flash-boot.ocd
Open On-Chip Debugger 0.10.0+dev-01126-g307e591f (2020-01-20-21:33)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'swd'
force hard breakpoints
Info : BCM2835 SPI SWD driver
Info : SWD only mode enabled
Info : clock speed 31200 kHz
Info : SWD DPIDR 0x2ba01477
Info : nrf52.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Listening on port 3333 for gdb connections
Stopping...
target halted due to debug-request, current mode: Thread
xPSR: 0x61000000 pc: 0x000001ca msp: 0x2000ffe8
Flashing Bootloader...
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x000000d8 msp: 0x20010000
Enabled ARM Semihosting to show debug output
** Programming Started **
Info : nRF52832-QFAA(build code: E1) 512kB Flash, 64kB RAM
Warn : Adding extra erase range, 0x00000b78 .. 0x00000fff
** Programming Finished **
** Verify Started **
** Verified OK **
Restarting...
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x000000d8 msp: 0x20010000, semihosting
**** Done!

Log of Mynewt Bootloader flashing. From https://github.com/lupyuen/pinetime-rust-mynewt/blob/master/logs/load-bootloader-pi.log

3️⃣ To flash Mynewt Application to PineTime, enter the following at the command prompt…

# Flash Rust+Mynewt Application to PineTime
cd ~/pinetime-rust-mynewt
scripts/nrf52-pi/flash-app.sh
view raw flash-app.sh hosted with ❤ by GitHub

Commands to flash Mynewt Application to PineTime

4️⃣ We should see

pi@raspberrypi:~/pinetime-rust-mynewt $ scripts/nrf52-pi/flash-app.sh
+ openocd/bin/openocd -f scripts/nrf52-pi/swd-pi.ocd -f scripts/nrf52/flash-app.ocd
Open On-Chip Debugger 0.10.0+dev-01126-g307e591f (2020-01-20-21:33)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'swd'
force hard breakpoints
Info : BCM2835 SPI SWD driver
Info : SWD only mode enabled
Info : clock speed 31200 kHz
Info : SWD DPIDR 0x2ba01477
Info : nrf52.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Listening on port 3333 for gdb connections
Stopping...
target halted due to debug-request, current mode: Thread
xPSR: 0x61000000 pc: 0x000081ee 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
** Programming Started **
Info : nRF52832-QFAA(build code: E1) 512kB Flash, 64kB RAM
Warn : Adding extra erase range, 0x0003e820 .. 0x0003efff
** Programming Finished **
** Verify Started **
** Verified OK **
Restarting...
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x000000d8 msp: 0x20010000, semihosting
Enabled ARM Semihosting to show debug output
**** Done! Press Ctrl-C to exit...

Log of Mynewt Application flashing. From https://github.com/lupyuen/pinetime-rust-mynewt/blob/master/logs/load-application-pi.log

5️⃣ The new PineTime firmware runs after the flashing has been completed. Here are the debugging messages produced by our Rust application…

Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
TMP create temp_stub_0
NET hwid 4a f8 cf 95 6a be c1 f6 89 ba 12 1a
NET standalone node
Rust test display

Log of Mynewt Application executing. From https://github.com/lupyuen/pinetime-rust-mynewt/blob/master/logs/load-application-pi.log

6️⃣ And we should see on the PineTime screen…

Our Rust Application rendering graphics and text to the PineTime display

7️⃣ Press to stop the display of debugging messages.

We have flashed a simple Rust application located at that renders some graphics and text to the PineTime display…

/// Render some graphics and text to the PineTime display. `start_display()` must have been called earlier.
pub fn test_display() -> MynewtResult<()> {
console::print("Rust test display\n"); console::flush();
// Create black background
let background = Rectangle::<Rgb565>
::new( Coord::new( 0, 0 ), Coord::new( 239, 239 ) ) // Rectangle coordinates
.fill( Some( Rgb565::from(( 0x00, 0x00, 0x00 )) ) ); // Black
// Create circle
let circle = Circle::<Rgb565>
::new( Coord::new( 40, 40 ), 40 ) // Circle centre and radius
.fill( Some( Rgb565::from(( 0xff, 0x00, 0xff )) ) ); // Magenta
// Create square
let square = Rectangle::<Rgb565>
::new( Coord::new( 60, 60 ), Coord::new( 150, 150 ) ) // Square coordinates
.fill( Some( Rgb565::from(( 0x00, 0x00, 0xff )) ) ); // Blue
// Create text
let text = fonts::Font12x16::<Rgb565>
::render_str("I AM PINETIME") // Text to be rendered
.stroke( Some( Rgb565::from(( 0x00, 0x00, 0x00 )) ) ) // Black text
.fill( Some( Rgb565::from(( 0xff, 0xff, 0x00 )) ) ) // Yellow background
.translate( Coord::new( 20, 16 )); // Shift the text
// Render background, circle, square and text to display
druid::draw_to_display(background);
druid::draw_to_display(circle);
druid::draw_to_display(square);
druid::draw_to_display(text);
// Return success to the caller
Ok(())
}
view raw display.rs hosted with ❤ by GitHub

Our Rust application that renders graphics and text. From https://github.com/lupyuen/pinetime-rust-mynewt/blob/master/rust/app/src/display.rs

Here’s a good introduction to Rust programming and here’s a good overview of Rust

The Rust application references the Rust library (crate) named [embedded_graphics]. That’s where , , , … are defined.

How do we modify this Rust application and rebuild the firmware? We have 3 options:

[Option 1] Build the firmware on a Windows computer, and copy to Pi for flashing

[Option 2] Build the firmware on a macOS computer, and copy to Pi for flashing

[Option 3] Build the firmware on a (powerful) Raspberry Pi (or PineBook Pro) and flash directly


[Option 1] Install PineTime Build Tools on Windows

(If you’re building firmware on macOS, skip to the next section. If you’re building firmware on Raspberry Pi, skip to the section “[Option 3] Install Build Tools on Raspberry Pi”)

To build your own firmware on a Windows computer, follow these instructions to install the build tools for Rust and Mynewt OS on Windows…

1️⃣ Download the file attached below…

Expand the file with 7zip…

2️⃣ Click here to install Build Tools For Visual Studio 2019:

Build Tools For Visual Studio 2019

Click the tab

Select the following components:

  1. (This should be automatically selected)

3️⃣ Install according to the instructions here:

Click the link provided to download

Launch the downloaded file

If you see the message “”…

Click

Click

At the prompt, press Enter to select the default option:

4️⃣ Open the Command Prompt and enter…

# Install Rust build tools for Arm Cortex
rustup default nightly
rustup update
rustup target add thumbv7em-none-eabihf

5️⃣ Install GNU Arm Embedded Toolchain for Windows from Arm Developer Website…

Select this option at the last install step:

6️⃣ Install VSCode…

🛈 What is VSCode? Is it related to Visual Studio? How is Microsoft involved? Read this


[Option 2] Install PineTime Build Tools on macOS

(If you’re building firmware on Windows, skip to the section “Build PineTime Firmware”)

To build your own firmware on a macOS computer, follow these instructions to install the build tools for Rust and Mynewt OS on macOS…

1️⃣ Download the file attached below…

Expand the file with Keka…

2️⃣ Install according to the instructions here:

At the prompt, press Enter to select the default option:

3️⃣ Open the Command Prompt and enter…

# Install Rust build tools for Arm Cortex
source $HOME/.cargo/env
rustup default nightly
rustup update
rustup target add thumbv7em-none-eabihf
# Install Go and newt (build tool for Mynewt OS)
cd pinetime-rust-mynewt
scripts/install-mac.sh

In case of problems, compare with this installation log

5️⃣ Install GNU Arm Embedded Toolchain for macOS from Arm Developer Website…

Expand the compressed file with Keka.

Add the uncompressed folder to your environment variable in your and files, like this:

export PATH=”/Users/MYUSERNAME/gcc-arm-none-eabi-8–2019-q3-update/bin:$PATH”

6️⃣ Install VSCode…

🛈 What is VSCode? Is it related to Visual Studio? How is Microsoft involved? Read this


[Option 3] Install PineTime Build Tools on Raspberry Pi

(If you’re building firmware on Windows or macOS, skip this section)

The PineTime Build Tools are already installed on our Raspberry Pi when we executed earlier.

Launching VSCode on Raspberry Pi

Launch VSCode by clicking the Raspberry Pi Menu (top left corner) → Programming → Code OSS Headmelted

🛈 What is VSCode? Is it related to Visual Studio? How is Microsoft involved? Read this

Building PineTime Firmware on Raspberry Pi 4 with VSCode. Displayed on Xiaomi 65-inch 4K TV.

If you’re building firmware on PineBook Pro…

To install the build tools on PineBook Pro, check these instructions


Build PineTime Firmware on Windows, macOS and Raspberry Pi

We’re all set to build our own PineTime Firmware with VSCode!

1️⃣ Launch VSCode. Click
Select the downloaded folder

When prompted to open the workspace, click

When prompted to install Extension Recommendations, click

2️⃣ Edit the Rust demo application located at

Change to your own message.

Editing the Rust demo application with VSCode

3️⃣ Click

This builds the Mynewt Application, which includes our Rust application.

Build Mynewt Application Log

If you see the message , rebuild the application by clicking

In case of problems, compare with this build log

4️⃣ Click

This creates the Firmware Image File for our Mynewt Application. The file is located at

Image Mynewt Application Log

In case of problems, compare with this image log

Building PineTime Firmware on Windows with VSCode


Flash New PineTime Firmware

Finally let’s flash our new firmware to PineTime!

1️⃣ If you used a Windows or macOS computer to build the firmware…

Copy the application firmware image from
on your Windows/macOS computer to the same folder on your Raspberry Pi.

I used Cyberduck to copy the file to Raspberry Pi. This step is not needed if you used a Pi to build the firmware.

Location of the Mynewt Application Firmware Image

2️⃣ On our Raspberry Pi, enter the following at the command prompt…

# Flash Rust+Mynewt Application to PineTime
cd ~/pinetime-rust-mynewt
scripts/nrf52-pi/flash-app.sh
view raw flash-app.sh hosted with ❤ by GitHub

Commands to flash Mynewt Application to PineTime

3️⃣ We should see…

pi@raspberrypi:~/pinetime-rust-mynewt $ scripts/nrf52-pi/flash-app.sh
+ openocd/bin/openocd -f scripts/nrf52-pi/swd-pi.ocd -f scripts/nrf52/flash-app.ocd
Open On-Chip Debugger 0.10.0+dev-01126-g307e591f (2020-01-20-21:33)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'swd'
force hard breakpoints
Info : BCM2835 SPI SWD driver
Info : SWD only mode enabled
Info : clock speed 31200 kHz
Info : SWD DPIDR 0x2ba01477
Info : nrf52.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Listening on port 3333 for gdb connections
Stopping...
target halted due to debug-request, current mode: Thread
xPSR: 0x61000000 pc: 0x000081ee 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
** Programming Started **
Info : nRF52832-QFAA(build code: E1) 512kB Flash, 64kB RAM
Warn : Adding extra erase range, 0x0003e820 .. 0x0003efff
** Programming Finished **
** Verify Started **
** Verified OK **
Restarting...
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x000000d8 msp: 0x20010000, semihosting
Enabled ARM Semihosting to show debug output
**** Done! Press Ctrl-C to exit...

Log of Mynewt Application flashing. From https://github.com/lupyuen/pinetime-rust-mynewt/blob/master/logs/load-application-pi.log

4️⃣ Our modified firmware is now running on PineTime! Press to exit.

Explore the Rust code here to understand how the features were implemented in PineTime

If you prefer to build PineTime firmware and create the firmware image via the command line, here are the commands…

For Windows…

:: Build Rust+Mynewt Application and create Application Firmware Image for PineTime
cd pinetime-rust-mynewt
scripts\build-app.cmd
scripts\nrf52\image-app.cmd

Build firmware and create firmware image on Windows

For macOS and Raspberry Pi…

# Build Rust+Mynewt Application and create Application Firmware Image for PineTime
cd ~/pinetime-rust-mynewt
scripts/build-app.sh
scripts/nrf52/image-app.sh

Build firmware and create firmware image on macOS and Raspberry Pi

If you see the error message , run or again and it should be fixed.


Debug PineTime Firmware with Raspberry Pi

With only a Raspberry Pi, we may debug the firmware on PineTime: Step into the program line by line, set a breakpoint to pause execution, inspect variables at runtime, …

Check the articleDebug Rust+Mynewt Firmware for PineTime on Raspberry Pi for details

[Watch video on YouTube]

Debugging PineTime Firmware with Raspberry Pi


💎 Advanced Topic: Build druid UI Firmware for PineTime

Our demo application can render graphics but it’s not interactive like a real watch app… Watch apps should respond to our touch! Like this… 抖音视频

This Rust demo application that responds to touch was programmed with the druid UI framework like this…

pub fn launch() {
console::print("Rust launch\n"); console::flush();
// Build a new window
let main_window = WindowDesc::new(ui_builder);
// Application state is initially 0
let data = 0_u32;
// Launch the window with the initial application state
AppLauncher::with_window(main_window)
.use_simple_logger()
.launch(data)
.expect("launch failed");
}
/// Build the UI for the window. The application state consists of 1 value: `count` of type `u32`.
fn ui_builder() -> impl Widget<u32> { // `u32` is the application state
console::print("Rust UI builder\n"); console::flush();
// Create a line of text based on a counter value
let text =
LocalizedString::new("hello-counter")
.with_arg(
"count",
// Closure that will fetch the counter value...
| data: &u32, _env | // Closure will receive the application state and environment
(*data).into() // We return the counter value in the application state
);
// Create a label widget to display the text
let label = Label::new(text);
// Create a button widget to increment the counter
let button = Button::new(
"increment", // Text to be shown
// Closure that will be called when button is tapped...
| _ctx, data, _env | // Closure will receive the context, application state and environment
*data += 1 // We increment the counter
);
// Create a column for the UI
let mut col = Column::new();
// Add the label widget to the column, centered with padding
col.add_child(
Align::centered(
Padding::new(5.0, label)
),
1.0
);
// Add the button widget to the column, with padding
col.add_child(
Padding::new(5.0, button),
1.0
);
// Return the column containing the label and button widgets
col
}

druid UI application. From https://github.com/lupyuen/pinetime-rust-mynewt/blob/master/rust/app/src/ui.rs

There’s a lot happening in this short piece of code… Check this article for the details.

To build this druid UI app instead of the previous graphics display app, open VSCode on your Windows or macOS computer. Edit the Rust application configuration file

Edit the file such that is commented out, and is uncommented…

# Optional features
[features]
default = [ # Select the conditional compiled features
# "display_app", # Disable graphics display app
"ui_app", # Enable druid UI app
# "use_float", # Disable floating-point support e.g. GPS geolocation
]
view raw Cargo-ui.toml hosted with ❤ by GitHub

From https://github.com/lupyuen/pinetime-rust-mynewt/blob/master/rust/app/Cargo.toml

Repeat the instructions above to build the PineTime firmware on your computer, then flash the firmware from Raspberry Pi to PineTime. And now you’ll have an interactive watch app on your PineTime!

If you wish to flash the druid UI firmware without rebuilding…

Download to your Raspberry Pi the file attached below…

Then flash the application firmware image located at

💎 In the video above, some touches don’t seem to update the counter. If you have any ideas why, lemme know! Here’s the touchscreen driver in Rust. This article explains how it works.

Rust druid app with touchable button running on PineTime

Here’s a video of PineTime connected to a Raspberry Pi 4 that’s building the druid app with VSCode… 抖音视频

[Watch video on YouTube]

Building druid app for PineTime with VSCode on RaspberryPi 4. Uses the “Task Runner” extension: https://marketplace.visualstudio.com/items?itemName=SanaAjani.taskrunnercode&ssr=false


💎 Advanced Topic: Flash and Debug PineTime with ST-Link

If we’re doing serious development with PineTime, I recommend getting an ST-Link v2 USB dongle ($2) that connects PineTime directly to our Windows, macOS or Linux computer.

ST-Link allows us to flash PineTime directly from our computer, and it even supports firmware debugging (setting breakpoints, checking values of variables at runtime, …)

Here’s how we connect PineTime to ST-Link…

PineTime connected to ST-Link

Connecting PineTime to ST-Link

Instructions for flashing and debugging may be found in the article Install Apache Mynewt and Embedded Rust for nRF52 and Visual Studio Code on Windows and macOS under the sections “Flash The Firmware” and “Run The Program”.

Also check this article that explains the VSCode Debugger configuration files: Debug RIOT-OS on PineTime with VSCode


What’s Next?

Find out how to debug PineTime firmware with a Raspberry Pi…

We have been using a modified version of OpenOCD that’s faster and more reliable as explained here…

Our PineTime firmware bundles the Watch App together with the operating system (Mynewt OS). If PineTime were a real consumer gadget like an Android phone, we would expect the Watch App to be installed separately from the operating system.

I’m working on a solution for this.

Stay Tuned!

Proposed plan to unbundle Watch Apps from PineTime firmware