Skip to content

Commit e492b67

Browse files
committed
Add P8 smartwatch configuration
* Split into pinetime (default) and p8 target * Change LFCLK to LFRC to support devices without LF crystal * Support various SPI flash chips by ignoring JEDEC IDs * Use recent mynewt-core and mcu-tools
1 parent 2e1a66e commit e492b67

19 files changed

+164
-41
lines changed

.vscode/launch-nrf52-pi.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
// Application Executable to be flashed before debugging. Note that the Application ELF image does not contain a valid Image Header, so we must install the Stub Bootloader.
1414
"executable": "bin/targets/nrf52_my_sensor/app/apps/my_sensor_app/my_sensor_app.elf",
1515
// Uncomment one of these lines to debug MCUBoot or Stub Bootloader:
16-
// "executable": "bin/targets/nrf52_boot/app/boot/mynewt/mynewt.elf",
17-
// "executable": "bin/targets/nrf52_boot/app/apps/boot_stub/boot_stub.elf",
16+
// "executable": "bin/targets/pinetime/app/boot/mynewt/mynewt.elf",
17+
// "executable": "bin/targets/pinetime/app/apps/boot_stub/boot_stub.elf",
1818
"device": "nRF52832",
1919
// Arm System View Description, from apache-mynewt-core/hw/mcu/nordic/src/ext/nrfx/mdk
2020
"svdFile": "scripts/nrf52/nrf52.svd",

.vscode/launch-nrf52.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
// Application Executable to be flashed before debugging. Note that the Application ELF image does not contain a valid Image Header, so we must install the Stub Bootloader.
1414
"executable": "bin/targets/nrf52_my_sensor/app/apps/my_sensor_app/my_sensor_app.elf",
1515
// Uncomment one of these lines to debug MCUBoot or Stub Bootloader:
16-
// "executable": "bin/targets/nrf52_boot/app/boot/mynewt/mynewt.elf",
17-
// "executable": "bin/targets/nrf52_boot/app/apps/boot_stub/boot_stub.elf",
16+
// "executable": "bin/targets/pinetime/app/boot/mynewt/mynewt.elf",
17+
// "executable": "bin/targets/pinetime/app/apps/boot_stub/boot_stub.elf",
1818
"device": "nRF52832",
1919
// Arm System View Description, from apache-mynewt-core/hw/mcu/nordic/src/ext/nrfx/mdk
2020
"svdFile": "scripts/nrf52/nrf52.svd",

.vscode/launch.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
// Application Executable to be flashed before debugging. Note that the Application ELF image does not contain a valid Image Header, so we must install the Stub Bootloader.
1414
"executable": "bin/targets/nrf52_my_sensor/app/apps/my_sensor_app/my_sensor_app.elf",
1515
// Uncomment one of these lines to debug MCUBoot or Stub Bootloader:
16-
// "executable": "bin/targets/nrf52_boot/app/boot/mynewt/mynewt.elf",
17-
// "executable": "bin/targets/nrf52_boot/app/apps/boot_stub/boot_stub.elf",
16+
// "executable": "bin/targets/pinetime/app/boot/mynewt/mynewt.elf",
17+
// "executable": "bin/targets/pinetime/app/apps/boot_stub/boot_stub.elf",
1818
"device": "nRF52832",
1919
// Arm System View Description, from apache-mynewt-core/hw/mcu/nordic/src/ext/nrfx/mdk
2020
"svdFile": "scripts/nrf52/nrf52.svd",

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ The goal of this firmware is to provide a mean for the user to OTA a new firmwar
7070
- Clone the project and `cd` into it
7171
- Init and update submodules : `git submodule update --init --recursive`
7272
- Configure mynewt : `newt upgrade`
73-
- Build : `scripts/nrf52/build-boot.sh`. The firmware is generated in `bin/targets/nrf52_boot/app/@mcuboot/boot/mynewt/mynewt.elf` and the DFU file for the reloader : `reloader/build-pinetime/reloader-mcuboot.zip`
73+
- Build : `scripts/nrf52/build-boot.sh`. The firmware is generated in `bin/targets/pinetime/app/@mcuboot/boot/mynewt/mynewt.elf` and the DFU file for the reloader : `reloader/build-pinetime/reloader-mcuboot.zip`
74+
75+
You can also build the firmware for the P8 watch, which has a slightly different pin mapping. The `build-boot.sh` accepts an optional argument (default: `pinetime`, options: `pinetime`, `p8`) to specify the target to build.
76+
77+
- Build : `scripts/nrf52/build-boot.sh p8`. The firmware is generated in `bin/targets/p8/app/@mcuboot/boot/mynewt/mynewt.elf` and the DFU file for the reloader : `reloader/build-p8/reloader-mcuboot.zip`
7478

