Bluetooth Mesh with four EBYTE E73-TBB Development Boards based on Nordic nRF52832 Microcontroller

Install Bluetooth Mesh and Apache Mynewt for nRF52 and Visual Studio Code on Windows and macOS

Follow these instructions to install the Bluetooth Mesh sample application for nRF52 and Visual Studio Code on Windows and macOS for the article

Install Rust for Windows and macOS

1️⃣ For Windows Only: Click here to install Build Tools For Visual Studio 2019:

Click the Individual Components tab

Select the following components:

  1. Windows 10 SDK (10.0.18362.0)
  2. C++ CMake Tools for Windows
  3. (This should be automatically selected) MSVC v142 — VS 2019 C++ x64/x86 Build Tools

2️⃣ Install rustup according to the instructions here:

3️⃣ For Windows Only: Click the link provided to download rustup‑init.exe

Launch the downloaded file rustup‑init.exe

If you see the message “Windows Defender SmartScreen prevented an unrecognised app from starting”…

Click More Info

Click Run Anyway

4⃣ At the Welcome to Rust! prompt, press Enter to select the default option:
1) Proceed with installation (default)

5️⃣ Open the Windows or macOS Command Prompt. Enter into the command prompt:

rustup default nightly
rustup update
rustup target add thumbv7m-none-eabi
rustup target add thumbv7em-none-eabihf
# For RISC-V Only:
rustup target add riscv32imac-unknown-none-elf
rustc -V

The reported version of rustc should be 1.38.0 or later:

rustc 1.38.0-nightly (435236b88 2019–08–01)

Install Source Files

1️⃣ Download the stm32bluepill-mynewt-sensor.7z file attached below…

For Windows:

For macOS:

2️⃣ Expand the .7z file with 7zip (Windows) or Keka (macOS)…

For Windows:

For macOS:

2️⃣ For Windows Only: Install Arm Cross-Compiler and Linker for Windows from Arm Developer Website…

Select this option at the last install step:
"Add path to environment variable"

3️⃣ For Windows Only: Download the ST-Link USB driver from ST-Link Driver Website (email registration required)…

Click Get Software
Unzip the downloaded file. Double-click the driver installer:
dpinst_amd64.exe

4️⃣ Install Windows Studio Code:

Launch Visual Studio Code

Click View → Extensions

Enter cortex-debug

Install the extension “Cortex-Debug” shown below…

Cortex-Debug Extension for Visual Studio Code:

5️⃣ For macOS Only: In Visual Studio Code, click Terminal → Run Task → Install Mynewt

This installs the Arm Cross-Compiler and Linker for macOS.

Build The Firmware

1️⃣ In Visual Studio Code, click File → Open Folder
Select the downloaded folder stm32bluepill-mynewt-sensor

When prompted to open the workspace, click Open Workspace

2️⃣ Click Terminal → Run Task → [1] Build Bootloader
This builds the Bootloader Firmware, which starts the Apache Mynewt operating system upon startup. If it shows errors, compare with .

Click Terminal → Run Task → [2] Build Application
This builds the Application Firmware containing our Rust program. Compare with .

When our Rust program has been successfully compiled as Application Firmware, we should see this…

If you see the message Undefined reference to main, rebuild the application by clicking Terminal → Run Task → [2] Build Application

Click Terminal → Run Task → [3] Image Application
This creates the flash image from the firmware. Compare with .

If any source files or configuration files are changed, rebuild the application by clicking Terminal → Run Task → [2] Build Application

Flash The Firmware

The next step is to flash the firmware into ROM. We’ll need to connect the nRF52 to the USB port of our computer via an .

nRF52 Board connected to ST-Link V2

1️⃣ Connect the nRF52 board to ST-Link V2 as follows…

view raw nrf52-stlink.md hosted with ❤ by GitHub

Plug ST-Link into your computer’s USB port.

2️⃣ Click Terminal → Run Task → [4] Load Bootloader

This flashes the bootloader, to start the Apache Mynewt operating system upon startup. If it shows errors, compare with .

3️⃣ Click Terminal → Run Task → [5] Load Application

This flashes the application firmware. If it shows errors, compare with .

If you’re unable to flash the nRF52, it’s highly likely that the flash ROM on your nRF52 has been protected. To remove the flash ROM protection, follow the steps in the section “Advanced Topic: Remove nRF52 Flash Protection With Raspberry Pi” in the article .

4️⃣ If the nRF52 board has been previously provisioned as a mesh node, erase the provisioning details in the Flash ROM by clicking
Terminal → Run Task → Erase Flash

Then re-flash the Bootloader and Application…
Click Terminal → Run Task → [4] Load Bootloader
Click Terminal → Run Task → [5] Load Application

Run The Program

1️⃣ Click Debug → Start Debugging

2️⃣ Click View → Output

