# Develop and Build the Pebble Firmware (Linux/MacOS)

# Install Dependencies

Follow the instruction below to install the required tools. Make sure you have current versions for the following tools:

cmake --version # must be >= 3.13.1
dtc --version # must be >= 1.4.6
python --version # bust be >= 3.6
1
2
3

    # Install ARM Compiler Toolchain

    Download the ARM embedded compiler toolchain

      set required environment variables

      # Create ~/.zephyrrc for easy env variables management
      echo 'export ZEPHYR_TOOLCHAIN_VARIANT=gnuarmemb' >> ~/.zephyrrc
      echo 'export GNUARMEMB_TOOLCHAIN_PATH="~/gnuarmemb"' >> ~/.zephyrrc
      
      1
      2
      3

      # Install the Nordic SDK

      the Nordic SDK is managed by the westtool, so we first need to install west: open a terminal and type

      # Install west
      pip3 install --user -U west
      # Make sure the `west`executable is in front of your PATH:
      echo 'export PATH=~/.local/bin:"$PATH"' >> ~/.bashrc
      source ~/.bashrc
      # Check that west is correctly installed
      west --version
      
      1
      2
      3
      4
      5
      6
      7

      In your home directory, crate a folder named ncs: we will install the SDK there:

      mkdir ~/ncs
      cd ~/ncs
      # Initialize the folder
      west init -m https://github.com/nrfconnect/sdk-nrf --mr v1.3.0
      # Download all required repositories
      west update
      # Export a Zephyr CMake package. This allows CMake to automatically load the boilerplate code required for building nRF Connect SDK applications:
      west zephyr-export
      
      1
      2
      3
      4
      5
      6
      7
      8

      Install required python dependencies

      pip3 install -r zephyr/scripts/requirements.txt
      pip3 install -r nrf/scripts/requirements.txt
      pip3 install -r bootloader/mcuboot/scripts/requirements.txt
      
      
      1
      2
      3
      4

      # Clone the Pebble-Firmware IoTeX repository:

      The pebble-firmware IoTeX repository contains the firmware application source and the board definition file:

      git clone https://github.com/iotexproject/pebble-firmware.git
      
      1

      Before we can build the firmware we need to replace the default board definition from the SDK with the one for Pebble:

      # Delete the default board definition
      rm -rf ~/ncs/nrf/boards/arm/thingy91_nrf9160
      # Replace with the one from pebble-firmware
      cp -rv ~/pebble-firmware/nrf/boards/arm/thingy91_nrf9160 ncs/nrf/boards/arm/
      
      1
      2
      3
      4

      # Compile Project with Command Line

      Before trying to build the project you must set required environment variables for Zephyr, to do so you can run:

      # Load environment variables for the Zephyr SDK
      source ~/ncs/zephyr/zephyr-env.sh
      
      1
      2

      Among other things, this will also source your ~/.zephyrrc where the arm toolchain environment variables are set: you can use this file to add any customization to the environment.

      WARNING

      Please notice that the environment variables will be lost if you close your terminal window: run source ~/ncs/zephyr/zephyr-env.sh again to get them back

      The project can then be compiled with the following commands:

      cd ~
      # Make sure to remove any previously created build directory
      rm -rf build/
      # Start the build process
      west build -b thingy91_nrf9160ns ~/pebble-firmware/nrf/applications/asset_tracker/
      
      1
      2
      3
      4
      5

      After the project is compiled successfully, you can flash the new Pebble firmware that is available at ~/build/zephyr/app_signed.hex.

      See how to configure the frimware before the build. See how to flash the frimware.