diff --git a/V203/usb/ch32v203/startup.cpp b/V203/usb/ch32v203/startup.cpp index 1c21ff6..f7474f3 100644 --- a/V203/usb/ch32v203/startup.cpp +++ b/V203/usb/ch32v203/startup.cpp @@ -1,9 +1,9 @@ #include "system.h" typedef __SIZE_TYPE__ size_t; extern "C" { - extern void handle_reset () __attribute__((naked,nothrow,used)); - extern void user_init () __attribute__((used)); - extern int main () __attribute__((used)); + [[using gnu: naked,nothrow,used]] extern void handle_reset (); + [[gnu::used]] extern void user_init (); + [[gnu::used]] extern int main (); // This is required to allow pure virtual functions to be defined. extern void __cxa_pure_virtual() { while (1); } @@ -14,41 +14,17 @@ extern "C" { extern uint32_t _data_vma; extern uint32_t _edata; - extern void (*__preinit_array_start[]) (void) __attribute__((weak)); - extern void (*__preinit_array_end[]) (void) __attribute__((weak)); - extern void (*__init_array_start[]) (void) __attribute__((weak)); - extern void (*__init_array_end[]) (void) __attribute__((weak)); + [[gnu::weak]] extern void (*__preinit_array_start[]) (void); + [[gnu::weak]] extern void (*__preinit_array_end[]) (void); + [[gnu::weak]] extern void (*__init_array_start[]) (void); + [[gnu::weak]] extern void (*__init_array_end[]) (void); - static void __init_array () { - uint32_t * dst, * end; - - /* Zero fill the bss section */ - dst = &_sbss; - end = &_ebss; - while (dst < end) * dst++ = 0U; - /* Copy data section from flash to RAM */ - uint32_t * src; - src = &_data_lma; - dst = &_data_vma; - end = &_edata; - if (src != dst) { - while (dst < end) * dst++ = * src++; - } - - size_t count; - /* Pro Cortex-Mx bylo toto zbytečné, lze předpokládat, že je to tak i zde. - count = __preinit_array_end - __preinit_array_start; - for (unsigned i = 0; i < count; i++) __preinit_array_start[i](); - */ - count = __init_array_end - __init_array_start; - for (unsigned i = 0; i < count; i++) __init_array_start[i](); - } // If you don't override a specific handler, it will just spin forever. - void DefaultIRQHandler( void ) { + [[gnu::interrupt]] void DefaultIRQHandler( void ) { // Infinite Loop for (;;); } - void NMI_RCC_CSS_IRQHandler( void ) { + [[gnu::interrupt]] void NMI_RCC_CSS_IRQHandler( void ) { RCC.INTR.B.CSSC = RESET; // clear the clock security int flag } #define ALIAS(f) __attribute__((nothrow,weak,alias(#f),used)) @@ -255,10 +231,35 @@ R"---( : : [main]"r"(user_init)/*, [InterruptVector]"r"(InterruptVector)*/ : "t0", "memory" ); } +static void init_variables () { + uint32_t * dst, * end; + + /* Zero fill the bss section */ + dst = &_sbss; + end = &_ebss; + while (dst < end) * dst++ = 0U; + /* Copy data section from flash to RAM */ + uint32_t * src; + src = &_data_lma; + dst = &_data_vma; + end = &_edata; + if (src != dst) { + while (dst < end) * dst++ = * src++; + } +} +static void init_constructors () { + /* Pro Cortex-Mx bylo toto zbytečné, lze předpokládat, že je to tak i zde. + count = __preinit_array_end - __preinit_array_start; + for (unsigned i = 0; i < count; i++) __preinit_array_start[i](); + */ + const size_t count = __init_array_end - __init_array_start; + for (unsigned i = 0; i < count; i++) __init_array_start[i](); +} void user_init () { + init_variables(); SystemInit(); SystemCoreClockUpdate(); - __init_array(); + init_constructors(); // Konstruktory zavolat až po inicializaci hodin main (); for (;;); }