Beginner
10 min

Simplify secure device-to-cloud connections with ESP32-C3-MINI-1-N4-A and STM32F031K6

IoT ExpressLink: Turning ordinary projects into extraordinary IoT solutions

IoT ExpressLink Click with Nucleo 32 with STM32F031K6 MCU

Published Oct 01, 2024

Click board™

IoT ExpressLink Click

Dev. board

Nucleo 32 with STM32F031K6 MCU

Compiler

NECTO Studio

MCU

STM32F031K6

Driven by a commitment to simplicity and security, our purpose is to make it easy for users to securely connect their devices to the cloud and effortlessly integrate with the extensive offerings of AWS services.

A

A

Hardware Overview

How does it work?

IoT ExpressLink Click is based on the ESP32-C3-MINI-1-N4-A, a 2.4GHz WiFi (802.11 b/g/n) and Bluetooth® 5 LE combo module from Espressif Systems that comes with an onboard PCB antenna and AWS IoT ExpressLink firmware (locked to the AWS). This module's core is the ESP32C3 series of SoC RISCV single-core 32-bit microprocessor (ESP32-C3FN4), a chip with an embedded flash of 4MB and a clock speed of up to 160MHz. Since flash is packaged in the ESP32-C3FN4 chip rather than integrated into the module, the ESP32-C3-MINI-1-N4-A has a smaller package size. Thanks to its rich set of features necessary to implement IoT ExpressLink services, this Click board™ is ideal for smart homes, industrial automation, health care,

consumer electronics, and generic IoT sensor hubs and data logger applications. The IoT ExpressLink Click interfaces with a host MCU through UART communication, which involves sending AT commands using RX and TX pins operating at a rate of 115200bps. Besides the UART pins, this Click board™ also employs other pins of the mikroBUS™ socket to enhance its functionality. For example, the WK pin is utilized as a module wake-up pin, the EVT pin detects significant events during operation, and the device enable pin RST offers a switch operation to turn ON/OFF the module. On the left side of the board, it is possible to find an additional unpopulated header that offers full support for debugging capabilities. With this

header, the user can use a JTAG interface for debugging, available through the JTAG interface pins (TDO, TCK, TDI, and TMS). On the right side of the board, there is also a set of unpopulated headers like extra UART pins for debugging and a header with user-configurable general-purpose I/O pins. This Click board™ can be operated only with a 3.3V logic voltage level. The board must perform appropriate logic voltage level conversion before using MCUs with different logic levels. Also, this Click board™ comes equipped with a library containing easy-to-use functions and an example code that can be used as a reference for further development.

IoT ExpressLink Click hardware overview image

Features overview

Development board

Nucleo 32 with STM32F031K6 MCU board provides an affordable and flexible platform for experimenting with STM32 microcontrollers in 32-pin packages. Featuring Arduino™ Nano connectivity, it allows easy expansion with specialized shields, while being mbed-enabled for seamless integration with online resources. The

board includes an on-board ST-LINK/V2-1 debugger/programmer, supporting USB reenumeration with three interfaces: Virtual Com port, mass storage, and debug port. It offers a flexible power supply through either USB VBUS or an external source. Additionally, it includes three LEDs (LD1 for USB communication, LD2 for power,

and LD3 as a user LED) and a reset push button. The STM32 Nucleo-32 board is supported by various Integrated Development Environments (IDEs) such as IAR™, Keil®, and GCC-based IDEs like AC6 SW4STM32, making it a versatile tool for developers.

Nucleo 32 with STM32F031K6 MCU double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

ARM Cortex-M0

MCU Memory (KB)

32

Silicon Vendor

STMicroelectronics

Pin count

32

RAM (Bytes)

4096

You complete me!

Accessories

Click Shield for Nucleo-32 is the perfect way to expand your development board's functionalities with STM32 Nucleo-32 pinout. The Click Shield for Nucleo-32 provides two mikroBUS™ sockets to add any functionality from our ever-growing range of Click boards™. We are fully stocked with everything, from sensors and WiFi transceivers to motor control and audio amplifiers. The Click Shield for Nucleo-32 is compatible with the STM32 Nucleo-32 board, providing an affordable and flexible way for users to try out new ideas and quickly create prototypes with any STM32 microcontrollers, choosing from the various combinations of performance, power consumption, and features. The STM32 Nucleo-32 boards do not require any separate probe as they integrate the ST-LINK/V2-1 debugger/programmer and come with the STM32 comprehensive software HAL library and various packaged software examples. This development platform provides users with an effortless and common way to combine the STM32 Nucleo-32 footprint compatible board with their favorite Click boards™ in their upcoming projects.

