Ghostyu NB-EK-L476 Developer Kit

Quick Peek of Huawei LiteOS with NB-IoT on Ghostyu NB-EK-L476 Developer Kit (STM32L476RCT6)

I ordered a few NB-IoT Developer Kits from Taobao.com and realised that their firmware had one thing in common… They were built with Huawei LiteOS.

Although LiteOS is a new embedded OS, we’ll find features that are commonly associated with modern Real-Time Operating Systems like Apache Mynewt and Zephyr.

In this article we’ll peek into the LiteOS + Application source code that was bundled with the NB-IoT Developer Kit that I have just received… Ghostyu NB-EK-L476 Developer Kit (also available on AliExpress)

(I bought the kit myself from Taobao and I’m not paid to write this article)

The kit (shown in the photo above) contains…

0️⃣ STMicroelectronics STM32L476RCT6 microcontroller

  • 80 MHz Arm Cortex M4 CPU with Floating-Point Unit
  • 256 KB Flash ROM (at 0x0800 0000)
  • 128 KB RAM (96 KB at 0x2000 0000, 32 KB with hardware parity at 0x1000 0000)
  • Supported Interfaces: CAN, I2C, LPUART, SAI, SPI, USART, USB.

1️⃣ Quectel BC95-B8 Band 8 NB-IoT Breakout Board with SIM slot
(Connected to Port LPUART1, PA0 for Enable Pin, PB15 for Interrupt Pin. Note that Port LPUART1 is not the same as USART3, but we may swap the TX/RX pins to make them the same)

NB-IoT Breakout Board with SIM slot underneath. Note the unusual orientation of the SIM — the notch faces outwards not inwards. Many thanks to StarHub for sponsoring the NB-IoT SIM!

This NB-IoT breakout board (at top right) is for NB-IoT Frequency Band 8 only, so it may not be suitable for all countries. But you may buy and replace the breakout board with the version that supports Global Frequency Bands: Quectel BC95-G Global Band NB-IoT Breakout Board (also on AliExpress, ask for the BC95-G version)

(I have used this BC95-G breakout board in an earlier tutorial)

Replacing Quectel BC95-B8 (Band 8, left) by BC95-G (Global Band, right)

2️⃣ Quectel L70-R GPS Module with GPS antenna
(Port UART2, PA1 for Enable Pin)

Underside of the board with GPS antenna

3️⃣ SHT20 Temperature and Humidity Sensor
(Port I2C2)

4️⃣ Light Sensor
(Analog, Port ADC1, GPIO PB1)

5️⃣ MicroSD Slot
(SDMMC1)

6️⃣ Four Push Buttons
(GPIO PC0 to PC3)

7️⃣ Green LED
(GPIO PA15)

8️⃣ White LED
(Composite red + green + blue LEDs, Analog, GPIO PB2)

9️⃣ Expansion Port at lower centre that exposes Ports SPI3, I2C1 and UART3

STM32L476RCT6 microcontroller with Expansion Port

🔟 LCD Connector (8-pin, yellow) at upper left that exposes Port SPI1, GPIO PA4, PB0 (LCD screen not included)

SWD Debug Port

Plus an SWD Debug Port (10-pin, white) at left, compatible with ST-Link v2.

The following pins should be connected: SWDIO, SWCLK, VCC, GND.

Pins connected from the board to ST-Link: SWDIO, SWCLK, VCC, GND

Here are the schematics (in Chinese)

The source code in this article was downloaded from the official Ghostyu website at doc.iotxx.com/NB-EK-L476 and reuploaded to GitHub…


Source Code Structure

Overall Structure of LiteOS

The source code folder consists of three major subfolders…

kernel: LiteOS kernel source code. This is provided by Huawei and is common to all LiteOS projects. Arm Cortex-specific code is also located here.

platform: Source code specific to the STM32L476RCT6 microcontroller and the NB-EK-L476 Developer Kit. This folder is packaged by Ghostyu, the makers of the kit.

user: Application source code. Provided by Ghostyu.

GCC, Keil and IAR build tools may be used to build LiteOS and the embedded application.


Kernel Functions

LiteOS Kernel Functions

The LiteOS kernel functions are located in the kernel folder. The functions cover…

Below we see the contents of the kernel folder, and a source file from the kernel that deals with task initialisation…


Main Function

The main() function is located in the user folder. The main() function starts up the various functions of the developer kit.

In the same source file, we see the SystemClock_Config() function that powers on the STM32 microcontroller peripherals and initialises the clocks. Read more about STM32 Clocks


Platform Functions

The platform folder contains code that’s specific to the microcontroller (STM32L4xx) and the development board (NB-EK-L476). This folder is likely managed by Ghostyu since it contains code specific to their development board. Here’s what we’ll find in the folder…

Display: Source code for the optional LED display (SPI)

Drivers: STM32 HAL (explained below)

GpsParse: Driver for onboard Quectel L70-R GPS module

NBxxModule: Driver for onboard Quectel BC95 NB-IoT module

Src: Board-specific functions

An drivers for various Onboard Sensors and Outputs:

Under platform/STM32L476RC_NBEK/Drivers we find the standard STM32 HAL Functions, provided by STMicroelectronics. These are the low-level Hardware Adaptation Layer functions called by the operating system to perform STM32-specific operations like accessing the UART, I2C and SPI ports.

This is fairly common in embedded operating systems, we see this in Zephyr and Mynewt too.


Quectel BC95 NB-IoT Driver

Inside the platform folder is the driver developed by Ghostyu for the Quectel BC95 NB-IoT module, which is connected to Port UART1.

Below we see a State Transition Machine for handling the AT commands: nb95_init_process, nb95_info_process, cmd_next, …

(The BC95 driver that I have built for Apache Mynewt uses a different approach)

Below we see the main loop for handling the AT commands, as well as the message-sending logic…


Quectel L70-R GPS Driver

Also inside the platform folder, Ghostyu has included a driver for the onboard Quectel L70-R GPS module, which is connected to Port UART2.

Here we see the code to transmit GPS commands and to parse the GPS responses…


Comparing Huawei LiteOS, Apache Mynewt, FreeRTOS and Zephyr

Below is the source code in four embedded operating systems for initialising a task: Huawei LiteOS, Apache Mynewt, FreeRTOS and Zephyr.

We can see that LiteOS and Mynewt are the most similar, since both are lightweight, modern operating systems.

Creating a task in Huawei LiteOS vs Apache Mynewt

Creating a task in FreeRTOS vs Zephyr


What’s Next

Although I won’t be running LiteOS, I’ll be porting some of the driver code to Apache Mynewt. Soon we’ll have an NB-IoT tutorial based on the Ghostyu NB-EK-L476 Developer Kit… In Embedded Rust!

Stay Tuned! Work in progress…

Rust and Mynewt transmitting over NB-IoT on the Ghostyu NB-EK-L476 Developer Kit

Rust and Mynewt running OK on the Ghostyu NB-EK-L476 Developer Kit. From https://github.com/lupyuen/stm32bluepill-mynewt-sensor/tree/l476