
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
Placing the Bluetooth Firmware in External Flash in AnyCloud Application - KBA232468
Version: **
Question:
How to place the Bluetooth firmware in external flash in AnyCloud application?
Answer:
A Wi-Fi and Bluetooth application based on AnyCloud SDK may not readily fit into the PSoC 6 MCU that has smaller internal flash (for example, 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 in external NOR flash, the flash consumption of the application can be reduced.
The Bluetooth firmware is located in the bluetooth-freertos in the following directory:
bluetooth-freertos/firmware/COMPONENT_<part_number> directory.
Where: <part_number> = Part number of the connectivity device (for example, 4343W).
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 are 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 prior to 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-anycloud-ble-battery-server code example and the PSoC 62S3 Wi-Fi BT Prototyping Kit (CY8CPROTO-062S3-4343W) as target. The PSoC 62S3 Wi-Fi BT Prototyping 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. You can easily adapt these steps to any application/target kit that supports the QSPI NOR flash.
Before you start, download and install the ModusToolbox software corresponding to your operating system. Perform these steps in the Eclipse IDE for ModusToolbox to place the BT firmware in external flash:
- Follow the steps in the Using the Code Example - In Eclipse IDE for ModusToolbox (steps 1-5) section, in the README.md file to clone the example. Refer to https://github.com/cypresssemiconductorco/mtb-example-anycloud-ble-battery-server example for this article. Use the CY8CPROTO-062S3-4343W Board Support Package (BSP) in step 2. The project is imported in the MTB IDE.
- In the Project Workspace window in the IDE, right-click the application name and select ModusToolbox > Library Manager.
- Perform these steps in the Library Manager:
- Set the bluetooth-freertos library as “local” instead of “shared”.
Note Changes performed in the local library will not affect other applications. - Add the serial-flash library to your project to communicate with the external flash.
- 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.
- Include the following headers in the Main.c file.
#include "cy_serial_flash_qspi.h"
#include "cycfg_qspi_memslot.h" - 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);
- Add the below code above the “const uint8_t brcm_patchram_buf[] = {” line in the
w_bt_firmware_controller.c file located at:
/AnyCloud_BLE_Battery_Server_External_Flash/libs/bluetooth
freertos/firmware/COMPONENT_4343W/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
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
- Follow these steps to connect the kit, build and program the BT firmware.
- Select the application project in the Project Explorer.
- 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.
- 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.
Additional Resources
- Refer to the PSoC 6 TRM for more details on the PSoC 6 memory architecture.
- Refer to the AN228740 for more details on the Serial Memory Interface.