How to generate Proteus compatible debug files using gcc-arm-none-eabi toolchain

1.3k Views Asked by At

I am developing a new project using LPC2138, an ARM7TDMI based micro-controller. I have already developed code for this micro-controller in Keil IDE. My intention here is to experiment with ARM code development using GNU toolchain in a Linux host PC. So I am using gcc-arm-none-eabi tool chain.

I have succeeded so far in generating the executable(as well as .hex file) for ARM. This is the makefile that I have used.

CC := arm-none-eabi-gcc
LD := arm-none-eabi-ld
AS := arm-none-eabi-as
AR := arm-none-eabi-ar -cr
OBJCOPY := arm-none-eabi-objcopy

TARGET := image.hex

OBJS := startup.o $(patsubst %.c,%.o,$(wildcard *.c))

CFLAGS := -mcpu=arm7tdmi-s -g3 -Wall -I.
AS_FLAGS := -mcpu=arm7tdmi-s -g3

LD_FLAGS := -Wl,-Map,$(TARGET:%.hex=%).map -nostartfiles

LD_SCRIPT := lpc2138.ld

$(TARGET) : $(TARGET:%.hex=%)
    $(OBJCOPY) -O ihex $< $@

$(TARGET:%.hex=%) : $(OBJS)
    $(CC) -o $@ -T $(LD_SCRIPT) $(OBJS) $(LD_FLAGS)

startup.o : startup.s
    $(AS) $(AS_FLAGS) -o $@ $<

%.o : %.c
    $(CC) -c $(CFLAGS) -o $@ $<

clean :
    rm -rf $(TARGET) $(TARGET:%.hex=%) $(TARGET:%.hex=%).map *.o

My issue is that I need to debug(step by step execution) the executable in Proteus(ISIS). But Proteus supports only executables in .coff and .elf format.

I know that gcc by default generates executables in elf format. I tried to rename the executable image with .elf extension and load it in Proteus. But Proteus simulation aborted showing errors in the elf file.

I can successfully load the .hex file and run the simulation. Also I have done debugging using the executable generated by other toolchains. But debugging using GNU tool chain is standing as a hurdle in front of me.

I have written the linker script myself as shown below. Is there anything that I am missing in that?

/* Stack and heap are equal in size by default.
 *
 * A positive value for STACK_HEAP_BOUNDARY_OFFSET increase the size
 * of the stack(Decrease size of heap).
 *
 * A negetive value for STACK_HEAP_BOUNDARY_OFFSET decrease the size
 * of the stack(increase size of heap).
 */
STACK_HEAP_BOUNDARY_OFFSET = 0;
MEMORY
{
    FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 512K
    SRAM  (rw) : ORIGIN = 0x40000000, LENGTH = 32K
}

SECTIONS
{
    .text :
    {
        startup.o (.text)
        *(.text)
        . = ALIGN(4);
    } > FLASH

    .rodata :
    {
        *(.rodata)
        . = ALIGN(4);
    } > FLASH

    .data :
    {
        __data_load__ = LOADADDR (.data);
        __data_start__ = .;
        *(.data)
        . = ALIGN(4);
        __data_end__ = .;
    } > SRAM AT > FLASH

    .bss :
    {
        __bss_start__ = .;
        *(.bss)
        *(COMMON)
        . = ALIGN(4);
        __bss_end__ = .;
    } > SRAM

    .heap :
    {
        __heap_start__ = .;
        . = . + ((LENGTH(SRAM) - (. - (ORIGIN(SRAM)))) / 2);
        . += STACK_HEAP_BOUNDARY_OFFSET;
        . = ALIGN(4);
        __heap_end__ = .;
    } > SRAM

    .stack :
    {
        __stack_start__ = .;
        . = . + (LENGTH(SRAM) - (. - (ORIGIN(SRAM))));
        . = ALIGN(4);
        __stack_end__ = .;
    } > SRAM
}
0

There are 0 best solutions below