Click Shield for Nucleo-32 accessories 1 image

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
Reset
PA11
RST
NC
NC
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Module Wake-Up
PA8
PWM
Event Detection
PA12
INT
UART TX
PA10
TX
UART RX
PA9
RX
NC
NC
SCL
NC
NC
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

IoT ExpressLink Click Schematic schematic

Step by step

Project assembly

Click Shield for Nucleo-144 front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Nucleo 32 with STM32F031K6 MCU as your development board.

Click Shield for Nucleo-144 front image hardware assembly
Nucleo 144 with STM32L4A6ZG MCU front image hardware assembly
2x4 RGB Click front image hardware assembly
Prog-cut hardware assembly
Nucleo-32 with STM32 MCU MB 1 - upright/background hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
Necto image step 5 hardware assembly
Necto image step 6 hardware assembly
Clicker 4 for STM32F4 HA MCU Step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Debug Image Necto Step hardware assembly

Track your results in real time

Application Output

1. Application Output - In Debug mode, the 'Application Output' window enables real-time data monitoring, offering direct insight into execution results. Ensure proper data display by configuring the environment correctly using the provided tutorial.

2. UART Terminal - Use the UART Terminal to monitor data transmission via a USB to UART converter, allowing direct communication between the Click board™ and your development system. Configure the baud rate and other serial settings according to your project's requirements to ensure proper functionality. For step-by-step setup instructions, refer to the provided tutorial.

3. Plot Output - The Plot feature offers a powerful way to visualize real-time sensor data, enabling trend analysis, debugging, and comparison of multiple data points. To set it up correctly, follow the provided tutorial, which includes a step-by-step example of using the Plot feature to display Click board™ readings. To use the Plot feature in your code, use the function: plot(*insert_graph_name*, variable_name);. This is a general format, and it is up to the user to replace 'insert_graph_name' with the actual graph name and 'variable_name' with the parameter to be displayed.

Software Support

Library Description

This library contains API for IoT ExpressLink Click driver.

Key functions:

  • iotexpresslink_reset_device - This function resets device by toggling the RST pin state.

  • iotexpresslink_send_cmd - This function send command string by using UART serial interface.

Open Source

Code example

The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.

/*!
 * @file main.c
 * @brief IoT ExpressLink Click Example.
 *
 * # Description
 * This example demonstrates the use of IoT ExpressLink click board by bridging the USB UART
 * to mikroBUS UART which allows the click board to establish a connection with
 * the IoT ExpressLink over the Quick Connect demo application without an AWS account.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver, resets the click board to factory default settings, reads
 * and displays the vendor model and thing name on the USB UART, sets the WiFi credentials,
 * and attempts to connect to the AWS Cloud. If the initial attempt fails and the error
 * message "Failed to access network" or "Failed to login AWS (MQTT) broker" appears,
 * check the WiFi credentials and try running the example again.
 *
 * ## Application Task
 * All data received from the USB UART will be forwarded to mikroBUS UART, and vice versa.
 * At this point you should disconnect from the UART terminal and run the Quick Connect
 * demo application.
 *
 * ## Additional Function
 * - static void iotexpresslink_clear_app_buf ( void )
 * - static err_t iotexpresslink_process ( uart_t *uart )
 * - static err_t iotexpresslink_read_response ( iotexpresslink_t *ctx )
 *
 * @note
 * To run the demo, follow the below steps:
 * 1. If you opened a terminal application in the previous step, be sure to disconnect that
 *    application from the serial port. 
 * 2. Download the Quick Connect executable: 
 *    Mac: https://quickconnectexpresslinkutility.s3.us-west-2.amazonaws.com/QuickConnect_v1.9_macos.x64.tar.gz
 *    Windows: https://quickconnectexpresslinkutility.s3.us-west-2.amazonaws.com/QuickConnect_v1.9_windows.x64.zip
 *    Linux: https://quickconnectexpresslinkutility.s3.us-west-2.amazonaws.com/QuickConnect_v1.9_linux.x64.tar.gz
 * 3. Unzip the package, and follow the steps from the README file.
 * 
 * The demo will connect to IoT ExpressLink and give you an URL that you can use to visualize data
 * flowing from the device to the cloud using AT+SEND commands. The demo will run for up
 * to two minutes, and afterwards, you will be able to type AT+SEND commands yourself and
 * see the data coming in on the visualizer.
 * 
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "iotexpresslink.h"

#define PROCESS_BUFFER_SIZE 500

// Enter valid WiFi credentials below
#define WIFI_SSID   "MikroE Public"     // WiFi SSID
#define WIFI_PASS   "mikroe.guest"      // WiFi Password

static iotexpresslink_t iotexpresslink;
static log_t logger;

static uint8_t app_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
static int32_t app_buf_len = 0;

/**
 * @brief IoT ExpressLink clearing application buffer.
 * @details This function clears memory of application buffer and reset its length.
 * @note None.
 */
