Merge pull request #58 from ktand/call_init_first

Force init() to be called before static object allocation
This commit is contained in:
Daniel Fekete 2018-08-28 06:48:38 +02:00 committed by GitHub
commit 8d5f6722b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 7 deletions

View File

@ -31,20 +31,25 @@ void initVariant() { }
void setupUSB() __attribute__((weak));
void setupUSB() { }
// Force init to be called *first*, i.e. before static object allocation.
// Otherwise, statically allocated objects that need HAL may fail.
__attribute__(( constructor (101))) void premain() {
// Required by FreeRTOS, see http://www.freertos.org/RTOS-Cortex-M3-M4.html
#ifdef NVIC_PRIORITYGROUP_4
HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
#endif
init();
}
int main(void)
{
//Used by FreeRTOS, see http://www.freertos.org/RTOS-Cortex-M3-M4.html
#ifdef NVIC_PRIORITYGROUP_4
HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
#endif
#ifdef STM32F7
SCB_EnableICache();
SCB_EnableDCache();
#endif
init();
initVariant();
#if defined(MENU_DEBUG_DISABLED)