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.

FOC例程lab5b的CSM加密问题,加密后程序无法运行

Other Parts Discussed in Thread: C2000WARE

我使用的是F28027F芯片,首先将文件CSMPasswords.asm加进工程,然后修改enableCSM .set 1,使能加密,然后在工程里预定义宏CSM_ENABLE,编译后提示*econst_end、*econst_start、*switch_end和*switch_start这些符号没有定义。然后我修改F28027F.cmd,从RAM的M0-M1里的0x500地址开始划分0x100大小空间到PAGE0,命名P_RAMM0_M1,接着设置.econst和.switch的拷贝加载地址:

.econst : LOAD = D_FLASHA,
RUN = P_RAMM0_M1,
LOAD_START(_econst_start),
LOAD_END(_econst_end),
RUN_START(_econst_ram_load),
PAGE = 0

.switch : LOAD = D_FLASHA,
RUN = P_RAMM0_M1,
LOAD_START(_switch_start),
LOAD_END(_switch_end),
RUN_START(_switch_ram_load),
PAGE = 0

程序编译通过,使用XDS100v2仿真器烧到芯片后,通过仿真器在线调试,能正常运行,中断服务函数里的闪灯正常闪烁。但问题是,将仿真器脱开后重新上电,程序感觉死掉了,灯也不闪烁。我再次将enableCSM .set 0,去除加密功能后烧进Flash,这时仿真器脱开也能正常运行。

我想请问下这是什么原因?另外,TI的FOC例程有没有测试过加密功能是否能用?我谨慎怀疑源程序存在Bug

