Ghostyu NB-EK-L476 Developer Kit
Quick Peek of Huawei LiteOS with NB-IoT on Ghostyu NB-EK-L476 Developer Kit (STM32L476RCT6)
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
- 128 KB RAM (96 KB at
0x2000 0000, 32 KB with hardware parity at
- Supported Interfaces: CAN, I2C, LPUART, SAI, SPI, USART, USB.
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)
L70-R GPS Module with GPS antenna
(Port UART2, PA1 for Enable Pin)
Underside of the board with GPS antenna
Temperature and Humidity Sensor
(Analog, Port ADC1, GPIO PB1)
(GPIO PC0 to PC3)
(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
and reuploaded to GitHub…
Source Code Structure
Overall Structure of LiteOS
The source code folder consists of three major subfolders…
LiteOS kernel source code. This is provided by Huawei and is common to all LiteOS projects. Arm
Cortex-specific code is also located here.
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.
Application source code. Provided by Ghostyu.
GCC, Keil and IAR build tools may be used to build LiteOS and the embedded application.
LiteOS Kernel Functions
The LiteOS kernel functions are
located in the
folder. The functions cover…
- Memory Management
- Interprocess Communication (Queues and Events)
- Task Synchronisation (Semaphore and Mutex)
- Task Management
- Time Management
- Hardware Interrupts and Exceptions
Below we see the contents of the
kernel folder, and a source file from the kernel that deals with
Kernel Functions. From https://github.com/lupyuen/NB-EK-L476/blob/master/kernel/base/core/los_task.c
In the same source file, we see
SystemClock_Config() function that powers on the STM32
microcontroller peripherals and initialises the clocks. Read
more about STM32 Clocks
main() function from https://github.com/lupyuen/NB-EK-L476/blob/master/user/main.c
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…
Source code for the optional LED display (SPI)
STM32 HAL (explained below)
Driver for onboard Quectel L70-R GPS module
Driver for onboard Quectel BC95 NB-IoT module
An drivers for various Onboard Sensors and Outputs:
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.
STM32 Hardware Adaptation Layer Functions. From https://github.com/lupyuen/NB-EK-L476/blob/master/platform/STM32L476RC_NBEK/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal.c
Quectel BC95 NB-IoT Driver
Below we see a State Transition
Machine for handling the AT commands:
(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…
Driver for Quectel L70-R GPS module. From https://github.com/lupyuen/NB-EK-L476/blob/master/platform/STM32L476RC_NBEK/GpsParse/gps_l70_r.c
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
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