CC2538裸机项目编译但不起作用

问题描述 投票:0回答:1

我是嵌入式开发新手,目前正在尝试开发一个基于 TI CC2538SF53 微控制器的定制板项目。我的代码基于我在网上看到的一些教程以及 Contiki 的 Github 存储库中使用的代码。

我可以很好地编译和链接我的项目,但我仍然无法让我的程序在板上运行,所以我认为我一定是映射了我的内存错误或其他什么。

我使用为此编译的不同二进制文件测试了该板,它们工作得很好。我无权访问编译这些二进制文件的源代码,因此我无法将它们用作参考。

有人对这个芯片有经验吗?你能告诉我我做错了什么吗?这是我的启动文件和链接器文件:

startup.c

#include <stdint.h>
#include "eposInterrupts.h"         // Interrupt handlers are defined here

#define FLASH_START_ADDR            0x00200000  //* Flash start address *//
#define FLASH_IMAGE_VALID           0x00000000  //* Identifies that the image in flash is valid *//
#define BOOTLOADER_BACKDOOR_ENABLE  0xFFFFFFF9  //* Enables the Bootloader Backdoor on GPIOA1 *//

#define SRAM_START  0x20000000                  //* SRAM starting location *//
#define SRAM_LENGTH (16 * 1024)                 //* 16 kB *//
#define STACK_START (SRAM_START + SRAM_LENGTH)  //* Stack starts right after SRAM ends *//

#define HWREG(x) (*((volatile uint32_t *)(x)))  //* Macro for direct register access *//
#define SYS_CTRL_I_MAP  0x400D2098              //* Register that selects whether to use regular or alternate interrupt map *//
#define ALTERNATE_I_MAP 0x00000001              //* Value to write on SYS_CTRL_I_MAP to select alternate interrupt map *//

void reset_handler(void);
void default_handler(void);
extern void bootloader(void);

//*****************************************************************************
// Reserve space for the system stack.
//*****************************************************************************
__attribute__ ((section(".stack"), used))
static uint64_t stack[256];

