0
votes

I asked this question on the SCB forum but got no answer I'm trying to port some projects from uVision ide to SCB. The problems began with the implementation of vector table. For examle, I have simple C++ code

#define STACK_TOP 0x20000800
typedef void (*handler_ptr)();

void ResetHandler() { while (1); }
void NMIHandler() { while (1); }
void HardFaultHandler() { while (1); }

__attribute__ ((section("vectors"))) handler_ptr const vector_table[] = {
    (handler_ptr) STACK_TOP,
    ResetHandler,
    NMIHandler,
    HardFaultHandler,
};

This code does not compile, because SCB library looking for "int main(void)" declaration. Ok, I can add this function, but then SCB ignores my vector table implementation and use own (if I call function which address in VT, I see SCB dummy handlers).

How can i rewrite SCB VT implementation by mine? Please do not offer the use of special SC3 functions names (it's not good to support with 2 IDE's) or move vector table to another memory location.

__attribute__ ((section(".isr_vector"))) void (* const g_pfnVectors[])(void)

from Luminary Micro's "startup_gcc.c - Startup code for use with GNU tools" has no effect too

Thank you.

1

1 Answers

1
votes

When it comes to low-level C extensions for embedded support, you're unlikely to get away with a single approach for both compilers. Even the official CMSIS distribution from ARM still has separate startups for every supported compiler.

However, what might work better than the explicit table declaration is not include it. Just declare the handlers you do want to implement; the CMSIS startups usually mark their own stubs as WEAK functions, so yours will take priority. However, you need to make sure you use the standard names for handlers as expected by the linker (e.g. Reset_Handler, NMI_Handler, WWDG_IRQHandler and so on). See CMSIS docs and source files for more info.

NB: One thing to watch out for is to make sure to add the extern "C" marker if you're compiling as C++ - otherwise the linker won't see your handlers.