NB-IoT GPS Tracker running on the Ghostyu NB-EK-L476 Developer Kit with STM32L476RCT6 microcontroller, Quectel L70-R GPS module and Quectel BC95 NB-IoT module. Photo taken during the field test at Berlayer Creek Boardwalk in Singapore.
Install Apache Mynewt and Embedded Rust for STM32 L476 and Visual Studio Code on Windows
Follow these instructions to install Apache Mynewt + Embedded Rust build and application files for STM32 L476 and Visual Studio Code on Windows for the article “Build an NB-IoT GPS Tracker on STM32 L476 with Apache Mynewt and Embedded Rust”
Install Rust
1️⃣ Click here to install Build Tools For Visual Studio
2019:https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019
2️⃣ Click the Individual Components
tab
Select the following components:
-
Windows 10 SDK (10.0.18362.0)
-
C++ CMake Tools for Windows
-
(This should be automatically selected)
MSVC v142 — VS 2019 C++ x64/x86 Build Tools
3️⃣ Install rustup
according to the
instructions here:https://rustup.rs
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 Command Prompt. Enter into the command prompt:
rustup default nightly
rustup update
rustup target add thumbv7m-none-eabi
rustup target add thumbv7em-none-eabihf
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 and Build The Firmware
1️⃣ Download the stm32bluepill-mynewt-sensor.7z
file attached
below…https://github.com/lupyuen/stm32bluepill-mynewt-sensor/releases/tag/v9.0.0
Expand the .7z
file with 7zip…https://www.7-zip.org/download.html
2️⃣ Install Arm Cross-Compiler and Linker for Windows from Arm Developer
Website…https://developer.arm.com/-/media/Files/downloads/gnu-rm/8-2019q3/RC1.1/gcc-arm-none-eabi-8-2019-q3-update-win32-sha1.exe?revision=fcadabed-d946-49dc-8f78-0732d2f43773?product=GNU%20Arm%20Embedded%20Toolchain,32-bit,,Windows,8-2019-q3-update
Select this option at the last install step:"Add path to environment variable"
3️⃣ Download the ST-Link USB driver from ST-Link Driver Website (email
registration required)…https://www.st.com/en/development-tools/stsw-link009.html
Click Get Software
Unzip the
downloaded file. Double-click the driver installer:dpinst_amd64.exe
4️⃣ Install Windows Studio Code:https://code.visualstudio.com/
Launch Visual Studio Code
Install the extension “Cortex-Debug
”…https://marketplace.visualstudio.com/items?itemName=marus25.cortex-debug
5️⃣ Click File → Open Folder
Select
the downloaded folder stm32bluepill-mynewt-sensor
When prompted to open the workspace, click Open Workspace
6️⃣ If you have a Quectel NB-IoT module…
Open the following file and configure the program settings:targets/stm32l4_my_sensor/syscfg.yml
Change the NB-IoT band setting NBIOT_BAND
.
Check with your NB-IoT operator for the band to use. The other settings are
documented below.
7️⃣ Click Terminal → Run Task → [1] Build Bootloader
This
builds the bootloader, which starts the Apache Mynewt operating system upon
startup. If it shows errors, compare with this build log.
Click Terminal → Run Task → [2] Build Application
This
builds the firmware containing our Rust program. Compare with this build log.
When our Rust program has been successfully compiled as STM32 ROM 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 this image log.
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 STM32 L476 board to the USB port of our computer via an ST-Link V2 adapter.
1️⃣ Check that the STM32 L476 board is connected to ST-Link… And that the ST-Link is connected to 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 this flash log.
3️⃣ Click Terminal → Run Task → [5] Load Application
This flashes the application firmware. If it shows errors, compare with this flash log.
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 the line with LoopCopyDataInit
Click Continue
or press F5
4️⃣ The debugger pauses next at the main()
function.
Click Continue
or press F5
Rust Source Files
The Rust source files are located in the rust
folder…
rust/app
: Rust application that polls the
internal temperature and GPS sensors and transmits the sensor data over NB-IoT
rust/visual
: Sample Visual
Embedded Rust program. Not used in this tutorial.
rust/mynewt
: Rust Safe Wrappers for Mynewt
OS and libraries
rust/macros
: Rust Procedural Macros for
generating Safe Wrappers and other utility macros like strn!()
Optional: Install Rust Language Server
To get full Rust Language Support for editing Rust source files in Visual Studio Code, you may install Rust Language Server…
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: Program Settings
The program settings may be found in the file targets/stm32l4_my_sensor/syscfg.yml
Program Settings. From https://github.com/lupyuen/stm32bluepill-mynewt-sensor/blob/l476/targets/stm32l4_my_sensor/syscfg.yml
COAP_HOST, COAP_PORT
: The program will
send CoAP messages to this IP address and port number, which defaults to the
CoAP server at thethings.io.
Keep the default settings if you wish to view your sensor data at blue-pill-geolocate.appspot.com
.
Change the setting to use your own CoAP server instead of thethings.io
COAP_URI
: The CoAP message will be
delivered to this URI at the CoAP server (which defaults to thethings.io).
Keep the default settings if you wish to view your sensor data at blue-pill-geolocate.appspot.com
.
For thethings.io, the last part IVRi…
is
the Thing Token. If you wish to send sensor data to your own Thing at
thethings.io, replace the last part of the URI with your Thing Token.
For the purpose of NB-IoT Education, I’ll allow you to transmit sensor data to
the Thing Token IVRi…
from my personal,
paid thethings.io account. Which will forward the sensor data to blue-pill-geolocate.appspot.com
for viewing.
NBIOT_BAND
: The program connects to this
NB-IoT Frequency Band. The
Frequency Band depends on your country and your NB-IoT network operator. Check
with your NB-IoT network operator for the Frequency Band to use.
NB-IoT Frequency Bands for Singapore. From https://www.imda.gov.sg/-/media/imda/files/regulation-licensing-and-consultations/frameworks-and-policies/spectrum-management-and-coordination/spectrummgmthb.pdf
NB-IoT Frequency Bands for Singapore. From https://www.imda.gov.sg/-/media/imda/files/regulation-licensing-and-consultations/ict-standards/telecommunication-standards/radio-comms/imda-ts-iot.pdf