7579
## About the code
7680

hw/bsp/nrf52/syscfg.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,18 @@ syscfg.vals:
5454

5555
###########################################################################
5656
# SPI Flash
57-
# XTX XT25F32B 32 Mb (4 MB) SPI NOR Flash (similar to QuadSPI SPI NOR Flash like Macronix 32 Mb (4 MB) MX25L3233F)
58-
# manufacturer (0x0b), device (0x15), memory type (0x40), density (0x16)
5957
# Settings below are documented at https://github.com/apache/mynewt-core/blob/master/hw/drivers/flash/spiflash/syscfg.yml
6058

6159
SPIFLASH: 1 # Enable SPI Flash
6260
SPIFLASH_SPI_NUM: 0 # SPI Interface 0
6361
SPIFLASH_SPI_CS_PIN: 5 # SPI interface CS pin: P0.05/AIN3, SPI-CE# (SPI-NOR)
6462
SPIFLASH_BAUDRATE: 8000 # Requested baudrate, 8000 is the fastest baudrate supported by nRF52832
63+
6564
SPIFLASH_MANUFACTURER: 0x0B # Expected SpiFlash manufacturer as read by Read JEDEC ID command 9FH
6665
SPIFLASH_MEMORY_TYPE: 0x40 # Expected SpiFlash memory type as read by Read JEDEC ID command 9FH
66+
SPIFLASH_IGNORE_MANUFACTURER: 1 # Many P8 watches contain a whole zoo of different SPI flash chips across variants
67+
SPIFLASH_IGNORE_MEMORY_TYPE: 1 # The chips still behave the same as the PineTime one.
68+
6769
SPIFLASH_MEMORY_CAPACITY: 0x16 # Expected SpiFlash memory capactity as read by Read JEDEC ID command 9FH (2 ^ 0x16 = 32 Mb)
6870
SPIFLASH_SECTOR_COUNT: 1024 # Number of sectors: 1024 sectors of 4 KB each
6971
SPIFLASH_SECTOR_SIZE: 4096 # TODO Number of bytes that can be erased at a time: 4 KB sector size
@@ -92,7 +94,7 @@ syscfg.vals:
9294
COREDUMP_FLASH_AREA: FLASH_AREA_IMAGE_1
9395

9496
MCU_DCDC_ENABLED: 1
95-
MCU_LFCLK_SOURCE: LFXO
97+
MCU_LFCLK_SOURCE: LFRC # Compatible with all variants, with or without external crystal
9698
BOOT_SERIAL_DETECT_PIN: 20
9799

98100
###########################################################################

libs/pinetime_boot/pkg.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pkg.deps:
3333
# Mynewt consolidates the initialisation functions into sysinit()
3434
# and calls them according to the Stage number, highest number first.
3535
# Stage 500 is used by Sensor Creator so we use Stage 600 onwards.
36-
# Generated sysinit() for Bootloader: bin/targets/nrf52_boot/generated/src/nrf52_boot-sysinit-app.c
36+
# Generated sysinit() for Bootloader: bin/targets/pinetime/generated/src/pinetime-sysinit-app.c
3737

3838
pkg.init:
3939
# pinetime_boot should be initialised last, when SPI and Semihosting Console are up

libs/pinetime_boot/src/blink.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
#include <os/mynewt.h>
2222
#include <hal/hal_gpio.h>
2323