__attribute__ ((section(".vectors"), used))
void (* const vectors[])(void) =
{
   (void (*)(void))((unsigned long)stack),                  // 0 Stack pointer
   reset_handler,                                           // 1 Reset handler
   NMI_handler,                                             // 2 The NMI handler
   hard_fault_handler,                                      // 3 The hard fault handler
   mem_manage_fault_handler,                                // 4 The MPU fault handler
   bus_fault_handler,                                       // 5 The bus fault handler
   usage_fault_handler,                                     // 6 The usage fault handler
   0,                                                       // 7 Reserved
   0,                                                       // 8 Reserved
   0,                                                       // 9 Reserved
   0,                                                       // 10 Reserved
   sv_call_handler,                                         // 11 SVCall handler
   debug_monitor_handler,                                   // 12 Debug monitor handler
   0,                                                       // 13 Reserved
   pend_sv_call_handler,                                    // 14 The PendSV handler
   systick_handler,                                         // 15 The SysTick handler
   GPIOA_handler,                                           // 16 GPIO Port A
   GPIOB_handler,                                           // 17 GPIO Port B
   GPIOC_handler,                                           // 18 GPIO Port C
   GPIOD_handler,                                           // 19 GPIO Port D
   0,                                                       // 20 none
   UART0_handler,                                           // 21 UART0 Rx and Tx
   UART1_handler,                                           // 22 UART1 Rx and Tx
   SSI0_handler,                                            // 23 SSI0 Rx and Tx
   I2C_handler,                                             // 24 I2C Master and Slave
   0,                                                       // 25 Reserved
   0,                                                       // 26 Reserved
   0,                                                       // 27 Reserved
   0,                                                       // 28 Reserved
   0,                                                       // 29 Reserved
   ADC_handler,                                             // 30 ADC Sequence 0
   0,                                                       // 31 Reserved
   0,                                                       // 32 Reserved
   0,                                                       // 33 Reserved
   watchdog_handler,                                        // 34 Watchdog timer 
   timer0A_handler,                                         // 35 Timer 0 subtimer A
   timer0B_handler,                                         // 36 Timer 0 subtimer B
   timer1A_handler,                                         // 37 Timer 1 subtimer A
   timer1B_handler,                                         // 38 Timer 1 subtimer B
   timer2A_handler,                                         // 39 Timer 2 subtimer A
   timer2B_handler,                                         // 40 Timer 2 subtimer B
   analog_comparator_handler,                               // 41 Analog Comparator 0
   RF_Core_Rx_Tx_handler,                                   // 42 RFCore Rx/Tx (Alternate)
   RF_Core_error_handler,                                   // 43 RFCore Error (Alternate)
   system_control_handler,                                  // 44 IcePick
   flash_control_handler,                                   // 45 FLASH Control
   AES_handler,                                             // 46 AES (Alternate)
   PKA_handler,                                             // 47 PKA (Alternate)
   sleep_timer_handler,                                     // 48 Sleep Timer (Alternate)
   MAC_timer_handler,                                       // 49 MacTimer (Alternate)
   SSI1_handler,                                            // 50 SSI1 Rx and Tx
   timer3A_handler,                                         // 51 Timer 3 subtimer A
   timer3B_handler,                                         // 52 Timer 3 subtimer B
   0,                                                       // 53 Reserved
   0,                                                       // 54 Reserved
   0,                                                       // 55 Reserved
   0,                                                       // 56 Reserved
   0,                                                       // 57 Reserved
   0,                                                       // 58 Reserved
   0,                                                       // 59 Reserved
   0,                                                       // 60 Reserved
   0,                                                       // 61 Reserved
   uDMA_handler,                                            // 62 uDMA
   uDMA_error_handler,                                      // 63 uDMA Error
   0,                                                       // 64 Unused
   0,                                                       // 65 Unused
   0,                                                       // 66 Unused
   0,                                                       // 67 Unused
   0,                                                       // 68 Unused
   0,                                                       // 69 Unused
   0,                                                       // 70 Unused
   0,                                                       // 71 Unused
   0,                                                       // 72 Unused
   0,                                                       // 73 Unused
   0,                                                       // 74 Unused
   0,                                                       // 75 Unused
   0,                                                       // 76 Unused
   0,                                                       // 77 Unused
   0,                                                       // 78 Unused
   0,                                                       // 79 Unused
   0,                                                       // 80 Unused
   0,                                                       // 81 Unused
   0,                                                       // 82 Unused
   0,                                                       // 83 Unused
   0,                                                       // 84 Unused
   0,                                                       // 85 Unused
   0,                                                       // 86 Unused
   0,                                                       // 87 Unused
   0,                                                       // 88 Unused
   0,                                                       // 89 Unused
   0,                                                       // 90 Unused
   0,                                                       // 91 Unused
   0,                                                       // 92 Unused
   0,                                                       // 93 Unused
   0,                                                       // 94 Unused
   0,                                                       // 95 Unused
   0,                                                       // 96 Unused
   0,                                                       // 97 Unused
   0,                                                       // 98 Unused
   0,                                                       // 99 Unused
   0,                                                       // 100 Unused
   0,                                                       // 101 Unused
   0,                                                       // 102 Unused
   0,                                                       // 103 Unused
   0,                                                       // 104 Unused
   0,                                                       // 105 Unused
   0,                                                       // 106 Unused
   0,                                                       // 107 Unused
   0,                                                       // 108 Unused
   0,                                                       // 109 Unused
   0,                                                       // 110 Unused
   0,                                                       // 111 Unused
   0,                                                       // 112 Unused
   0,                                                       // 113 Unused
   0,                                                       // 114 Unused
   0,                                                       // 115 Unused
   0,                                                       // 116 Unused
   0,                                                       // 117 Unused
   0,                                                       // 118 Unused
   0,                                                       // 119 Unused
   0,                                                       // 120 Unused
   0,                                                       // 121 Unused
   0,                                                       // 122 Unused
   0,                                                       // 123 Unused
   0,                                                       // 124 Unused
   0,                                                       // 125 Unused
   0,                                                       // 126 Unused
   0,                                                       // 127 Unused
   0,                                                       // 128 Unused
   0,                                                       // 129 Unused
   0,                                                       // 130 Unused
   0,                                                       // 131 Unused
   0,                                                       // 132 Unused
   0,                                                       // 133 Unused
   0,                                                       // 134 Unused
   0,                                                       // 135 Unused
   0,                                                       // 136 Unused
   0,                                                       // 137 Unused
   0,                                                       // 138 Unused
   0,                                                       // 139 Unused
   0,                                                       // 140 Unused
   0,                                                       // 141 Unused
   0,                                                       // 142 Unused
   0,                                                       // 143 Unused
   0,                                                       // 144 Unused
   0,                                                       // 145 Unused
   0,                                                       // 146 Unused
   0,                                                       // 147 Unused
   0,                                                       // 148 Unused
   0,                                                       // 149 Unused
   0,                                                       // 150 Unused
   0,                                                       // 151 Unused
   0,                                                       // 152 Unused
   0,                                                       // 153 Unused
   0,                                                       // 154 Unused
   0,                                                       // 155 Unused
   USB_handler,                                             // 156 USB 2538
   RF_Core_Rx_Tx_handler,                                   // 157 RFCore Rx/Tx
   RF_Core_error_handler,                                   // 158 RFCore Error
   AES_handler,                                             // 159 AES
   PKA_handler,                                             // 160 PKA
   sleep_timer_handler,                                     // 161 Sleep Timer
   MAC_timer_handler,                                       // 162 MacTimer
};

