英飞凌
直播中

陈静

7年用户 1269经验值
私信 关注

如何将ASM集成到PSoC5LP项目中?

我希望将 AN78175 的安全软件程序库集成到我正在开发的 PSoC5LP 项目中,该项目需要对 RAM/闪存/CPU 进行更密集的自测试。  我的问题是在尝试组装 SelfTest_CPU_s.s 时出现的。 装配源文件。  出于某种原因,它似乎无法识别表示注释的分号字符?
以下是该文件的完整内容:

;-------------------------------------------------------------------------------; FILENAME: SelfTest_CPU.s; Version 1.0;;  DESCRIPtiON:;    Assembly routines for RealView compiler.;;-------------------------------------------------------------------------------; Copyright 2010-2012, Cypress Semiconductor Corporation.  All rights reserved.; You may use this file only in accordance with the license, terms, conditions, ; disclaimers, and limitations in the end user license agreement accompanying ; the software package with which this file was provided.;-------------------------------------------------------------------------------    AREA |.text|,CODE    THUMB;-------------------------------------------------------------------------------; Function Name: CPU_PSoC_5_Asm;-------------------------------------------------------------------------------; Summary:;   Tests all ARM M3 CPU registers except PC.;; Parameters:;   None;; Return:;   void.;;-------------------------------------------------------------------------------; void CPU_PSoC_5_Asm(void)CPU_PSoC_5_Asm FUNCTION    EXPORT CPU_PSoC_5_Asm        PUSH  {R1-R12, LR}                        MOV   R0, #0xAAAAAAAA        CMP   R0, #0xAAAAAAAA          BNE.W   test_asm_fail             MOV   R0, #0x55555555          CMP   R0, #0x55555555          BNE.W   test_asm_fail                 MOV   R1, #0xAAAAAAAA        CMP   R1, #0xAAAAAAAA          BNE.W   test_asm_fail           MOV   R1, #0x55555555          CMP   R1, #0x55555555          BNE.W   test_asm_fail                   MOV   R2, #0xAAAAAAAA        CMP   R2, #0xAAAAAAAA          BNE.W   test_asm_fail           MOV   R2, #0x55555555          CMP   R2, #0x55555555          BNE.W   test_asm_fail                MOV   R3, #0xAAAAAAAA        CMP   R3, #0xAAAAAAAA          BNE   test_asm_fail           MOV   R3, #0x55555555          CMP   R3, #0x55555555          BNE   test_asm_fail                    MOV   R4, #0xAAAAAAAA        CMP   R4, #0xAAAAAAAA          BNE   test_asm_fail           MOV   R4, #0x55555555          CMP   R4, #0x55555555          BNE   test_asm_fail                MOV   R5, #0xAAAAAAAA        CMP   R5, #0xAAAAAAAA          BNE   test_asm_fail           MOV   R5, #0x55555555          CMP   R5, #0x55555555          BNE   test_asm_fail                   MOV   R6, #0xAAAAAAAA        CMP   R6, #0xAAAAAAAA          BNE   test_asm_fail           MOV   R6, #0x55555555          CMP   R6, #0x55555555          BNE   test_asm_fail                MOV   R7, #0xAAAAAAAA        CMP   R7, #0xAAAAAAAA          BNE   test_asm_fail           MOV   R7, #0x55555555          CMP   R7, #0x55555555          BNE   test_asm_fail                    MOV   R8, #0xAAAAAAAA        CMP   R8, #0xAAAAAAAA          BNE   test_asm_fail           MOV   R8, #0x55555555          CMP   R8, #0x55555555          BNE   test_asm_fail                MOV   R9, #0xAAAAAAAA        CMP   R9, #0xAAAAAAAA          BNE   test_asm_fail           MOV   R9, #0x55555555          CMP   R9, #0x55555555          BNE   test_asm_fail                   MOV   R10, #0xAAAAAAAA        CMP   R10, #0xAAAAAAAA          BNE   test_asm_fail           MOV   R10, #0x55555555          CMP   R10, #0x55555555          BNE   test_asm_fail                MOV   R11, #0xAAAAAAAA        CMP   R11, #0xAAAAAAAA          BNE   test_asm_fail           MOV   R11, #0x55555555          CMP   R11, #0x55555555          BNE   test_asm_fail                  MOV   R12, #0xAAAAAAAA        CMP   R12, #0xAAAAAAAA          BNE   test_asm_fail           MOV   R12, #0x55555555          CMP   R12, #0x55555555          BNE   test_asm_fail                           MOV   LR, #0xAAAAAAAA        CMP   LR, #0xAAAAAAAA          BNE   test_asm_fail           MOV   LR, #0x55555555          CMP   LR, #0x55555555          BNE   test_asm_fail                       ; Test SP register         ; Note: SP ignores writes to the lower two bits,         ; so they are intentionally set to 0                            ; Save SP to R0                  MOV   R0, SP                            ; Load SP with 0xAAAAAAA8         LDR   R1, =0xAAAAAAA8           MOV   SP, R1                      CMP   SP, R1                             ; Restore SP and return failure         IT    NE                         MOVNE SP, R0                  BNE   test_asm_fail                 ; Load SP with #0x55555554         LDR   R1, =0x55555554            MOV   SP, R1                      CMP   SP, R1                      IT    NE                          MOVNE SP, R0                  BNE   test_asm_fail         MOV   SP, R0                              ; Return success         MOV   R0, #0                     POP   {R1-R12, LR}              BX    LR                                     ; Return failure test_asm_fail                     MOV   R0, #0x00000001           POP   {R1-R12, LR}             BX    LR                            ENDFUNC    END;[] END OF FILE

