1 CreateTask
创建任务并开启任务调度。
void CreateTask(void)
{
osThreadDef(ledTask, LedTask, osPriorityNormal, 0, 128);
osThreadId ledTaskHandle = osThreadCreate(osThread(ledTask), NULL);
osKernelStart();
}
2 LedTask
任务函数。使用Explorer STM32F4开发板可观察到红色LED闪烁。
void LedTask(void const *arg)
{
*(unsigned int*)(RCC_BASE + 0x30) |= 1 << 5; // 开启GBIOF时钟
*(unsigned int*)(GPIOF_BASE + 0x00) = 0x01 << 18; // 输出模式
*(unsigned int*)(GPIOF_BASE + 0x04) = 0 << 9; // 推挽输出
*(unsigned int*)(GPIOF_BASE + 0x08) = 0x10 << 18; // 输出速度50MhZ
*(unsigned int*)(GPIOF_BASE + 0x0C) = 0x01 << 18; // 上拉电阻
for(;;)
{
*(unsigned int*)(GPIOF_BASE + 0x14) = 0 << 9; // 端口输出0,灯亮
osDelay(1000);
*(unsigned int*)(GPIOF_BASE + 0x14) = 1 << 9; // 端口输出1,灯灭
osDelay(1000);
}
}