Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob

Placing the Bluetooth® firmware into an external flash in a Wi-Fi application – KBA232468

Placing the Bluetooth® firmware into an external flash in a Wi-Fi application – KBA232468

ArunKumarChoul
Employee
Employee
50 questions asked 50 sign-ins 25 sign-ins

Version: *A

A Wi-Fi and Bluetooth® application based on ModusToolbox™ for connectivity run-time software may not readily fit into a PSoC™ 6 MCU that has smaller internal flash (e.g., PSoC™ 6 MCU with 512-KB flash). A Bluetooth® application image includes the Bluetooth® firmware image that will be loaded into the Bluetooth® device on start-up. By configuring the application to place the Bluetooth® firmware into an external NOR flash, the flash consumption of the application can be reduced.

You can find the Bluetooth® firmware inside the btstack-integration under the
btstack-integration/ COMPONENT_< transport_methods> /firmware/COMPONENT_<part_number>
 directory.

Where,

  • <part_number> is the part number of the connectivity device (for example, 4343W).
  • <transport_methods> is the transport method (such as BLESS-IPC, BTSS-IPC, and HCI-UART) supported.
  •  There is only one product that supports BLESS-IPC tansport method. Therfore, the path does not have “firmware/COMPONENT_<part_number>” in it.

The approach explained in this KBA makes use of the Execute-In-Place (XIP) feature of the Serial Memory Interface (SMIF) block (i.e., QSPI) in the PSoC™ 6 MCU. The SMIF block supports interfacing with QSPI memory devices. The Bluetooth® firmware available in the form of C arrays is placed into the linker section “.cy_xip” using the linker attribute “section”. The data from the “.cy_xip section is then programmed into the external flash by the programmer. The application must initialize the QSPI interface and enable the XIP mode before initializing the Bluetooth® interface. In XIP mode, the SMIF block translates the memory accesses from CPU to the addresses starting from 0x18000000 (XIP region) into QSPI transfers, and therefore, the accesses are transparent to the CPU. This approach makes use of serial-flash library that provides API to interface with the external memory.

This approach is demonstrated using the mtb-example-btstack-freertos-battery-server code example and the PSoC™ 62S3 Wi-Fi & Bluetooth® Prototyping Kit (CY8CPROTO-062S3-4343W) as the target. This kit consists of the PSoC™ 6 MCU with 512-KB flash and 256-KB SRAM with QSPI interface support and the CYW4343W connectivity device. The kit also has S25FL512S, which is a 64-MB (512 Mbit) QSPI NOR flash.

Before you start, download and install the ModusToolbox™ corresponding to the operating system. Do the following to place the Bluetooth® firmware in the external flash:

  1. Clone the application by following the steps in the “Using the Code Example - In Eclipse IDE for ModusToolbox™” (steps 1-5) section in the README.md. For more details, see the Bluetooth® LE Battery Server with OTA update code example. Use the CY8CPROTO-062S3-4343W board support package (BSP) in step 2. The project is imported in the ModusToolbox™ IDE.
  2. In the Project Workspace window in the IDE, right-click on the application name and select ModusToolbox™ > Library Manager.
  3. Do the following steps in the Library Manager:
    a) Set the btstack-integration library as “Local Git Repo” instead of “Shared Git Repo”.

    Note:  Changes done in the local library will not affect other applications.
    b) Add the serial-flash library to your project to communicate with the external flash.
IFX_Publisher2_0-1696832206206.pngFigure 1  Selecting the serial-flash

  1. Add the following code in the Makefile after the line that begins with DEFINES=.

DEFINES+=CY_ENABLE_XIP_PROGRAM
DEFINES+=CY_STORAGE_BT_DATA=\".cy_xip\"

CY_ENABLE_XIP_PROGRAM allows the external memory configuration to be placed into the supervisory flash (SFlash) area. This allows the programmer tool to read the configuration to understand how to communicate with the memory through the SMIF block. See the cy_serial_flash_prog.c file for details.

CY_STORAGE_BT_DATA=\".cy_xip\" allows placing the constant arrays carrying the BT firmware to be placed into the .cy_xip section which is placed into the external memory.

  1. Include the following headers in the Main.c file.
    #include "cy_serial_flash_qspi.h"
    #include "cycfg_qspi_memslot.h"

  2. Add the following code in the Main.c file as shown in the screenshot below.

    const uint32_t bus_frequency = 50000000lu;

    cy_serial_flash_qspi_init(smifMemConfigs[0], CYBSP_QSPI_D0, CYBSP_QSPI_D1,

    CYBSP_QSPI_D2, CYBSP_QSPI_D3, NC, NC, NC, NC, 

    CYBSP_QSPI_SCK, CYBSP_QSPI_SS, bus_frequency);

    cy_serial_flash_qspi_enable_xip(true);

    IFX_Publisher2_1-1696832350866.pngFigure 2  Code to initialize the QSP

  3. Add the following code above the const uint8_t brcm_patchram_buf[] = { line in the w_bt_firmware_controller.c file located at:

    /mtb-example-btstack-freertos-battery-server/libs/btstack-integration/COMPONENT_HCI-UART/firmware/COMPONENT_4343W/COMPONENT_MURATA-1DX/w_bt_firmware_controller.c

Note The location of the file is important as there can be two of these files, one shared and one local. Choose the ‘local’ file.

#if defined(CY_STORAGE_BT_DATA)
__attribute__((section(CY_STORAGE_BT_DATA))) __attribute__((used))
#endif

This code works when you are using the GNU or Arm® C Compiler.

IFX_Publisher2_2-1696832577888.png

 


The above code works when you are using the GNU or Arm C Compiler. For other compiler, modify the code as shown below:

ICCARM:
#if defined(CY_STORAGE_BT_DATA)
CY_PRAGMA(location = CY_STORAGE_BT_DATA) __attribute__((used))
#endif

  1. Follow these steps to connect the kit, build and program the BT firmware.
  1. Select the application project in the Project Explorer.
  2. In the Quick Panel, select \<Application Name > Program (KitProg3). The external memory denoted by the XIP region starting from the address 0x18000000 is erased and programmed in the command terminal.

    IFX_Publisher2_0-1696834401523.png 9. Run the code example by following the instructions in README.md of the code example. To view the logs, connect
    a serial terminal to KitProg3 COM port with the 8N1, 115200 baud settings.


    References

     


0 Likes
480 Views