Select Adapter Output to see the Console Log of debug messages generated by our program

3️⃣ The debugger pauses at Reset_Handler

Click Continue or press F5

4️⃣ The debugger pauses next at the main() function

Click Continue or press F5

The program is now running on our microcontroller. .

TMP create temp_stub_0 At sysinit() the Stub Temperature Driver creates an instance of the Stub Temperature Sensor
NET hwid e2 61 11 35 36 72 66 8f 74 44 b9 13  Unique Hardware ID for our nRF52
NET standalone node  nRF52 runs in Standalone Mode, without other network nodes
Rust TMP poll start_sensor_listener() starts polling the Stub Temperature Sensor every 10 seconds
STB read temp sensor 10 seconds later, Mynewt polls the sensor and calls aggregate_sensor_data()
Rust send_sensor_data: t=1757 aggregate_sensor_data() calls send_sensor_data() with the simulated temperature
NET random device id
nrf52,00000000000000000000000000
send_sensor_data() obtains a random device ID
NET network not ready send_sensor_data() quits because no Server Transport is available
STB read temp sensor 10 seconds later the same steps are repeated
Rust send_sensor_data: t=1757
NET network not ready
STB read temp sensor
view raw nrf52-log.md hosted with ❤ by GitHub

Console Log from

Here’s a video demo of the application build and debug on nRF52…

Optional: Install Rust Language Server

To get full Rust Language Support for editing Rust source files in Visual Studio Code, you may install

1️⃣ In Visual Studio Code, browse to a Rust file like rust/app/src/lib.rs

2️⃣ When prompted to install RLS, click Yes

3️⃣ Good Luck! Sometimes the RLS installation fails with this message because we are using the nightly build…

Optional: Update The Program Settings

The program settings may be found in the file

After updating the program settings, rebuild the application by clicking Terminal → Run Task → [2] Build Application

syscfg.vals:
###########################################################################
# CoAP Server Settings
# CoAP host e.g. 104.199.85.211 (for coap.thethings.io)
COAP_HOST: '"104.199.85.211"'
# CoAP UDP port, usually port 5683
COAP_PORT: 5683
# CoAP URI e.g. v2/things/IVRiBCcR6HPp_CcZIFfOZFxz_izni5xc_KO-kgSA2Y8 (for thethings.io, the last part is the Thing Token)
COAP_URI: '"v2/things/IVRiBCcR6HPp_CcZIFfOZFxz_izni5xc_KO-kgSA2Y8"'
###########################################################################
# Network Settings
DEVICE_TYPE: '"nrf52"' # Device type that will be prepended to the Device ID. thethings.io converts the raw temperature depending on the device type.
NBIOT_BAND: 8 # Connect to this NB-IoT band
SENSOR_NETWORK: 1 # Enable Sensor Network library
SENSOR_COAP: 1 # Send sensor data to CoAP server
COAP_CBOR_ENCODING: 0 # Disable CBOR encoding of CoAP payload
COAP_JSON_ENCODING: 1 # Use JSON to encode CoAP payload for forwarding to thethings.io
RAW_TEMP: 1 # Use raw temperature (integer) instead of floating-point temperature values, to reduce ROM size
###########################################################################
# Hardware Settings
HARDFLOAT: 1 # Enable hardware floating-point support for STM32L476RC
LOW_POWER: 0 # Disable low power support
UART_0: 0 # Disable USART2
UART_1: 0 # Disable USART1
UART_2: 0 # Disable USART3
UART_2_SWAP_TXRX: 0 # Disable swapping of TX/RX pins for USART3
GPS_L70R: 0 # Disable driver for Quectel L70R GPS module
GPS_L70R_UART: 0 # Connect to Quectel L70R module on USART2
GPS_L70R_ENABLE_PIN: MCU_GPIO_PORTA(1) # GPIO Pin PA1 enables and disables the GPS module. Set to -1 for no pin.
BC95G: 0 # Disable driver for Quectel BC95-G NB-IoT module
BC95G_UART: 2 # Connect to Quectel BC95-G module on LPUART1 i.e. USART3 with TX/RX pins swapped
BC95G_ENABLE_PIN: MCU_GPIO_PORTA(0) # GPIO Pin PA0 enables and disables the NB-IoT module. Set to -1 for no pin.
ADC_1: 0 # Disable port ADC1
TEMP_STM32: 0 # Disable STM32 internal temperature sensor
HMAC_PRNG: 0 # Disable HMAC PRNG pseudorandom number generator
TEMP_STUB: 1 # Enable stub temperature sensor

Program Settings. From

Mynewt Project Structure

References

The Mynewt Project Structure is described in the article

The application is based on the Apache NimBLE sample application with the following changes…

  1. Reduced the number of buttons and LEDs from 4 to 2
  2. Removed calls to math function sqrt()
  3. Added Rust support

The following files may be useful for reference…