谢谢大家!

  • 附上当前设置的CMD文件

    MEMORY
    {
    PAGE 0: /* Program Memory */
    /* Memory (RAM/FLASH/OTP) blocks can be moved to PAGE1 for data allocation */

    OTP : origin = 0x3D7800, length = 0x000400 /* on-chip OTP */
    CSM_RSVD : origin = 0x3F7F80, length = 0x000076 /* Part of FLASHA. Program with all 0x0000 when CSM is in use. */
    BEGIN : origin = 0x3F7FF6, length = 0x000002 /* Part of FLASHA. Used for "boot to Flash" bootloader mode. */
    CSM_PWL_P0 : origin = 0x3F7FF8, length = 0x000008 /* Part of FLASHA. CSM password locations in FLASHA */

    IQTABLES : origin = 0x3FE000, length = 0x000B50 /* IQ Math Tables in Boot ROM */
    IQTABLES2 : origin = 0x3FEB50, length = 0x00008C /* IQ Math Tables in Boot ROM */
    IQTABLES3 : origin = 0x3FEBDC, length = 0x0000AA /* IQ Math Tables in Boot ROM */

    ROM : origin = 0x3FF27C, length = 0x000D44 /* Boot ROM */
    RESET : origin = 0x3FFFC0, length = 0x000002 /* part of boot ROM */
    VECTORS : origin = 0x3FFFC2, length = 0x00003E /* part of boot ROM */
    FLASHB_D : origin = 0x3F0000, length = 0x006000 /* on-chip FLASH B, C and D */
    D_FLASHA : origin = 0x3F6000, length = 0x001F80 /* on-chip FLASH A */
    P_RAML0 : origin = 0x008000, length = 0x000980 /* on-chip PRAM block L0 */
    P_RAMM0_M1 : origin = 0x000500, length = 0x000100
    PAGE 1 : /* Data Memory */
    /* Memory (RAM/FLASH/OTP) blocks can be moved to PAGE0 for program allocation */
    /* Registers remain on PAGE1 */

    RAMM0_M1 : origin = 0x000000, length = 0x000500 /* on-chip RAM block M0 + M1. 0x600 to 0x800 reserved for InstaSPIN */
    D_RAML0 : origin = 0x008980, length = 0x000680 /* on-chip DRAM block L0 */
    }

    /* Allocate sections to memory blocks.
    Note:
    codestart user defined section in DSP28_CodeStartBranch.asm used to redirect code
    execution when booting to flash
    ramfuncs user defined section to store functions that will be copied from Flash into RAM
    */

    SECTIONS
    {
    /* Allocate program areas: */
    .cinit : > FLASHB_D PAGE = 0
    .pinit : > FLASHB_D, PAGE = 0
    .text : > FLASHB_D PAGE = 0
    codestart : > BEGIN PAGE = 0
    ramfuncs : LOAD = FLASHB_D,
    RUN = P_RAML0,
    LOAD_START(_RamfuncsLoadStart),
    LOAD_END(_RamfuncsLoadEnd),
    RUN_START(_RamfuncsRunStart),
    PAGE = 0

    csmpasswds : > CSM_PWL_P0 PAGE = 0
    csm_rsvd : > CSM_RSVD PAGE = 0

    /* Allocate uninitalized data sections: */
    .stack : > D_RAML0 PAGE = 1
    .ebss : > RAMM0_M1 PAGE = 1
    .esysmem : > RAMM0_M1 PAGE = 1

    ebss_extension : > P_RAML0 PAGE = 0
    rom_accessed_data : > RAMM0_M1 PAGE = 1

    vib_buf_data : > D_RAML0 PAGE = 1
    graph_data : > D_RAML0 PAGE = 1

    /* Initalized sections go in Flash */
    /* For SDFlash to program these, they must be allocated to page 0 */
    // .econst : > D_FLASHA, PAGE = 0
    // .switch : > D_FLASHA, PAGE = 0

    .econst : LOAD = D_FLASHA,
    RUN = P_RAMM0_M1,
    LOAD_START(_econst_start),
    LOAD_END(_econst_end),
    RUN_START(_econst_ram_load),
    PAGE = 0

    .switch : LOAD = D_FLASHA,
    RUN = P_RAMM0_M1,
    LOAD_START(_switch_start),
    LOAD_END(_switch_end),
    RUN_START(_switch_ram_load),
    PAGE = 0

    /* Allocate IQ math areas: */
    IQmath : > FLASHB_D PAGE = 0 /* Math Code */
    IQmathTables : > IQTABLES, PAGE = 0, TYPE = NOLOAD

    /* Uncomment the section below if calling the IQNexp() or IQexp()
    functions from the IQMath.lib library in order to utilize the
    relevant IQ Math table in Boot ROM (This saves space and Boot ROM
    is 1 wait-state). If this section is not uncommented, IQmathTables2
    will be loaded into other memory (SARAM, Flash, etc.) and will take
    up space, but 0 wait-state is possible.
    */
    /*
    IQmathTables2 : > IQTABLES2, PAGE = 0, TYPE = NOLOAD
    {

    IQmath.lib<IQNexpTable.obj> (IQmathTablesRam)

    }
    */
    /* Uncomment the section below if calling the IQNasin() or IQasin()
    functions from the IQMath.lib library in order to utilize the
    relevant IQ Math table in Boot ROM (This saves space and Boot ROM
    is 1 wait-state). If this section is not uncommented, IQmathTables3
    will be loaded into other memory (SARAM, Flash, etc.) and will take
    up space, but 0 wait-state is possible.
    */
    /*
    IQmathTables3 : > IQTABLES3, PAGE = 0, TYPE = NOLOAD
    {

    IQmath.lib<IQNasinTable.obj> (IQmathTablesRam)

    }
    */

    /* .reset is a standard section used by the compiler. It contains the */
    /* the address of the start of _c_int00 for C Code. */
    /* When using the boot ROM this section and the CPU vector */
    /* table is not needed. Thus the default type is set here to */
    /* DSECT */
    .reset : > RESET, PAGE = 0, TYPE = DSECT
    vectors : > VECTORS PAGE = 0, TYPE = DSECT

    }
  • 你好,能否介绍一下你的加密方法是哪里看到的吗?我查找了很多资料都没看到类似enableCSM .set 1的做法。
  • 你好,是例程里自带的CSMPasswords.asm文件

    ;// TI File $Revision: /main/1 $
    ;// Checkin $Date: August 14, 2008 16:58:11 $
    ;//###########################################################################
    ;//
    ;// FILE: DSP2802x_CSMPasswords.asm
    ;//
    ;// TITLE: DSP2802x Code Security Module Passwords.
    ;//
    ;// DESCRIPTION:
    ;//
    ;// This file is used to specify password values to
    ;// program into the CSM password locations in Flash
    ;// at 0x3F7FF8 - 0x3F7FFF.
    ;//
    ;// In addition, the reserved locations 0x3F7F80 - 0X3f7ff5 are
    ;// all programmed to 0x0000
    ;//
    ;//###########################################################################
    ;//
    ;// Original source based on D.A.
    ;//
    ;// $TI Release: 2802x Header Files V1.00 $
    ;// $Release Date: November 10, 2008 $
    ;//###########################################################################

    ; The "csmpasswords" section contains the actual CSM passwords that will be
    ; linked and programmed into to the CSM password locations (PWL) in flash.
    ; These passwords must be known in order to unlock the CSM module.
    ; All 0xFFFF's (erased) is the default value for the password locations (PWL).

    ; It is recommended that all passwords be left as 0xFFFF during code
    ; development. Passwords of 0xFFFF do not activate code security and dummy
    ; reads of the CSM PWL registers is all that is required to unlock the CSM.
    ; When code development is complete, modify the passwords to activate the
    ; code security module.

    enableCSM .set 0 ;0-disable CSM, 1-enable CSM

    .sect "csmpasswds"

    .if enableCSM == 1 ; enableCSM=1
    .int 0xFFFF ;PWL0 (LSW of 128-bit password)
    .int 0xFFFF ;PWL1
    .int 0xFFFF ;PWL2
    .int 0xFFFF ;PWL3
    .int 0xFFF4 ;PWL4
    .int 0xFFF5 ;PWL5
    .int 0xFFF6 ;PWL6
    .int 0xFFF7 ;PWL7 (MSW of 128-bit password)
    .else ; enableCSM=0
    .int 0xFFFF ;PWL0 (LSW of 128-bit password)
    .int 0xFFFF ;PWL1
    .int 0xFFFF ;PWL2
    .int 0xFFFF ;PWL3
    .int 0xFFFF ;PWL4
    .int 0xFFFF ;PWL5
    .int 0xFFFF ;PWL6
    .int 0xFFFF ;PWL7 (MSW of 128-bit password)
    .endif

    ;----------------------------------------------------------------------

    ; For code security operation, all addresses between 0x3F7F80 and
    ; 0X3f7ff5 cannot be used as program code or data. These locations
    ; must be programmed to 0x0000 when the code security password locations
    ; (PWL) are programmed. If security is not a concern, then these addresses
    ; can be used for code or data.

    ; The section "csm_rsvd" can be used to program these locations to 0x0000.

    .sect "csm_rsvd"
    .loop (3F7FF5h - 3F7F80h + 1)
    .int 0x0000
    .endloop

    ;//===========================================================================
    ;// End of file.
    ;//===========================================================================

  • lab05b本身应该是不带有CSM代码的,上述代码可能是之前版本的CSM代码。你试一下以下位置的f2802x_csmpasswords.asm:
    C:\ti\c2000\C2000Ware_3_02_00_00\device_support\f2802x\common\source
    另外,上传代码的话最好用回复框右下角的“使用高级编辑器编辑文本”,里面有上传代码的摁键,点击之后用代码上传工具上传。
  • 你发的这个asm和我说的asm没有本质区别,不能解决问题

  • 你测试过吗?如果用最新的文件还是有问题,那就是其他地方的错误了。
  • 我使用F28069F时候也遇到同样的问题,请问您解决了吗?