我知道这个代码已经很旧了(好像是 2012 年的)。  是否存在某些不兼容性?  我注意到它在顶部注释块中提到了"RealView Compiler" 。  这可能是某个不再使用的传统编译器/汇编器吗?  无论如何,ARM GNU GCC 是否不将分号视为注释?  我是否应该删除这个源文件,然后使用写在 SelfTest_CPU_asm.c 中的 CPU_PSoC_Asm() 函数? 文件?  我相信,它所做的事情本质上是一样的:

    __attribute__((naked)) uint8 CPU_PSoC_Asm(void)      /* declaration of function if PSoC 5 GCC compiler */    {            /* Disable global interrupts */            CyGlobalIntDisable;                            __ASM volatile (            "     PUSH  {R1-R12, LR}          nt"            CPU_REGISTER_TEST("R0")                      #if (ERROR_IN_CPU_REGISTERS)                CPU_REGISTER_TEST_ERROR("R1")            #else                    CPU_REGISTER_TEST("R1")            #endif              CPU_REGISTER_TEST("R2")            CPU_REGISTER_TEST("R3")            CPU_REGISTER_TEST("R4")            CPU_REGISTER_TEST("R5")            CPU_REGISTER_TEST("R6")            CPU_REGISTER_TEST("R7")            CPU_REGISTER_TEST("R8")            CPU_REGISTER_TEST("R9")            CPU_REGISTER_TEST("R10")            CPU_REGISTER_TEST("R11")            CPU_REGISTER_TEST("R12")            CPU_REGISTER_TEST("LR")                        /* Test SP register */            /*   Note: SP ignores writes to the lower two bits,                        so they are intentionally set to 0 */                                   /* Save SP to R0 */                       "    MOV   R0, SP              nt"                         /* Load SP with 0xAAAAAAA8 */            "    LDR   R1, =0xAAAAAAA8     nt"             "    MOV   SP, R1              nt"             "    CMP   SP, R1              nt"                        /* Restore SP and return failure */            "    IT    NE                  nt"             "        MOVNE SP, R0          nt"            "        BNE   __test_asm_fail nt"                        /* Load SP with 0x55555554 */            "    LDR   R1, =0x55555554     nt"             "    MOV   SP, R1              nt"            "    CMP   SP, R1              nt"            "    IT    NE                  nt"            "        MOVNE SP, R0          nt"            "        BNE   __test_asm_fail nt"            "    MOV   SP, R0              nt"                        /* Return success */            "    MOV   R0, #0              nt"             "    POP   {R1-R12, LR}        nt"            "    BX    LR                  nt"                        /* Return failure */            "__test_asm_fail:              nt"            "    MOV   R0, 0x00000001      nt"            "    POP   {R1-R12, LR}        nt"            "    BX    LR                  nt");                               /* Enable global interrupts */                    CyGlobalIntEnable;                           /* end of assembler code for PSoC 5 */      }
我注意到 CyGlobalIntDisable/CyGlobalIntEnable 也会出错:",不支持裸函数中的非 ASM 语句" 。  是否可以分别用" CPSID i nt" 和" CPSIE i nt" 来代替?
我使用的是 PSoC Creator 4.3,编译器是 ARM GCC 5.4-2016-q2-update。

回帖(1)

久醉不醒

2024-5-24 16:39:25
要将ASM集成到PSoC 5LP项目中并解决SelfTest_CPU_s.s文件中的注释问题,请按照以下步骤操作:

1. 首先,确保您已经安装了PSoC Creator IDE,这是开发PSoC 5LP项目所需的集成开发环境。

2. 创建一个新的PSoC 5LP项目或打开一个现有的项目。

3. 在PSoC Creator IDE中,导航到“Project”菜单,然后选择“New”->“File”来创建一个新的ASM文件。将SelfTest_CPU_s.s文件的内容复制到新创建的ASM文件中。

4. 解决注释问题:在ASM文件中,分号(;)通常用于单行注释。但是,从您提供的文件内容来看,分号前面有一个空格,这可能导致汇编器无法识别注释。请确保在每个注释行的开头,分号前面没有空格。例如,将以下内容:

   `;-------------------------------------------------------------------------------------------;`

   更改为:

   `;-------------------------------------------------------------------------------`

5. 保存修改后的ASM文件。

6. 在PSoC Creator IDE中,将新创建的ASM文件添加到项目中。右键单击项目名称,选择“Add Existing Item”,然后浏览并选择修改后的ASM文件。

7. 在PSoC Creator IDE中,打开项目的“Build”设置。在“Build”选项卡中,确保选中了“Include Assembler Files in Build”选项。这将确保在构建项目时包含ASM文件。

8. 现在,您可以开始将AN78175的安全软件程序库集成到您的PSoC 5LP项目中。根据AN78175文档和示例代码,将所需的库文件和函数集成到您的项目中。

9. 在集成过程中,您可能需要对SelfTest_CPU_s.s文件进行一些修改,以适应您的特定需求。确保在进行这些修改时,遵循正确的ASM语法和注释规则。

10. 构建并测试您的PSoC 5LP项目,确保所有集成的组件正常工作。

通过遵循这些步骤,您应该能够成功地将ASM集成到PSoC 5LP项目中,并解决SelfTest_CPU_s.s文件中的注释问题。
举报

更多回帖

发帖
×
20
完善资料,
赚取积分