Is there a kernel AP to run before all tasks?

I initialize the hardware before creating tasks. Then I create the tasks then run the scheduler.
Is there a kernel AP to use for initializing the hardware before the scheduler started?

The Kernel knows nothing about most of the hardware. The port layer will have the basic code to setup the Timer used for the Tick, and the interrupt controller.

Some of the extras may have code for some of the I/O devices but that isn’t part of the kernel.

Thanks Richard.
So, what I am doing:
int main()
{
ConfigHardwareIO();
xTaskCreate();
vTaskStartScheduler();
}
That’s the way?

Tasks can configure the hardware they use after they start, before entering their endless loop. In some cases, it may allow a better hierarchical project organization.

1 Like

That is one way to do it. I tend to have my main be something like

int main(){
    initDevice1()
    initDevice2()
    initDevice3()
    vTaskStartScheduler()
}

where the various initDevice routines are declared in a header, and I will have one file C for device1, another one for device1, and a third for device3, and that init code will do the prescheduled hardware initialization and create any tasks/semaphors/queue needed for the code that operates that device.

The answers here are good. I’ll add one nuance: sometimes you’ll have a hardware driver that requires a delay of some sort (e.g. a relay that needs settling time).

Before the scheduler is running, you can’t use vTaskDelay(), and after it’s running, you don’t want to use delay_ms(). So you can do something like this:

void time_task_delay_ms(uint32_t ms) {
    if (xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED) {
        delay_ms(ms);
    } else {
        vTaskDelay(pdMS_TO_TICKS(ms));
    }
}