//*****************************************************************************
// Customer Configuration Area in Lock Page
//*****************************************************************************
typedef struct {
    uint32_t bootloaderCfg;     // Bootloader backdoor enabled in PA7 
  uint32_t imageValid;        // Image valid bytes
  const void* vectorAddr;     // Vector table located at flash start address
  uint8_t  pageLockBits[32];  // Unlock all flash pages and debug access
} lockPageCCA_t;

__attribute__((section(".flashcca")))
const lockPageCCA_t cca_lock_page =
{
  BOOTLOADER_BACKDOOR_ENABLE,
  FLASH_IMAGE_VALID,
  &vectors,
  {
    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF 
  }
};

extern int main(void);
extern void prepareBootloader(void);

extern uint32_t _etext;
extern uint32_t _sdata;
extern uint32_t _edata;
extern uint32_t _sbss;
extern uint32_t _ebss;

void reset_handler (void) {
    uint32_t *source;
  uint32_t *destination;

    // Copy the data segment initializers from flash to SRAM.
    source = &_etext;
    for(destination = &_sdata; destination < &_edata; ) {
        *destination++ = *source++;
    }

    // Zero fill the bss segment.

    for(destination = &_sbss; destination < &_ebss; ) {
        *destination++ = 0;
    }

   // Initialize usb interface for bootloader
   // prepareBootloader();
          
   // Call the application's entry point.
   main();

   // End here if return from main()
   while(1);
}

void default_handler(void) {
  while(1);
}

链接器.ld

MEMORY {
    FLASH(rx) : ORIGIN = 0x00200000, LENGTH = 512K - 44
    FLASH_CCA(rx) : ORIGIN = ORIGIN(FLASH) + LENGTH(FLASH), LENGTH = 44
    SRAM_NON_RETENTION(rwx) : ORIGIN =  0x20000000, LENGTH = 16K
    SRAM_RETENTION(rwx) : ORIGIN = 0x20004000, LENGTH = 16K
    STACK(rwx) : ORIGIN = 0x20008000, LENGTH = 2K
}

ENTRY(reset_handler)

SECTIONS {
    /* Section in which code is placed */
    .text : {
        _stext = .;
        *(.vectors*)
        *(.text*)
        *(.rodata*)
        _etext = .;
    } > FLASH

    /* Section in which initialized data is placed */
    .data : {
        _sdata = .;
        *(vtable)
        *(.data*)
        _edata = .;
    } > SRAM_RETENTION AT> FLASH
    
    /* Section in which uninitialized data is placed */
    .bss : {
        _sbss = .;
        *(.bss*)
        *(COMMON)
        _ebss = .;
    } > SRAM_RETENTION

    /* Program stack */
    .stack (NOLOAD) : {
        *(.stack)
    } > STACK

    /* Program heap is placed entirely on the non retention SRAM */
    _heap = ORIGIN(SRAM_NON_RETENTION);
    _eheap = ORIGIN(SRAM_NON_RETENTION) + LENGTH(SRAM_NON_RETENTION);
 
    .flashcca : { 
        *(.flashcca)
    } > FLASH_CCA   
}
c embedded bare-metal linker-scripts texas-instruments
1个回答
0
投票
  1. 您是否使用正确的编译选项进行编译(最小 -mcpu=cortex-m3 -mthubm)
  2. 检查您得到的是否是您所期望的。
  • 从 elf 中提取二进制文件(或者如果您使用调试器,则不要启动应用程序 - 简单检查闪存)
  • 检查向量表中的地址是否正确(记住它们必须是odd才能正确指示THUMB指令!!!!!,否则无法工作)
© www.soinside.com 2019 - 2024. All rights reserved.