/** * @file main.c * @brief Entry: clock update, USART banner, LED init, create tasks, start scheduler. */ #include "n32wb03x.h" #include #include "FreeRTOS.h" #include "task.h" #include "bsp_usart.h" #include "bsp_led.h" #include "app_tasks.h" #include "app_cli.h" #include "app_ble.h" #include "app_version.h" /* APP1 link base: the vector table lives at the start of the APP1 bank. * Cortex-M0 has no SCB->VTOR; this chip remaps vectors via PWR->VTOR_REG * (bit31 = enable, [30:0] = vector base). The SDK SystemInit() sets it to * 0x81000000 (bootloader region at 0x01000000), and ns_ble_stack_init() * clears it to 0 internally, so the APP must restore its own vector base * before enabling any NVIC interrupt and again after app_ble_init(). */ #define APP_VTOR_VALUE (0x80000000u | 0x01008000u) /** * @brief Main program. */ int main(void) { /* Update SystemCoreClock (configured to 64MHz HSI by SystemInit) */ SystemCoreClockUpdate(); /* Remap the vector table to this APP before any interrupt is enabled */ PWR->VTOR_REG = APP_VTOR_VALUE; /* USART1 init, print startup banner before the scheduler runs */ bsp_usart_init(); printf("\n========================================\n"); printf(" N32WB031 FreeRTOS + UART + LED demo\n"); printf(" Firmware version %s\n", APP_FW_VERSION); printf(" SystemCoreClock = %lu Hz\n", (unsigned long)SystemCoreClock); printf(" BLE enabled, advertising as \"%s\"\n", "CAIIC-MCM"); printf("========================================\n"); /* LED1(PB0) / LED2(PA6) init */ bsp_led_init(); /* BLE stack init + start advertising + create the BLE schedule task. * ns_ble_stack_init() clears PWR->VTOR_REG; restore the APP vector base. */ app_ble_init(); PWR->VTOR_REG = APP_VTOR_VALUE; /* Create log queue and tasks (LedTask, LedTask2, PrintTask) */ AppTasks_CreateAll(); /* Create the CLI task (command parsing/execution/response) */ AppCli_Init(); /* Start the FreeRTOS scheduler (port configures SysTick itself) */ vTaskStartScheduler(); /* We should never get here as control is now taken by the scheduler */ for (;;) { } }