2019-12-02 13:42:10 -05:00
# PineTime
2019-12-05 13:39:52 -05:00
> The PineTime is a free and open source smartwatch capable of running custom-built open operating systems. Some of the notable features include a heart rate monitor, a week-long battery as well as a capacitive touch IPS display that is legible in direct sunlight. It is a fully community driven side-project, which means that it will ultimately be up to the developers and end-users to determine when they deem the PineTime ready to ship.
2019-12-05 13:44:19 -05:00
2019-12-05 13:39:52 -05:00
> We envision the PineTime as a companion for not only your PinePhone but also for your favorite devices — any phone, tablet, or even PC.
2019-11-17 14:47:04 -05:00
2019-12-05 13:39:52 -05:00
*https://www.pine64.org/pinetime/*
The goal of this project is to build a firmware designed for the PineTime around FreeRTOS.
It's coded using a mix of C and C++ : the NRF52-SDK and FreeRTOS are written in C, but I prefer to write my own code in C++.
Please **NOTE : for now, this project is in heavy development state** . Feel free to use it, contribute to it or fork it !
This project is based on https://github.com/JF002/nrf52-baseproject.
It's a CMake project that configure everything needed to build applications for the PineTime (https://wiki.pine64.org/index.php/PineTime).
2019-11-17 14:47:04 -05:00
I tested this project (compile only) with the following versions:
* gcc-arm-none-eabi-8-2019-q3-update (from https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads)
* nRF5_SDK_15.3.0_59ac345 (from https://www.nordicsemi.com/Software-and-Tools/Software/nRF5-SDK)
2019-12-05 13:39:52 -05:00
I've tested this project on the actual PineTime hardware.
## Current state
2019-12-27 11:13:09 -05:00
![Pinetime ](./images/pinetime.jpg "Pinetime" )
2019-12-05 13:39:52 -05:00
* Project builds and runs on the Pinetime;
* Logs available via JLink RTT;
2019-12-26 06:04:12 -05:00
* Basic (but faster) LCD driver.
* One big font to display the time (hours : minutes)
* BLE advertising, connection and bonding
* BLE CTS client (retrieves the time from the connected device if it implements a CTS server)
2019-12-26 12:33:40 -05:00
* Push button to go to disable screen (and go to low power mode) / enable screen (and wake-up). **NOTE** : I'm not completely sure the power consumption is optimal, especially in sleep mode. Any help to measure and debug this is welcome.
2020-01-03 10:35:34 -05:00
* Touch panel : wake up when sleeping and draw square on screen when running
2019-12-26 12:33:40 -05:00
2020-01-17 09:02:43 -05:00
## Stub using NRF52-DK
2020-01-02 09:19:28 -05:00
![Pinetime stub ](./images/pinetimestub1.jpg "PinetimeStub" )
See [this page ](./doc/PinetimeStubWithNrf52DK.md )
2019-11-17 14:47:04 -05:00
2019-12-26 06:02:01 -05:00
## How to build
2019-11-17 14:47:04 -05:00
* Download and unzip arm-none-eabi and NRF52 SDK
* Clone this repo
2020-01-17 08:56:56 -05:00
* **[JLINK]** Call CMake with the following command line argument
2019-11-17 14:47:04 -05:00
2020-01-17 08:56:56 -05:00
- -DARM_NONE_EABI_TOOLCHAIN_PATH=[Path to the toolchain directory]
- -DNRF5_SDK_PATH=[Path to the SDK directory]
- -DUSE_JLINK=1
- -DNRFJPROG=[Path to NRFJProg executable]
2019-11-17 14:47:04 -05:00
2020-01-17 09:03:34 -05:00
* OR
* **[GDB CLIENT (if you use a BlackMagicProbe, for example)]** Call CMake with the following command line argument
2020-01-17 08:56:56 -05:00
- -DARM_NONE_EABI_TOOLCHAIN_PATH=[Path to the toolchain directory]
- -DNRF5_SDK_PATH=[Path to the SDK directory]
- -DUSE_GDB_CLIENT=1
- -DGDB_CLIENT_BIN_PATH=[Path to arm-none-eabi-gdb executable]
- -DGDB_CLIENT_TARGET_REMOTE=[Target remote connetion string. Ex : /dev/ttyACM0]
2020-01-17 09:03:34 -05:00
* Optionally, you can define MERGEHEX with the path to the ```mergehex``` tool from [NRF5X Command Line Tools ](https://infocenter.nordicsemi.com/index.jsp?topic=%2Fug_nrf5x_cltools%2FUG%2Fcltools%2Fnrf5x_command_line_tools_lpage.html&cp=6_1 ) to be able to merge the application and softdevice into one HEX file. In this case the merged file is generated in src/pinetime-app-full.hex
2020-01-17 08:56:56 -05:00
- -DMERGEHEX=[Path to the mergehex executable]
JLINK
2019-11-17 14:47:04 -05:00
```
$ mkdir build
$ cd build
2020-01-17 08:56:56 -05:00
$ cmake -DCMAKE_BUILD_TYPE=Debug -DARM_NONE_EABI_TOOLCHAIN_PATH=... -DNRF5_SDK_PATH=... -DUSE_JLINK=1 -DNRFJPROG=... ../
```
GDB (Back Magic Probe)
```
$ mkdir build
$ cd build
$ cmake -DARM_NONE_EABI_TOOLCHAIN_PATH=... -DNRF5_SDK_PATH=... -DUSE_GDB_CLIENT=1 -DGDB_CLIENT_BIN_PATH=... -DGDB_CLIENT_TARGET_REMOTE=... -DMERGEHEX=... ../
2019-11-17 14:47:04 -05:00
```
* Make
```
2020-01-17 08:56:56 -05:00
$ make -j pinetime-app
2019-11-17 14:47:04 -05:00
```
2020-01-17 08:56:56 -05:00
## How to program
* Erase
2020-01-17 09:02:43 -05:00
2020-01-17 08:56:56 -05:00
```
$ make FLASH_ERASE
```
* Flash softdevice & application
2020-01-17 09:02:43 -05:00
2020-01-17 08:56:56 -05:00
```
$ make FLASH_SOFTDEVICE
$ make FLASH_pinetime-app
```
Or, with ```mergehex```
2020-01-17 09:02:43 -05:00
2020-01-17 08:56:56 -05:00
```
$ make FLASH_MERGED_pinetime-app
```
2020-01-17 09:02:43 -05:00
* For your information : list make targets :
2020-01-17 08:56:56 -05:00
```
$ make help
```
2019-11-17 14:47:04 -05:00
## RTT
RTT is a feature from Segger's JLink devices that allows bidirectionnal communication between the debugger and the target.
This feature can be used to get the logs from the embedded software on the development computer.
* Program the MCU with the code (see above)
* Start JLinkExe
```
$ JLinkExe -device nrf52 -if swd -speed 4000 -autoconnect 1
```
* Start JLinkRTTClient
```
$ JLinkRTTClient
2019-12-21 16:31:06 -05:00
```
## Tools
2019-12-26 06:02:01 -05:00
- https://github.com/eliotstock/memory : display the memory usage (FLASH/RAM) using the .map file from GCC.
## BLE connection, bonding and time synchronization
At runtime, BLE advertising is started. You can then use a smartphone or computer to connect and bond to your Pinetime.
As soon as a device is bonded, Pinetime will look for a **CTS** server (**C**urrent **T**ime **S**ervice) on the connected device.
Here is how to do it with an Android smartphone running NRFConnect:
* Build and program the firmware on the Pinetime
* Install NRFConnect (https://www.nordicsemi.com/Software-and-Tools/Development-Tools/nRF-Connect-for-desktop)
* Start NRFConnect and create a CTS server :
- Tap the hamburger button on the top left and select "Configure GATT server"
- Tap "Add service" on the bottom
- Select server configuration "Current Time Service" and tap OK
* Go back to the main screen and scan for BLE devices. A device called "PineTime" should appear
* Tap the button "Connect" next to the PineTime device. It should connect to the PineTime and switch to a new tab.
* On this tab, on the top right, there is a 3 dots button. Tap on it and select Bond. The bonding process begins, and if it is sucessful, the PineTime should update its time and display it on the screen.