This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LP-EM-CC2340R5: Propblem about modifying "FLASH_BASE" in .cmd file

Part Number: LP-EM-CC2340R5
Other Parts Discussed in Thread: UNIFLASH, SYSCONFIG

Tool/software:

Hello TI support Team,

I plan to allocate the bootloader's flash memory block from address 0x00000000 to 0x0000FFFF and designate address 0x00010000 as the application start address.

So I modified "FLASH_BASE" in lpf3_freertos.cmd file.

=========================================================

/*
 * Copyright (c) 2021-2024, Texas Instruments Incorporated
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * *  Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * *  Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * *  Neither the name of Texas Instruments Incorporated nor the names of
 *    its contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include "ti_utils_build_linker.cmd.genmap"

--stack_size=2048
--heap_size=0
--entry_point resetISR

/* Retain interrupt vector table variable                                    */
--retain "*(.resetVecs)"

/* Suppress warnings and errors:                                             */
/* - 10063: Warning about entry point not being _c_int00                     */
/* - 16011, 16012: 8-byte alignment errors. Observed when linking in object  */
/*   files compiled using Keil (ARM compiler)                                */
--diag_suppress=10063,16011,16012

/* Set severity of diagnostics to Remark instead of Warning                  */
/* - 10068: Warning about no matching log_ptr* sections                      */
--diag_remark=10068

/* The starting address of the application.  Normally the interrupt vectors  */
/* must be located at the beginning of the application.                      */
#define FLASH_BASE              0x00010000
#define FLASH_SIZE              ti_utils_build_GenMap_FLASH0_SIZE
#define RAM_BASE                ti_utils_build_GenMap_RAM0_BASE
#define RAM_SIZE                ti_utils_build_GenMap_RAM0_SIZE
#if defined(ti_utils_build_GenMap_S2RRAM_BASE) && \
    defined(ti_utils_build_GenMap_S2RRAM_SIZE)
#define S2RRAM_BASE             ti_utils_build_GenMap_S2RRAM_BASE
#define S2RRAM_SIZE             ti_utils_build_GenMap_S2RRAM_SIZE
#endif
#define CCFG_BASE               ti_utils_build_GenMap_CCFG_BASE
#define CCFG_SIZE               ti_utils_build_GenMap_CCFG_SIZE
#if defined(ti_utils_build_GenMap_SCFG_BASE) && \
    defined(ti_utils_build_GenMap_SCFG_SIZE)
#define SCFG_BASE               ti_utils_build_GenMap_SCFG_BASE
#define SCFG_SIZE               ti_utils_build_GenMap_SCFG_SIZE
#endif
#if defined(ti_utils_build_GenMap_HSMOTP_BASE) && \
    defined(ti_utils_build_GenMap_HSMOTP_SIZE)
#define HSMOTP_BASE             ti_utils_build_GenMap_HSMOTP_BASE
#define HSMOTP_SIZE             ti_utils_build_GenMap_HSMOTP_SIZE
#endif

/* System memory map */
MEMORY
{
    /* Bootloader stored in and executes from internal flash */
    //FLASH_BOOT (RX) : origin = 0x00000000, length = 0x00010000
    /* Application stored in and executes from internal flash */
    FLASH (RX) : origin = FLASH_BASE, length = (FLASH_SIZE - FLASH_BASE)
    /* Application uses internal RAM for data */
    SRAM (RWX) : origin = RAM_BASE, length = RAM_SIZE

#if defined(S2RRAM_BASE) && defined(S2RRAM_SIZE)
    /* S2RRAM is intended for the S2R radio module, but it can also be used by
     * the application with some limitations. Please refer to the s2rram example.
     */
    S2RRAM (RW) : origin = S2RRAM_BASE, length = S2RRAM_SIZE
#endif

    /* Configuration region */
    CCFG (R) : origin = CCFG_BASE, length = CCFG_SIZE

#if defined(SCFG_BASE) && defined(SCFG_SIZE)
    /* Security configuration region */
    SCFG (R): origin = SCFG_BASE, length = SCFG_SIZE
#endif
#if defined(HSMOTP_BASE) && defined(HSMOTP_SIZE)
    /* HSM OTP region */
    HSMOTP (R): origin = HSMOTP_BASE, length = HSMOTP_SIZE
#endif

    /* Explicitly placed off target for the storage of logging data.
     * The ARM memory map allocates 1 GB of external memory from 0x60000000 - 0x9FFFFFFF.
     * Unlikely that all of this will be used, so we are using the upper parts of the region.
     * ARM memory map: developer.arm.com/.../
    LOG_DATA (R) : origin = 0x90000000, length = 0x40000        /* 256 KB */
    LOG_PTR  (R) : origin = 0x94000008, length = 0x40000        /* 256 KB */
}

