Intermediate
30 min

Embrace the future of communication with BM832A and STM32G474RE

Bluetooth 5.0 solution that has it all!

BLE 12 Click with Nucleo 64 with STM32G474RE MCU

Published Nov 08, 2024

Click board™

BLE 12 Click

Dev Board

Nucleo 64 with STM32G474RE MCU

Compiler

NECTO Studio

MCU

STM32G474RE

Enjoy high-quality audio and data transfer without limitations

A

A

Hardware Overview

How does it work?

BLE 12 Click is based on the BM832A, a highly flexible, ultra-low power Bluetooth module that provides BLE connectivity for any embedded application from Fanstel. The BM832A module is based on the Nordic nRF52 SoC, which integrates a 64MHz, 32bit ARM Cortex M4 processor with a floating-point unit (FPU) and a 2.4GHz multiprotocol radio (supporting Bluetooth 5.0 and an integrated PCB trace antenna), featuring -96dBm RX sensitivity (depending on data rate), alongside 192kB Flash memory and 24kB RAM. BLE 12 Click allows UART and SPI interfaces, with commonly used UART RX and TX pins as its default communication protocol for exchanging AT commands operating at 115200 bps by default configuration, to transmit and exchange data with the host MCU. The selection can be made by positioning SMD jumpers labeled COMM SEL in an appropriate position. Note that all the jumpers' positions must be on the same side, or the Click

board™ may become unresponsive. The CMD pin routed on the PWM pin of the mikroBUS™ represents the communication-activation feature. A high logic state of the CMD pin allows the module to communicate with the MCU, while a low state allows data to be sent to a far-end device (for example, a smartphone) transparently. With the selected UART interface, power consumption can be reduced by sending the command "AT+STOP". The CS pin must be set to a low logic state for 200μs or more to wake up the UART interface. Besides, it has an additional data-ready signal, labeled as REQ and routed on the INT pin of the mikroBUS™ socket, indicating that new data is ready for the host. This Click board™ comes with worldwide regulatory certifications and offers enhanced performance, security, and reliability to support IoT products running on Bluetooth networks. Besides, at the center of the BLE 12 Click, an additional unpopulated header offers full

support for debugging and programming capabilities. With this header, the user can use a Serial Wire Debug interface for programming and debugging, available through the SWD interface pins (SWDIO, SWCLK, and SWO). In addition to the appropriate interfaces, this Click board™ also has some additional features. A Reset button routed to the RST pin on the mikroBUS™ socket puts the module into a Reset state, while the two additional LED indicators, yellow and red LEDs labeled as LED1 and LED2, can be used for optional user-configurable visual indication. 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, it comes equipped with a library containing functions and an example code that can be used, as a reference, for further development.

BLE 12 Click hardware overview image

Features overview

Development board

Nucleo-64 with STM32G474R MCU offers a cost-effective and adaptable platform for developers to explore new ideas and prototype their designs. This board harnesses the versatility of the STM32 microcontroller, enabling users to select the optimal balance of performance and power consumption for their projects. It accommodates the STM32 microcontroller in the LQFP64 package and includes essential components such as a user LED, which doubles as an ARDUINO® signal, alongside user and reset push-buttons, and a 32.768kHz crystal oscillator for precise timing operations. Designed with expansion and flexibility in mind, the Nucleo-64 board features an ARDUINO® Uno V3 expansion connector and ST morpho extension pin

headers, granting complete access to the STM32's I/Os for comprehensive project integration. Power supply options are adaptable, supporting ST-LINK USB VBUS or external power sources, ensuring adaptability in various development environments. The board also has an on-board ST-LINK debugger/programmer with USB re-enumeration capability, simplifying the programming and debugging process. Moreover, the board is designed to simplify advanced development with its external SMPS for efficient Vcore logic supply, support for USB Device full speed or USB SNK/UFP full speed, and built-in cryptographic features, enhancing both the power efficiency and security of projects. Additional connectivity is

provided through dedicated connectors for external SMPS experimentation, a USB connector for the ST-LINK, and a MIPI® debug connector, expanding the possibilities for hardware interfacing and experimentation. Developers will find extensive support through comprehensive free software libraries and examples, courtesy of the STM32Cube MCU Package. This, combined with compatibility with a wide array of Integrated Development Environments (IDEs), including IAR Embedded Workbench®, MDK-ARM, and STM32CubeIDE, ensures a smooth and efficient development experience, allowing users to fully leverage the capabilities of the Nucleo-64 board in their projects.

Nucleo 64 with STM32G474RE MCU double side image

Microcontroller Overview

MCU Card / MCU

STM32G474RE front image

Architecture

ARM Cortex-M4

MCU Memory (KB)

512

Silicon Vendor

STMicroelectronics

Pin count

64

RAM (Bytes)

128k

You complete me!

Accessories

