Quantcast
Channel: MSP low-power microcontrollers
Viewing all articles
Browse latest Browse all 66738

Forum Post: RE: MSP430 irq handlers and vectors with gcc

$
0
0
This is a minimal program that is executed directly from the reset vector and replaces the normal startup code. Compile with something like: msp430-gcc -Os -mmcu=msp430... -nostartfiles-o minimal minimal.c #include // defined by the linker script extern char __stack; __attribute__((naked)) static void my_program(void) { // no stack yet; cannot have local variables _set_SP_register(&__stack); WDTCTL = WDTPW | WDTHOLD; P1DIR |= BIT0; for (;;) P1OUT ^= BIT0; } __attribute__((section(".resetvec"), used)) static void (*reset_vector)(void) = my_program; "Minimal" means that it does not even initialize global variables. This could be done with code like this (some sections are not used on all architectures, or might be empty), after setting SP: extern char __bssstart, __bsssize; extern char __high_bssstart, __high_bsssize; extern char __datastart, __romdatastart, __romdatacopysize; extern int __upper_data_init; extern char __high_datastart, __rom_highdatastart, __rom_highdatacopysize; ... // initialize .bss memset(&__bssstart, 0, (uintptr_t)&__bsssize); // initialize .upper.bss memset(&__high_bssstart, 0, (uintptr_t)&__high_bsssize); // initialize .data memmove(&__datastart, &__romdatastart, (uintptr_t)&__romdatacopysize); // initialize .upper.data if (&__rom_highdatacopysize != 0) { if (__upper_data_init == 0) { __upper_data_init = 1; memmove(&__rom_highdatastart, &__high_datastart, (uintptr_t)&__rom_highdatacopysize); } else { memmove(&__highdatastart, &__rom_highdatastart, (uintptr_t)&__rom_highdatacopysize); } } This still uses the original .resetvec section. To make the interrupt vectors an array, I've put the following into the file vec.ld (this is for the F2013; others have more entries): MEMORY { ALLVECTORS : ORIGIN = 0xFFE0, LENGTH = 0x0020 } SECTIONS { __interrupt_vectors : { KEEP (*(__interrupt_vectors )) } > ALLVECTORS } And the vectors are put into that section (this replaces the reset_vector pointer in the first program): static void __attribute((interrupt)) some_interrupt(void) { ... } __attribute__((section("__interrupt_vectors"), used)) static void (*vectors[16])(void) = { 0, // unused 0, // unused some_interrupt, // P1 0, // P2 0, // USI 0, // ADC10/SD16_A 0, // unused 0, // unused 0, // Timer_A2 0, // Timer_A2 CCR0 0, // WDT+ 0, // Comp_A+ 0, // unused 0, // unused 0, // NMI my_program // reset }; Compile with something like: msp430-gcc -Os -mmcu= msp430f2013 -nostartfiles -Xlinker "-Tvec.ld" -o whatever whatever.c

Viewing all articles
Browse latest Browse all 66738

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>