static void iotexpresslink_clear_app_buf ( void );

/**
 * @brief IoT ExpressLink data reading function.
 * @details This function reads data from device and concatenates data to application buffer. 
 * @param[in] ctx : Click context object.
 * See #iotexpresslink_t object definition for detailed explanation.
 * @return @li @c  0 - Read some data.
 *         @li @c -1 - Nothing is read.
 * See #err_t definition for detailed explanation.
 * @note None.
 */
static err_t iotexpresslink_process ( iotexpresslink_t *ctx ) ;

/**
 * @brief IoT ExpressLink read response function.
 * @details This function waits for a response message, reads and displays it on the USB UART.
 * @param[in] ctx : Click context object.
 * See #iotexpresslink_t object definition for detailed explanation.
 * @return @li @c  0 - OK response.
 *         @li @c -2 - Timeout error.
 *         @li @c -3 - Command error.
 *         @li @c -4 - Unknown error.
 * See #err_t definition for detailed explanation.
 * @note None.
 */
static err_t iotexpresslink_read_response ( iotexpresslink_t *ctx );

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    iotexpresslink_cfg_t iotexpresslink_cfg;  /**< Click config object. */

    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_info( &logger, " Application Init " );

    // Click initialization.
    iotexpresslink_cfg_setup( &iotexpresslink_cfg );
    IOTEXPRESSLINK_MAP_MIKROBUS( iotexpresslink_cfg, MIKROBUS_1 );
    if ( UART_ERROR == iotexpresslink_init( &iotexpresslink, &iotexpresslink_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    log_printf( &logger, "Reset device\r\n\n" );
    iotexpresslink_reset_device ( &iotexpresslink );
    Delay_ms ( 2000 );
    log_printf( &logger, "Factory reset\r\n" );
    strcpy ( app_buf, IOTEXPRESSLINK_CMD_FACTORY_RESET );
    iotexpresslink_send_cmd ( &iotexpresslink, app_buf );
    iotexpresslink_read_response ( &iotexpresslink );
    Delay_ms ( 2000 );
    
    log_printf( &logger, "Vendor model\r\n" );
    strcpy ( app_buf, IOTEXPRESSLINK_CMD_CONF_CHECK );
    strcat ( app_buf, IOTEXPRESSLINK_CMD_SEPARATOR );
    strcat ( app_buf, IOTEXPRESSLINK_CONF_KEY_ABOUT );
    iotexpresslink_send_cmd ( &iotexpresslink, app_buf );
    iotexpresslink_read_response ( &iotexpresslink );
    
    log_printf( &logger, "Thing name\r\n" );
    strcpy ( app_buf, IOTEXPRESSLINK_CMD_CONF_CHECK );
    strcat ( app_buf, IOTEXPRESSLINK_CMD_SEPARATOR );
    strcat ( app_buf, IOTEXPRESSLINK_CONF_KEY_THING_NAME );
    iotexpresslink_send_cmd ( &iotexpresslink, app_buf );
    iotexpresslink_read_response ( &iotexpresslink );
    
    log_printf( &logger, "WiFi SSID\r\n" );
    strcpy ( app_buf, IOTEXPRESSLINK_CMD_CONF );
    strcat ( app_buf, IOTEXPRESSLINK_CMD_SEPARATOR );
    strcat ( app_buf, IOTEXPRESSLINK_CONF_KEY_SSID );
    strcat ( app_buf, IOTEXPRESSLINK_CMD_SIGN_EQUAL );
    strcat ( app_buf, WIFI_SSID );
    iotexpresslink_send_cmd ( &iotexpresslink, app_buf );
    iotexpresslink_read_response ( &iotexpresslink );
    
    log_printf( &logger, "WiFi Password\r\n" );
    strcpy ( app_buf, IOTEXPRESSLINK_CMD_CONF );
    strcat ( app_buf, IOTEXPRESSLINK_CMD_SEPARATOR );
    strcat ( app_buf, IOTEXPRESSLINK_CONF_KEY_PASSPHRASE );
    strcat ( app_buf, IOTEXPRESSLINK_CMD_SIGN_EQUAL );
    strcat ( app_buf, WIFI_PASS );
    iotexpresslink_send_cmd ( &iotexpresslink, app_buf );
    iotexpresslink_read_response ( &iotexpresslink );
    
    log_printf( &logger, "Try to connect\r\n" );
    strcpy ( app_buf, IOTEXPRESSLINK_CMD_CONNECT );
    iotexpresslink_send_cmd ( &iotexpresslink, app_buf );
    iotexpresslink_read_response ( &iotexpresslink );
    
    log_info( &logger, " Application Task " );
    
    log_printf( &logger, "Now close the UART terminal and switch to the QuickConnect app\r\n" );
    Delay_ms ( 1000 );
    
    uart_set_blocking( &logger.uart, false );
}

void application_task ( void ) 
{
    app_buf_len = uart_read( &logger.uart, app_buf, PROCESS_BUFFER_SIZE );
    if ( app_buf_len > 0 ) 
    {
        uart_write ( &iotexpresslink.uart, app_buf, app_buf_len );
        iotexpresslink_clear_app_buf( );
    }
    app_buf_len = uart_read( &iotexpresslink.uart, app_buf, PROCESS_BUFFER_SIZE );
    if ( app_buf_len > 0 ) 
    {
        uart_write ( &logger.uart, app_buf, app_buf_len );
        iotexpresslink_clear_app_buf( );
    }
}

void main ( void ) 
{
    application_init( );

    for ( ; ; ) 
    {
        application_task( );
    }
}

static void iotexpresslink_clear_app_buf ( void ) 
{
    memset( app_buf, 0, app_buf_len );
    app_buf_len = 0;
}

static err_t iotexpresslink_process ( iotexpresslink_t *ctx ) 
{
    uint8_t rx_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
    int32_t rx_size = 0;
    rx_size = iotexpresslink_generic_read( ctx, rx_buf, PROCESS_BUFFER_SIZE );
    if ( rx_size > 0 ) 
    {
        int32_t buf_cnt = app_buf_len;
        if ( ( ( app_buf_len + rx_size ) > PROCESS_BUFFER_SIZE ) && ( app_buf_len > 0 ) ) 
        {
            buf_cnt = PROCESS_BUFFER_SIZE - ( ( app_buf_len + rx_size ) - PROCESS_BUFFER_SIZE );
            memmove ( app_buf, &app_buf[ PROCESS_BUFFER_SIZE - buf_cnt ], buf_cnt );
        }
        for ( int32_t rx_cnt = 0; rx_cnt < rx_size; rx_cnt++ ) 
        {
            if ( rx_buf[ rx_cnt ] ) 
            {
                app_buf[ buf_cnt++ ] = rx_buf[ rx_cnt ];
                if ( app_buf_len < PROCESS_BUFFER_SIZE )
                {
                    app_buf_len++;
                }
            }
        }
        return IOTEXPRESSLINK_OK;
    }
    return IOTEXPRESSLINK_ERROR;
}

static err_t iotexpresslink_read_response ( iotexpresslink_t *ctx ) 
{
    uint32_t timeout_cnt = 0;
    uint32_t timeout = 30000;
    memset( app_buf, 0, PROCESS_BUFFER_SIZE );
    app_buf_len = 0;
    iotexpresslink_process( ctx );
    while ( ( 0 == strstr( app_buf, IOTEXPRESSLINK_RSP_OK ) ) &&
            ( 0 == strstr( app_buf, IOTEXPRESSLINK_RSP_ERR ) ) )
    {
        iotexpresslink_process( ctx );
        if ( timeout_cnt++ > timeout )
        {
            iotexpresslink_clear_app_buf( );
            return IOTEXPRESSLINK_ERROR_TIMEOUT;
        }
        Delay_ms( 1 );
    }
    Delay_ms ( 100 );
    iotexpresslink_process( ctx );
    if ( app_buf_len > 0 ) 
    {
        log_printf( &logger, "%s\r\n", app_buf );
    }
    if ( strstr( app_buf, IOTEXPRESSLINK_RSP_OK ) )
    {
        iotexpresslink_clear_app_buf( );
        return IOTEXPRESSLINK_OK;
    }
    else if ( strstr( app_buf, IOTEXPRESSLINK_RSP_ERR ) )
    {
        iotexpresslink_clear_app_buf( );
        return IOTEXPRESSLINK_ERROR_CMD;
    }
    iotexpresslink_clear_app_buf( );
    return IOTEXPRESSLINK_ERROR_UNKNOWN;
}

// ------------------------------------------------------------------------ END

Additional Support

Resources

Love this project?

'Buy This Kit' button takes you directly to the shopping cart where you can easily add or remove products.