Click Shield for Nucleo-64 comes equipped with two proprietary mikroBUS™ sockets, allowing all the Click board™ devices to be interfaced with the STM32 Nucleo-64 board with no effort. This way, Mikroe allows its users to add any functionality from our ever-growing range of Click boards™, such as WiFi, GSM, GPS, Bluetooth, ZigBee, environmental sensors, LEDs, speech recognition, motor control, movement sensors, and many more. More than 1537 Click boards™, which can be stacked and integrated, are at your disposal. The STM32 Nucleo-64 boards are based on the microcontrollers in 64-pin packages, a 32-bit MCU with an ARM Cortex M4 processor operating at 84MHz, 512Kb Flash, and 96KB SRAM, divided into two regions where the top section represents the ST-Link/V2 debugger and programmer while the bottom section of the board is an actual development board. These boards are controlled and powered conveniently through a USB connection to program and efficiently debug the Nucleo-64 board out of the box, with an additional USB cable connected to the USB mini port on the board. Most of the STM32 microcontroller pins are brought to the IO pins on the left and right edge of the board, which are then connected to two existing mikroBUS™ sockets. This Click Shield also has several switches that perform functions such as selecting the logic levels of analog signals on mikroBUS™ sockets and selecting logic voltage levels of the mikroBUS™ sockets themselves. Besides, the user is offered the possibility of using any Click board™ with the help of existing bidirectional level-shifting voltage translators, regardless of whether the Click board™ operates at a 3.3V or 5V logic voltage level. Once you connect the STM32 Nucleo-64 board with our Click Shield for Nucleo-64, you can access hundreds of Click boards™, working with 3.3V or 5V logic voltage levels.

Click Shield for Nucleo-64 accessories 1 image

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
Reset
PC12
RST
SPI Chip Select
PB12
CS
SPI Clock
PB3
SCK
SPI Data OUT
PB4
MISO
SPI Data IN
PB5
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Communication Selection
PC8
PWM
Data-Ready
PC14
INT
UART TX
PA3
TX
UART RX
PA2
RX
NC
NC
SCL
NC
NC
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Schematic

BLE 12 Click Schematic schematic

Step by step

Project assembly

Click Shield for Nucleo-64 accessories 1 image hardware assembly

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

Click Shield for Nucleo-64 accessories 1 image hardware assembly
Nucleo 64 with STM32G474RE MCU front image hardware assembly
BarGraph 5 Click front image hardware assembly
Prog-cut hardware assembly
Nucleo-64 with STM32GXXX MCU MB 1 Micro B Conn - 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 via Debug Mode

1. Once the code example is loaded, pressing the "DEBUG" button initiates the build process, programs it on the created setup, and enters Debug mode.

2. After the programming is completed, a header with buttons for various actions within the IDE becomes visible. Clicking the green "PLAY" button starts reading the results achieved with the Click board™. The achieved results are displayed in the Application Output tab.

DEBUG_Application_Output

Software Support

Library Description

This library contains API for BLE 12 Click driver.

Key functions:

  • ble12_set_device_name - BLE 12 set device name function

  • ble12_set_op_mode - BLE 12 set operating mode function

  • ble12_send_cmd - BLE 12 sends the command function

Open Source

Code example

This example can be found in NECTO Studio. Feel free to download the code, or you can copy the code below.

/*!
 * @file main.c
 * @brief BLE 12 Click Example.
 *
 * # Description
 * This example reads and processes data from BLE 12 Click board™.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes UART driver and logs UART. 
 * After driver initialization, the app performs a wake-up module, 
 * enters command mode, sets the device name and advertising time interval, 
 * and disconnects all connections. 
 * After that, the blinking of the yellow LED Indicates
 * that the BLE 12 Click board™ is ready for connection. 
 * After establishing the connection, the yellow LED is turned on.
 *
 * ## Application Task
 * This example demonstrates the use of the BLE 12 Click board™. 
 * Reads the received data and parses it. 
 * Results are being sent to the Usart Terminal, where you can track their changes.
 *
 * ## Additional Function
 * - static void ble12_clear_app_buf ( void )
 * - static err_t ble12_process ( void )
 *
 * @note
 * We have used the Serial Bluetooth Terminal Android application for the test
 * and you can find it at the link:
 * https://play.google.com/store/apps/details?id=de.kai_morich.serial_bluetooth_terminal
 * 
 * @author Nenad Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "ble12.h"

#define PROCESS_BUFFER_SIZE 200
#define RSP_TIMEOUT         100

static ble12_t ble12;
static log_t logger;

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

/**
 * @brief BLE 12 clearing application buffer.
 * @details This function clears memory of application buffer and reset it's length and counter.
 * @note None.
 */
static void ble12_clear_app_buf ( void );

/**
 * @brief BLE 12 data reading function.
 * @details This function reads data from device and concatenates data to application buffer.
 *
 * @return @li @c  0 - Read some data.
 *         @li @c -1 - Nothing is read.
 *         @li @c -2 - Application buffer overflow.
 *
 * See #err_t definition for detailed explanation.
 * @note None.
 */
