NB-IOT: Get started with STM32 and CubeMX on macOS

RosarIOT
Posts: 1
Joined: Thu 08. Aug 2019 17:59:25

NB-IOT: Get started with STM32 and CubeMX on macOS

Post by RosarIOT » Sun 08. Sep 2019 14:04:23

STM32, Arduino, firmware, Nucleo Board, 5G, NB-IoT, CubeMX, development board, PGBoard... all those words meant nothing to me until a few weeks ago... Last time I compiled a Linux kernel was in 1998, my last C/C++ was on university project 20 years ago, and I think my last Window was Win98…

Also, never programmed a firmware, not even a driver, so when I got involved into a IoT hardware project I feared I could never catch up but hopefully I found out that it is doable, even for developers who are using high-level languages and MacOS.

At start I go impression that most tools were for PC (IAR, kiel, etc) or Linux, so I installed virtual machine and installed all those tools … it was so slow ... so I needed to find a better way for me, and after a few weeks I was already doing my first NB-IoT app :) This tutorial will let you go to the same result, step by step.

macos_cubemx_stm32.jpg
macos_cubemx_stm32.jpg (55.95 KiB) Viewed 4091 times



Which hardware to start with? Nucleo-64 board, Arduino or integrated NB-IoT PGBoard ?

First of all I needed to choose a proper hardware and development tools. I read a lot of articles and youtube videos, and saw many references to easy-to-use solutions, and development kit for starters, like Arduino and development boards from STMicroelectronics.

NB-IoT applications need to have a very low consumption, and still I wanted to have a powerful and flexible microprocessor, so the best candidate would be microprocessor STM32l452RE https://www.st.com/en/microcontrollers- ... 452re.html, and this evaluation board Nucleo-64 https://www.st.com/en/evaluation-tools/ ... 452re.html

However, I also needed to add a few sensors and connectivity to 5G/NarrowBand, and I got a NB-IOT prototyping kit called PGBoard (https://www.pgboard.eu/) which is based on STM32-Nucleo L452RE development board, on which NB-IoT modules have been integrated, and provide 5G connection with data SIM.

You can get it for less than 100 EUR at https://www.pgboard.eu/

Development toolchain for MacOS

Since PGBoard is based on STM32 Microcontroller, I found out most of needed toolchain was available on Mac. Yeah :)

So here what I installed:

STM CubeMX, https://www.st.com/en/development-tools ... bemx.html

System Workbench for STM32, https://www.st.com/en/development-tools/sw4stm32.html


Install and test PGBoard

PGBoard contains following items:

Image

PGBoard comes also with a firmware example; here are the steps to follow:

1) download and unzip example https://www.m2mc.cz/files/nbiotevk_v2-0-5.zip

Result folder will contain all files needed for the project:

Code: Select all

…
nbiotevk/Src/spi.c
nbiotevk/Src/rtc.c
nbiotevk/Src/gpio.c
nbiotevk/Src/syscalls.c
nbiotevk/Src/i2c.c
nbiotevk/Src/stm32l4xx_it.c
nbiotevk/Src/rtc.c.bak
nbiotevk/Src/dma.c
nbiotevk/Src/main.c
...

2) Launch CubeMX and choose nbiotevk.ioc file then click on GENERATE CODE (top right)

TutorialCubMx1-2.jpg
TutorialCubMx1-2.jpg (86.33 KiB) Viewed 4091 times

3) Open Applications > AC6 > SystemWorkbench
  • open/import nbiotek folder
  • Click on RUN, choose "Run AC6/STM32 C/C++ Application"
If the device is not connected an ERROR will occur, otherwise the PGBoard will flash and firmware will be flashed!

eclipse1-4.jpg
eclipse1-4.jpg (101.23 KiB) Viewed 4091 times


That was easy :) ! no need extra hardware, your first NB-IoT application is done!

The basic firmware has 3 functionalities:

button click: send signal strength to operator
button double click: send all sensors data to operator
button long press: switch GPS on/off (huge impact on battery)

I will make another POST on how to connect to miotiq platform to read and write data from PGBoard.


Error management and Logging


I found this very useful for debugging purposes:

Code: Select all

$ brew install minicom
$ minicom -D /dev/tty.usbmodem14113

Also if you have the RESTLINK/ST-Link programming module hardware debugger you can download ST-Link utility at https://www.st.com/content/st_com/en/pr ... t-software and run:

Code: Select all

java -jar stsw-link007/AllPlatforms/STLinkUpgrade.jar


Useful link and tutorials

https://www.youtube.com/watch?v=mkx4qZCCHqI

https://www.youtube.com/watch?v=VtjMGCyLEuA
https://www.youtube.com/watch?v=FgZVNrggNIk
https://www.youtube.com/watch?v=UN0-bajleUA

https://www.youtube.com/watch?v=szMGedsp9jc