Skip to content

Commit 12d5a73

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 12d5a73

File tree

19 files changed

+163
-40
lines changed

19 files changed

+163
-40
lines changed

.vscode/launch-nrf52-pi.json

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 5 additions & 1 deletion
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

Lines changed: 5 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 4 additions & 7 deletions
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

Lines changed: 9 additions & 0 deletions
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

0 commit comments

Comments
 (0)