24-
#define PUSH_BUTTON_IN 13 // GPIO Pin P0.13: PUSH BUTTON_IN
25-
2624
/// GPIO settings for the backlight: LCD_BACKLIGHT_{LOW,MID,HIGH} (P0.14, 22, 23)
2725
static const uint8_t backlights[] = {
2826
14, // Low Backlight
@@ -130,6 +128,6 @@ static void delay_ms(uint32_t ms) {
130128
uint8_t button_samples = 0;
131129
for (int i = 0; i < ms; i++) {
132130
for (int delay = 0; delay < 100000; delay++) {}
133-
button_samples += hal_gpio_read(PUSH_BUTTON_IN);
131+
button_samples += hal_gpio_read(MYNEWT_VAL(PUSH_BUTTON_IN));
134132
}
135133
}

libs/pinetime_boot/src/display.c

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
#define DISPLAY_RST 26 // LCD_RESET (P0.26): Display reset
3838
#define DISPLAY_HIGH 23 // LCD_BACKLIGHT_{LOW,MID,HIGH} (P0.14, 22, 23): Backlight (active low)
3939
#define BATCH_SIZE 256 // Max number of SPI data bytes to be transmitted
40-
#define PUSH_BUTTON_IN 13 // GPIO Pin P0.13: PUSH BUTTON_IN
4140

4241
// Screen Size
4342
#define ROW_COUNT 240

libs/pinetime_boot/src/pinetime_boot.c

+4-7
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@
3232
#include <hal/hal_watchdog.h>
3333
#include "pinetime_boot/version.h"
3434

35-
#define PUSH_BUTTON_IN 13 // GPIO Pin P0.13: PUSH BUTTON_IN
36-
#define PUSH_BUTTON_OUT 15 // GPIO Pin P0.15/TRACEDATA2: PUSH BUTTON_OUT
37-
3835
/// Vector Table will be relocated here.
3936
#define RELOCATED_VECTOR_TABLE 0x7F00
4037

@@ -54,9 +51,9 @@ void pinetime_boot_init(void) {
5451

5552
// Init the push button. The button on the side of the PineTime is disabled by default. To enable it, drive the button out pin (P0.15) high.
5653
// While enabled, the button in pin (P0.13) will be high when the button is pressed, and low when it is not pressed.
57-
hal_gpio_init_in(PUSH_BUTTON_IN, HAL_GPIO_PULL_DOWN);
58-
hal_gpio_init_out(PUSH_BUTTON_OUT, 1);
59-
hal_gpio_write(PUSH_BUTTON_OUT, 1); // Enable the button
54+
hal_gpio_init_in(MYNEWT_VAL(PUSH_BUTTON_IN), HAL_GPIO_PULL_DOWN);
55+
hal_gpio_init_out(MYNEWT_VAL(PUSH_BUTTON_OUT), 1);
56+
hal_gpio_write(MYNEWT_VAL(PUSH_BUTTON_OUT), 1); // Enable the button
6057
// blink_backlight(1, 1);
6158

6259
// Display the image.
@@ -70,7 +67,7 @@ void pinetime_boot_init(void) {
7067
console_printf("Waiting 5 seconds for button...\n"); console_flush();
7168
for (int i = 0; i < 64 * 5; i++) {
7269
for (int delay = 0; delay < 3000; delay++) {
73-
button_samples += hal_gpio_read(PUSH_BUTTON_IN);
70+
button_samples += hal_gpio_read(MYNEWT_VAL(PUSH_BUTTON_IN));
7471
}
7572
if(i % 64 == 0) {
7673
console_printf("step %d - %d\n", (i / (64)) + 1, (int)button_samples); console_flush();

libs/pinetime_boot/syscfg.yml

+9
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,12 @@
33
# Strings must be enclosed by '"..."'
44

55
syscfg.defs:
6+
PUSH_BUTTON_IN:
7+
description: Pin of the pushbutton (in)
8+
value:
9+
restrictions: $notnull
10+
11+
PUSH_BUTTON_OUT:
12+
description: Pin of the pushbutton (out)
13+
value:
14+
restrictions: $notnull

project.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# under the License.
1818
#
1919

20-
project.name: "my_project"
20+
project.name: "pinetime_mcuboot_bootloader"
2121

2222
project.repositories:
2323
- apache-mynewt-core
@@ -28,12 +28,12 @@ project.repositories:
2828
#
2929
repository.apache-mynewt-core:
3030
type: github
31-
vers: 1.8.0
32-
user: apache
31+
vers: ca2f81ae59bb9640a72c695feab1b05487ececee-commit # Contains JEDEC ignore options
32+
user: StarGate01
3333
repo: mynewt-core
3434

3535
repository.mcuboot:
3636
type: github
37-
vers: 1.5.0
38-
user: JuulLabs-OSS
37+
vers: c657cbea75f2bb1faf1fceacf972a0537a8d26dd-commit # 1.9.0
38+
user: mcu-tools
3939
repo: mcuboot

scripts/nrf52/build-boot.cmd

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
:: Build Mynewt bootloader on Windows
22

33
:: Build the bootloader.
4-
newt\newt.exe build nrf52_boot
4+
newt\newt.exe build pinetime
55

66
:: Show the size.
7-
newt\newt.exe size -v nrf52_boot
7+
newt\newt.exe size -v pinetime

scripts/nrf52/build-boot.sh

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#!/usr/bin/env bash
22
# Build Mynewt bootloader on macOS and Linux
33

4+
TARGET=${1:-pinetime}
5+
echo "Building target $TARGET"
6+
47
set -e # Exit when any command fails.
58
set -x # Echo all commands.
69

@@ -10,17 +13,17 @@ source paths.bash
1013
arm-none-eabi-gcc --version
1114

1215
# Build the bootloader.
13-
newt build nrf52_boot
16+
newt build $TARGET
1417

1518
# Show the size.
16-
newt size -v nrf52_boot
19+
newt size -v $TARGET
1720

18-
arm-none-eabi-objcopy -I binary -O ihex bin/targets/nrf52_boot/app/@mcuboot/boot/mynewt/mynewt.elf.bin bin/targets/nrf52_boot/app/@mcuboot/boot/mynewt/mynewt.elf.hex
19-
scripts/hex2c.py bin/targets/nrf52_boot/app/@mcuboot/boot/mynewt/mynewt.elf.hex > reloader/src/boards/pinetime/bootloader.h
20-
make -C reloader BOARD=pinetime
21+
arm-none-eabi-objcopy -I binary -O ihex bin/targets/$TARGET/app/@mcuboot/boot/mynewt/mynewt.elf.bin bin/targets/$TARGET/app/@mcuboot/boot/mynewt/mynewt.elf.hex
22+
scripts/hex2c.py bin/targets/$TARGET/app/@mcuboot/boot/mynewt/mynewt.elf.hex > reloader/src/boards/$TARGET/bootloader.h
23+
make -C reloader build-$TARGET/reloader-mcuboot.zip all BOARD=$TARGET
2124

2225
set +x
23-
echo "Bootloader firmware (elf) : bin/targets/nrf52_boot/app/@mcuboot/boot/mynewt/mynewt.elf"
24-
echo "Bootloader firmware (bin) : bin/targets/nrf52_boot/app/@mcuboot/boot/mynewt/mynewt.bin"
25-
echo "Bootloader firmware (hex) : bin/targets/nrf52_boot/app/@mcuboot/boot/mynewt/mynewt.hex"
26-
echo "Reloader (DFU) : reloader/build-pinetime/reloader-mcuboot.zip"
26+
echo "Bootloader firmware (elf) : bin/targets/$TARGET/app/@mcuboot/boot/mynewt/mynewt.elf"
27+
echo "Bootloader firmware (bin) : bin/targets/$TARGET/app/@mcuboot/boot/mynewt/mynewt.bin"
28+
echo "Bootloader firmware (hex) : bin/targets/$TARGET/app/@mcuboot/boot/mynewt/mynewt.hex"
29+
echo "Reloader (DFU) : reloader/build-$TARGET/reloader-mcuboot.zip"

targets/p8/pkg.yml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
19+
# Target Settings
20+
pkg.name: targets/p8
21+
pkg.type: target
22+
pkg.description:
23+
pkg.author:
24+
pkg.homepage:
25+
26+
# Package Dependencies: MCUBoot is dependent on these drivers and libraries.
27+
pkg.deps:
28+
- "libs/semihosting_console" # Semihosting Console
29+
- "libs/pinetime_boot" # Render boot graphic and check for rollback. Comment out for Stub Bootloader.
30+
31+
# C compiler flags
32+
pkg.cflags:
33+
- -DMCUBOOT_HAVE_LOGGING=1 # So that sysinit() will be run, needed for displaying boot graphic
34+
- -DDISABLE_SEMIHOSTING # Uncomment to disable Arm Semihosting. Must be uncommented for production.
35+
# - -Os # Optimise for smallest size

targets/nrf52_boot/syscfg.yml renamed to targets/p8/syscfg.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
# MCUBoot Bootloader Settings
18+
# Target Settings
1919

2020
syscfg.vals:
2121
BOOT_CUSTOM_START: 1 # Use custom boot function boot_custom_start()
@@ -54,3 +54,7 @@ syscfg.vals:
5454
SANITY_INTERVAL: 1000 # The interval (in milliseconds) at which the sanity checks should run, should be at least 200ms prior to watchdog
5555
WATCHDOG_INTERVAL: 2000 # The interval (in milliseconds) at which the watchdog should reset if not tickled, in ms
5656

57+
# Specific target hardware config
58+
59+
PUSH_BUTTON_IN: 17
60+
PUSH_BUTTON_OUT: -1
File renamed without changes.

targets/nrf52_boot/pkg.yml renamed to targets/pinetime/pkg.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
# specific language governing permissions and limitations
1717
# under the License.
1818

19-
# MCUBoot Package Settings
20-
pkg.name: targets/nrf52_boot
19+
# Target Settings
20+
pkg.name: targets/pinetime
2121
pkg.type: target
2222
pkg.description:
2323
pkg.author:

targets/pinetime/syscfg.yml

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
# Target Settings
19+
20+
syscfg.vals:
21+
BOOT_CUSTOM_START: 1 # Use custom boot function boot_custom_start()
22+
OS_MAIN_STACK_SIZE: 1024 # Small stack size: 4 KB
23+
MSYS_1_BLOCK_COUNT: 64 # Allocate MSYS buffers for Semihosting Console
24+
HAL_ENABLE_SOFTWARE_BREAKPOINTS: 0 # In case of assertion failure, don't breakpoint. Must be set to 0 so that bootloader will reboot and won't hang in case of assertion failures.
25+
MCU_DEBUG_IGNORE_BKPT: 1
26+
27+
###########################################################################
28+
# Hardware Settings
29+
30+
SPIFLASH: 1 # Enable SPI Flash
31+
SPI_0_MASTER: 1 # Enable SPI port 0 for ST7789 display and SPI Flash
32+
I2C_1: 0 # Disable I2C port 1 for CST816S touch controller, BMA421 accelerometer, HRS3300 heart rate sensor
33+
UART_0: 0 # Disable UART port to reduce ROM size
34+
35+
###########################################################################
36+
# Common Settings for minimal ROM size
37+
38+
CONSOLE_COMPAT: 0 # Disable console input
39+
CONSOLE_RTT: 0 # Disable RTT Console
40+
CONSOLE_UART: 0 # Disable UART Console
41+
LOG_CLI: 0 # Disable logging command-line interface
42+
LOG_LEVEL: 255 # Disable logs
43+
SENSOR_CLI: 0 # Disable sensor command-line interface
44+
SENSOR_OIC: 0 # Disable sensor OIC functions
45+
SHELL_CMD_HELP: 0 # Disable shell help
46+
SHELL_OS_MODULE: 0 # Disable shell module
47+
SHELL_TASK: 0 # Disable shell task
48+
STATS_CLI: 0 # Disable statistics command-line interface
49+
OS_SYSVIEW_TRACE_CALLOUT: 0 # Disable trace of callouts
50+
OS_SYSVIEW_TRACE_EVENTQ: 0 # Disable trace of event queues
51+
OS_SYSVIEW_TRACE_MUTEX: 0 # Disable trace of mutex
52+
OS_SYSVIEW_TRACE_SEM: 0 # Disable trace of semaphores
53+
BOOTUTIL_FEED_WATCHDOG: 1 # Enable watchdog feeding while performing a swap upgrade
54+
SANITY_INTERVAL: 1000 # The interval (in milliseconds) at which the sanity checks should run, should be at least 200ms prior to watchdog
55+
WATCHDOG_INTERVAL: 2000 # The interval (in milliseconds) at which the watchdog should reset if not tickled, in ms
56+
57+
# Specific target hardware config
58+
59+
PUSH_BUTTON_IN: 13
60+
PUSH_BUTTON_OUT: 15

targets/pinetime/target.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Bootloader Target Settings
2+
3+
# Bootloader will be based on MCUBoot. Select "apps/boot_stub" for the Stub Bootloader.
4+
target.app: "@mcuboot/boot/mynewt" # Use MCUBoot, which doesn't support debugging
5+
# target.app: "apps/boot_stub" # Use Stub Bootloader, which supports debugging
6+
7+
# Board Support Package (BSP) for the target
8+
target.bsp: "hw/bsp/nrf52"
9+
10+
# Build with debug support. Or select "optimized" to remove debug support.
11+
#target.build_profile: debug # For debugging
12+
target.build_profile: optimized # For production

0 commit comments

Comments
 (0)