Placing the Wi-Fi Firmware Into External Flash in an AnyCloud Application - KBA230802

Version 4

    Version: **

     

    Translation - Japanese: AnyCloudアプリケーションの外部フラッシュにWi-Fiファームウェアを配置する - KBA230802 - Community Translated (JA)

     

    A Wi-Fi application based on AnyCloud SDK may not readily fit into a PSoC 6 MCU that has smaller internal flash (e.g., PSoC 6 MCU with 512 KB flash). A Wi-Fi application image includes the Wi-Fi firmware image that will be loaded into the Wi-Fi device on start-up. By configuring the application to place the Wi-Fi firmware into external NOR flash, the flash consumption of the application can be reduced.

     

    For example, the size of the Wi-Fi firmware for the CYW4343W device is about 420 KB. Therefore, the size of the application built for PSoC 6 MCU + CYW4343W can be reduced by the same amount. You can find the Wi-Fi firmware inside the Wi-Fi Host Driver (WHD) under the WiFi_Host_Driver/resources/firmware/COMPONENT_<part_number> directory. <part_number> stands for the part number of the connectivity device (e.g., 4343W).

     

    The approach explained in this KBA makes use of the Execute-In-Place (XIP) feature of the Serial Memory Interface (SMIF) block (aka QSPI) in PSoC 6 MCU. This block supports interfacing with QSPI memory devices. The Wi-Fi 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 XIP mode before initializing the Wi-Fi 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-wifi-scan code example and the PSoC 62S3 Wi-Fi BT Prototyping Kit (CY8CPROTO-062S3-4343W) as target. This kit has 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 other application or target kit that supports QSPI NOR flash.

     

    Before you start, download and install ModusToolbox software corresponding to your operating system before proceeding. To run the commands, you can use any terminal application on Linux and macOS. On Windows, navigate to the modus-shell directory {ModusToolbox install directory}/tools_<version>/modus-shell and run Cygwin.bat.

     

    Steps

    1. Clone the code example and change the working directory to the root of the code example:

    git clone https://github.com/cypresssemiconductorco/mtb-example-anycloud-wifi-scan.git

    cd mtb-example-anycloud-wifi-scan

     

    2. Add the Board Support Package (BSP) for CY8CPROTO-062S3-4343W kit:

    echo https://github.com/cypresssemiconductorco/TARGET_CY8CPROTO-062S3-4343W/#latest-v1.X >> deps/TARGET_CY8CPROTO-062S3-4343W.lib

    Alternatively, you can use the library-manager tool to add BSPs and libraries to the code example. See the user guide for details.

     

    3. Add the serial-flash library to the application:

    echo https://github.com/cypresssemiconductorco/serial-flash/#latest-v1.X >> deps/serial-flash.lib

     

    4. Import the libraries by running the make getlibs command.

    If you build the application at this point targeting CY8CPROTO-062S3-4343W, the build will fail during the linking stage with error messages like section `.text' is not within region `flash' and region `flash' overflowed by 53708 bytes.

     

    5. Add the following lines in the Makefile after the line that begins with DEFINES=

      DEFINES+=CY_ENABLE_XIP_PROGRAM

      DEFINES+=CY_STORAGE_WIFI_DATA=\".cy_xip\"

     

    • CY_ENABLE_XIP_PROGRAM – Allows the external memory configuration to be placed into the supervisory flash (SFlash) area so that the programmer tool can 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_WIFI_DATA=\".cy_xip\"" – Allows placing the constant arrays carrying the Wi-Fi firmware to be placed into the .cy_xip section which is placed into the external memory.

     

    6. Include the following headers in main.c:

    #include "cy_serial_flash_qspi.h"

    #include "cycfg_qspi_memslot.h"

     

    7. Insert the following code in main.c 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);

     

      

     

    8. Connect the kit, and then build and program the firmware using the following command:

    make program -j8 TARGET=CY8CPROTO-062S3-4343W

    If you do not want to specify the TARGET with the make command every time, you can update the value of the TARGET variable in the Makefile to CY8CPROTO-062S3-4343W.

    You can see in the command terminal that the external memory denoted by the XIP region starting from the address 0x18000000 is erased and programmed.

     

    9. Run the code example by following the instructions in README.md of the code example. You can quickly see the Wi-Fi scan results by connecting a serial terminal to KitProg3 COM port with 8N1, 115200 baud settings.