static err_t ble12_process ( void );

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    ble12_cfg_t ble12_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.
    ble12_cfg_setup( &ble12_cfg );
    BLE12_MAP_MIKROBUS( ble12_cfg, MIKROBUS_1 );
    if ( UART_ERROR == ble12_init( &ble12, &ble12_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    if ( BLE12_ERROR == ble12_default_cfg ( &ble12 ) )
    {
        log_error( &logger, " Default configuration." );
        for ( ; ; );
    }
    
    app_buf_len = 0;
    app_buf_cnt = 0;
    Delay_ms( 100 );
    log_info( &logger, " Application Task " );
    
    log_printf( &logger, "-------------------------------\r\n" );
    log_printf( &logger, "\t  BLE 12 Click\r\n" );
    log_printf( &logger, "-------------------------------\r\n" );
    log_printf( &logger, "\t  Command mode\r\n" );
    ble12_set_op_mode( &ble12, BLE12_OP_MODE_CMD );
    Delay_ms( 100 );
    
    ble12_event_startup( &ble12 );
    Delay_ms( 100 );
     
    ble12_set_led_state( &ble12, BLE12_LED_RED, BLE12_LED_OFF );
    ble12_set_led_state( &ble12, BLE12_LED_YELLOW, BLE12_LED_OFF );
    Delay_ms( 100 );
    
    log_printf( &logger, "- - - - - - - - - - - - - - - -\r\n" );
    log_printf( &logger, "> Set device name:" );
    log_printf( &logger, " BLE 12 Click\r\n" );
    ble12_set_device_name( &ble12, "BLE 12 Click" );
    Delay_ms( 100 );
    
    log_printf( &logger, "> Set Adv. Interval: 99 ms\r\n" );
    ble12_set_adv_interval( &ble12, "0099" );
    Delay_ms( 100 );
    
    log_printf( &logger, "> Disconnect all connections\r\n" );
    ble12_disconnect( &ble12 );
    Delay_ms( 100 );
    
    log_printf( &logger, "-------------------------------\r\n" );
    log_printf( &logger, "  Please connect your device\r\n" );
    
    do
    {
        ble12_process(); 
        ble12_set_led_state( &ble12, BLE12_LED_YELLOW, BLE12_LED_ON );
        Delay_ms( 50 );
        ble12_set_led_state( &ble12, BLE12_LED_YELLOW, BLE12_LED_OFF );
        Delay_ms( 50 );
    }
    while ( !strstr( app_buf, BLE12_EVT_CONNECTED ) );
    Delay_ms( 100 );

    ble12_set_led_state( &ble12, BLE12_LED_RED, BLE12_LED_OFF );
    ble12_set_led_state( &ble12, BLE12_LED_YELLOW, BLE12_LED_ON );
    log_printf( &logger, "- - - - - - - - - - - - - - - -\r\n" );
    log_printf( &logger, "\tDevice connected\r\n" );
    Delay_ms( 100 );
    
    ble12_set_op_mode( &ble12, BLE12_OP_MODE_DATA );
    log_printf( &logger, "-------------------------------\r\n" );
    log_printf( &logger, "\t    Data mode\r\n" );
    log_printf( &logger, "- - - - - - - - - - - - - - - -\r\n" );
    Delay_ms( 100 );
    
    ble12_process();
    ble12_clear_app_buf( );
    Delay_ms( 100 );
}

void application_task ( void ) 
{      
    ble12_process();
    
    if ( app_buf_len > 0 ) 
    { 
        log_printf( &logger, "%s", app_buf );
        ble12_clear_app_buf(  );    
    }
}

void main ( void ) 
{
    application_init( );

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

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

static err_t ble12_process ( void ) 
{
    int32_t rx_size;
    char rx_buff[ PROCESS_BUFFER_SIZE ] = { 0 };
    
    rx_size = ble12_generic_read( &ble12, rx_buff, PROCESS_BUFFER_SIZE );

    if ( rx_size > 0 ) 
    {
        int32_t buf_cnt = 0;

        if ( app_buf_len + rx_size >= PROCESS_BUFFER_SIZE ) 
        {
            ble12_clear_app_buf(  );
            return BLE12_ERROR;
        } 
        else
        {
            buf_cnt = app_buf_len;
            app_buf_len += rx_size;
        }

        for ( int32_t rx_cnt = 0; rx_cnt < rx_size; rx_cnt++ ) 
        {
            if ( ( rx_buff[ rx_cnt ] != 0 ) && ( rx_buff[ rx_cnt ] != 0x2B ) ) 
            {
                app_buf[ ( buf_cnt + rx_cnt ) ] = rx_buff[ rx_cnt ];   
            }
            else
            {
                app_buf_len--;
                buf_cnt--;
            }
        }
        
        
        
        return BLE12_OK;
    }
    return BLE12_ERROR;
}



// ------------------------------------------------------------------------ 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.