kothman98 / dummy111

dummy111
0 stars 0 forks source link

Help with lpc802 flashing #2

Open kothman98 opened 3 years ago

kothman98 commented 3 years ago

@UweBonnes Hi, I need your help with trying to flash my lpc802 can you help me? I noticed a post you made in a previous issue and i was hoping you could help me out here.

make file

CC=arm-none-eabi-gcc
MACH=cortex-m0plus
CFLAGS= -c -mcpu=$(MACH) -mthumb -mfloat-abi=soft -std=gnu11 -Wall -O0
LDFLAGS= -nostdlib -mthumb -mfloat-abi=soft --specs=nano.specs -T lpc802_link.ld -Wl,-Map=final.map

all:main.o lpc802_startup.o final.elf

main.o:main.c
    $(CC) $(CFLAGS) -o $@ $^

lpc802_startup.o:lpc802_startup.c
    $(CC) $(CFLAGS) -o $@ $^

final.elf: main.o lpc802_startup.o
    $(CC) $(LDFLAGS) -o $@ $^
clean:
    rm -rf *.o *.elf *.map

load:
    openocd -d -f interface/cmsis-dap.cfg -f target/lpc8xx.cfg

startup.c file

// Create vector table first
#include<stdint.h>

#define SRAM_START  0x10000000
#define SRAM_SIZE   0x800
#define SRAM_END    ((SRAM_START) + (SRAM_SIZE))

#define STACK_START SRAM_END

extern uint32_t end_of_text;

extern uint32_t start_of_data;
extern uint32_t end_of_data;

extern uint32_t start_of_bss;
extern uint32_t end_of_bss;

int main(void);

void Reset_Handler(void);
void NMI_Handler(void);
void HardFault_Handler(void);
void SVC_Handler(void);
void PendSV_Handler(void);
void SysTick_Handler(void);
void IntDefaultHandler(void);

void SPI0_IRQHandler(void)      __attribute__((weak, alias("Default_Handler")));
void DAC0_IRQHandler(void)      __attribute__((weak, alias("Default_Handler")));
void UART0_IRQHandler(void)     __attribute__((weak, alias("Default_Handler")));
void UART1_IRQHandler(void)     __attribute__((weak, alias("Default_Handler")));
void I2C1_IRQHandler(void)      __attribute__((weak, alias("Default_Handler")));
void I2C0_IRQHandler(void)      __attribute__((weak, alias("Default_Handler")));
void MRT_IRQHandler(void)       __attribute__((weak, alias("Default_Handler")));
void CMP_IRQHandler(void)       __attribute__((weak, alias("Default_Handler")));
void WDT_IRQHandler(void)       __attribute__((weak, alias("Default_Handler")));
void BOD_IRQHandler(void)       __attribute__((weak, alias("Default_Handler")));
void FLASH_IRQHandler(void)     __attribute__((weak, alias("Default_Handler")));
void WKT_IRQHandler(void)       __attribute__((weak, alias("Default_Handler")));
void ADC_SEQA_IRQHandler(void)      __attribute__((weak, alias("Default_Handler")));
void ADC_SEQB_IRQHandler(void)      __attribute__((weak, alias("Default_Handler")));
void ADC_THCMP_IRQHandler(void)     __attribute__((weak, alias("Default_Handler")));
void ADC_OVR_IRQHandler(void)       __attribute__((weak, alias("Default_Handler")));
void CTIMER0_IRQHandler(void)       __attribute__((weak, alias("Default_Handler")));
void PININT0_IRQHandler(void)       __attribute__((weak, alias("Default_Handler")));
void PININT1_IRQHandler(void)       __attribute__((weak, alias("Default_Handler")));
void PININT2_IRQHandler(void)       __attribute__((weak, alias("Default_Handler")));
void PININT3_IRQHandler(void)       __attribute__((weak, alias("Default_Handler")));
void PININT4_IRQHandler(void)       __attribute__((weak, alias("Default_Handler")));
void PININT5_IRQHandler(void)       __attribute__((weak, alias("Default_Handler")));
void PININT6_IRQHandler(void)       __attribute__((weak, alias("Default_Handler")));
void PININT7_IRQHandler(void)       __attribute__((weak, alias("Default_Handler")));
void __valid_user_code_checksum(void)       __attribute__((weak, alias("Default_Handler")));