/* Section allocation in memory */
SECTIONS
{
    .resetVecs      :   > FLASH_BASE
    .text           :   > FLASH
    .TI.ramfunc     : {} load=FLASH, run=SRAM, table(BINIT)
    .const          :   > FLASH
    .constdata      :   > FLASH
    .rodata         :   > FLASH
    .binit          :   > FLASH
    .cinit          :   > FLASH
    .pinit          :   > FLASH
    .init_array     :   > FLASH
    .emb_text       :   > FLASH
    .ccfg           :   > CCFG

#if defined(SCFG_BASE) && defined(SCFG_SIZE)
    .scfg           :   > SCFG
#endif
#if defined(HSMOTP_BASE) && defined(HSMOTP_SIZE)
    .hsmotp         :   > HSMOTP
#endif

    .ramVecs        :   > SRAM, type = NOLOAD, ALIGN(256)
    .data           :   > SRAM
    .bss            :   > SRAM
    .sysmem         :   > SRAM
    .stack          :   > SRAM (HIGH)
    .nonretenvar    :   > SRAM

#if defined(S2RRAM_BASE) && defined(S2RRAM_SIZE)
    /* Placing the section .s2rram in S2RRAM region. Only uninitialized
     * objects may be placed in this section.
     */
    .s2rram         :   > S2RRAM, type = NOINIT
#endif

    .log_data       :   > LOG_DATA, type = COPY
    .log_ptr        : { *(.log_ptr*) } > LOG_PTR align 4, type = COPY
}
===========================================================
And CCS displays the following error message when I attempt to update the code in debug mode.
"Cortex_M0P: JTAG Communication Error: (Error -615 @ 0x0) The target failed to see a correctly formatted SWD header. The connection to the target may be unreliable. Try lowering the TCLK setting before trying again. (Emulation package 20.0.0.3178)
Cortex_M0P: Failed to remove the debug state from the target before disconnecting. There may still be breakpoint op-codes embedded in program memory. It is recommended that you reset the emulator before you connect and reload your program before you continue debugging"
Could you please teach me how to solve this problem?

Thank you for your guidance.

  • Hello Weiting Liao,

    I hope you are doing well. First lets double check that the device is functioning properly, can you open UniFlash and attempt to read the device memory (this should confirm that the device and debugger are ok).

    For modifying the flash we can leverage some of our migration examples (as we also modify the flash) from the SDK documentation:

    CC2340R5 to CC2340R22 Porting Guide — SimpleLinkTm Low Power F3 SDK BLE5-Stack User's Guide 3.03.02.00 documentation

    There is also plenty of other references to flash in our documentation as well:

    Flash — SimpleLinkTm Low Power F3 SDK BLE5-Stack User's Guide 3.03.02.00 documentation

    Thanks,
    Alex F

  • Hi Alex,

    The device works and shows no errors after restoring the 'FLASH_BASE' setting to 0x00000000 and updating the code in debug mode.

    Once I changed the FLASH_BASE to 0x00010000 and updated the code, the errors appeared again.

    This leads me to believe the issue is related to the FLASH_BASE setting, as the device itself is functioning properly.

    Do you have any further information or suggestions to help me resolve this issue?

    If you need any additional information, please let me know.

  • Hello Weiting Liao,

    In your Syscfg did you set your board to a custom board? One thought is that syscfg may still want to use the original flash base rather than the new one. 

    -Did you already follow the flash modification in the porting guide? (https://dev.ti.com/tirex/explore/content/simplelink_lowpower_f3_sdk_8_20_00_119/docs/ble5stack/ble_user_guide/html/ble-stack-5.x-guide/porting-guides/cc2340r5_to_cc2340r22.html?highlight=flash#migration-guide

    Thanks,
    Alex F 

  • Hi Alex,

    I made the modifications in the .cmd file as shown earlier and set my board to a custom board, but it still didn't work.

  • Hello Weiting Liao,

    Update: As a quick test I did modify the lpf3_nortos.cmd file and changed FLASH_SIZZE to 0x00010000 which was able to build and flash, though it seems like the setting may not have been applied as reading the memory using UniFlash seems like the flash did not start at 0x00010000; I may need mess around with the Flash Protection settings in device configuration.

    Thanks,
    Alex F

  • Hello Alex,

    It is the FLASH_BASE that determines the application start address, not the FLASH_SIZE.

    In my case, I was able to modify the FLASH_BASE and successfully build the project, but I couldn't flash the firmware.

    To verify, you can inspect the flash memory allocation in the .map file.

    The FLASH_SIZE setting does not impact the application start address.

    ====================.map file=======================

    MEMORY CONFIGURATION

    name origin length used unused attr fill
    ---------------------- -------- --------- -------- -------- ---- --------
    FLASH 00010000 00070000 000093ea 00066c16 R X
    SRAM 20000000 00009000 00005b14 000034ec RW X
    S2RRAM 40098000 00001000 00000000 00001000 RW
    CCFG 4e020000 00000800 00000800 00000000 R
    LOG_DATA 90000000 00040000 00000000 00040000 R
    LOG_PTR 94000008 00040000 00000000 00040000 R

    ........

    SECTION ALLOCATION MAP

    output attributes/
    section page origin length input sections
    -------- ---- ---------- ---------- ----------------
    .resetVecs
    *            0   00010000 0000008c
                      00010000 0000008c ti_freertos_config.o (.resetVecs)

    .binit 0 00010000 00000000

    .text 0 00010090 00008a24

    Thanks,
    Weiting Liao

  • Hello,

    There could be a couple of things going on here.

    1. Did you update the Bootloader Vector Table in the CCFG?

    It very well could be that ROM is jumping to wrong place because the vector table wasn't updated. You can find these settings in sysconfig Device Configuration --> Boot Configuration.

    2. Please read section 8.4.3 and 8.4.1 in the Technical reference manual for the CC2340. These two sections outline specific requirements for creating a custom bootloader.

    For instance, the bootloader entry function has a specific function prototype:

    Additionally, per point 1:

    Please let me know if you have more questions.

    Best,
    Nima Behmanesh

  • Hello Alex,

    I’ve resolved the issue.

    Thank you for your support!