uint32_t vectors[] __attribute__((section(".isr_vector")))= {
    STACK_START,
    (uint32_t) Reset_Handler,
    (uint32_t) NMI_Handler,
    (uint32_t)HardFault_Handler,              // The hard fault handler
    0,                              // Reserved
    0,                              // Reserved
    0,                              // Reserved
    (uint32_t)__valid_user_code_checksum,     // LPC MCU Checksum
    0,                              // Reserved
    0,                              // Reserved
    0,                              // Reserved
    (uint32_t)SVC_Handler,                    // SVCall handler
    0,                              // Reserved
    0,                              // Reserved
    (uint32_t)PendSV_Handler,                 // The PendSV handler
    (uint32_t)SysTick_Handler,                // The SysTick handler

    // Chip Level - LPC80x
    (uint32_t)SPI0_IRQHandler,                //  0 - SPI0
    0,                              //  1 - Reserved
    (uint32_t)DAC0_IRQHandler,                //  2 - DAC0
    (uint32_t)UART0_IRQHandler,               //  3 - UART0
    (uint32_t)UART1_IRQHandler,               //  4 - UART1
    0,                              //  5 - Reserved
    0,                              //  6 - Reserved
    (uint32_t)I2C1_IRQHandler,                //  7 - I2C1
    (uint32_t)I2C0_IRQHandler,                //  8 - I2C0
    0,                              //  9 - Reserved
    (uint32_t)MRT_IRQHandler,                 // 10 - Multi-rate timer
    (uint32_t)CMP_IRQHandler,                 // 11 - Analog comparator / Cap Touch
    (uint32_t)WDT_IRQHandler,                 // 12 - Windowed watchdog timer
    (uint32_t)BOD_IRQHandler,                 // 13 - BOD
    (uint32_t)FLASH_IRQHandler,               // 14 - FLASH
    (uint32_t)WKT_IRQHandler,                 // 15 - Self wake-up timer
    (uint32_t)ADC_SEQA_IRQHandler,            // 16 - ADC seq A
    (uint32_t)ADC_SEQB_IRQHandler,            // 17 - ADC_seq B
    (uint32_t)ADC_THCMP_IRQHandler,           // 18 - ADC threshold compare
    (uint32_t)ADC_OVR_IRQHandler,             // 19 - ADC overrun
    0,                              // 20 - Reserved
    0,                              // 21 - Reserved
    0,                              // 22 - Reserved
    (uint32_t)CTIMER0_IRQHandler,             // 23 - Timer 0
    (uint32_t)PININT0_IRQHandler,             // 24 - PININT0
    (uint32_t)PININT1_IRQHandler,             // 25 - PININT1
    (uint32_t)PININT2_IRQHandler,             // 26 - PININT2
    (uint32_t)PININT3_IRQHandler,             // 27 - PININT3
    (uint32_t)PININT4_IRQHandler,             // 28 - PININT4
    (uint32_t)PININT5_IRQHandler,             // 29 - PININT5
    (uint32_t)PININT6_IRQHandler,             // 30 - PININT6
    (uint32_t)PININT7_IRQHandler              // 31 - PININT7
};

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

void NMI_Handler(void)
{ while(1) {}
}

void HardFault_Handler(void)
{ while(1) {}
}

void SVC_Handler(void)
{ while(1) {}
}

void PendSV_Handler(void)
{ while(1) {}
}

void SysTick_Handler(void)
{ while(1) {}
}
void Reset_Handler(void)
{
    //copy .data section to SRAM
    uint32_t size = (uint32_t)&end_of_data - (uint32_t)&start_of_data;

    uint8_t *pDst = (uint8_t*)&start_of_data; //sram
    uint8_t *pSrc = (uint8_t*)&end_of_text; //flash

    for(uint32_t i =0 ; i < size ; i++)
    {
        *pDst++ = *pSrc++;
    }

    //Init. the .bss section to zero in SRAM
    size = (uint32_t)&end_of_bss - (uint32_t)&start_of_bss;
    pDst = (uint8_t*)&start_of_bss;
    for(uint32_t i =0 ; i < size ; i++)
    {
        *pDst++ = 0;
    }

    main();
}

main.c

const int const_v_1 = 100;
const int const_v_2 = 100; 
int main(void){
    int x = 123;
    int y = 400; 
    x = x + y;
    for(;;);
    return 1;
}

linker file

ENTRY(Reset_Handler)

MEMORY
{
  FLASH (rx) : ORIGIN = 0x0, LENGTH = 0x3f80
  RAM (rwx) : ORIGIN = 0x10000000, LENGTH = 0x800
}

SECTIONS
{
    .text :
    {
        *(.isr_vector)
        *(.text)
        *(.rodata)
        . = ALIGN(4);
        end_of_text = .;
    }> FLASH

    .data :
    {
        start_of_data = .;
        *(.data)
        . = ALIGN(4);
        end_of_data = .;
    }> RAM AT> FLASH

    .bss :
    {
        start_of_bss = .;
        *(.bss)
        *(COMMON)
        . = ALIGN(4);
        end_of_bss = .;
    }> RAM AT> FLASH

} 
UweBonnes commented 3 years ago

You need to be much more specific if you want help. Tell exact what you did, what you expect and what you think that does not work. Use BMP hosted to get vernose printout on the console.