生成工程的过程跟用STM32CubeMX是一样的,配置好后点击code generation,即可生成新的工程,生成的工程如下图所示。
网址:https://www.micrium.com/
因为我的工程是用STM32CubeIDE生成的,在新弹出网页的最下方,下载的
在该源码文件中,有一个Micrium的文件夹,里面是移植需要用到的程序源码,还有一个PDF文件,这个文件里面详细说明了移植步骤。
因为我用的是UC/OS III,所以选择的是UC/OS III的相关文件,如果是UC/OSII的话,操作时类似的,其实具体的文件路径,在上面提到的官方的PDF文件中都有详细的介绍。
增加包含文件
/* USER CODE BEGIN Includes */
#include
#include
#include
#include
#include
/* USER CODE END Includes */
相关定义
/* USER CODE BEGIN PD */
//#warning "Modify this value to match the number of external interrupts in your MCU"
#define EXT_INT_MAX_NBR 22u
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
static OS_TCB StartupTaskTCB;
static CPU_STK StartupTaskStk[APP_CFG_STARTUP_TASK_STK_SIZE];
static void StartupTask (void *p_arg);
/* USER CODE END PV */
初始化
int main(void)
{
/* USER CODE BEGIN 1 */
OS_ERR os_err;
CPU_INT16U int_id;
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
CPU_IntDis();
for (int_id = CPU_INT_EXT0; int_id <= (EXT_INT_MAX_NBR - 1u); int_id++)
{
/* Set all external intr. to KA interrupt priority boundary */
CPU_IntSrcPrioSet(int_id, CPU_CFG_KA_IPL_BOUNDARY/*, CPU_INT_KA*/);
}
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
/* USER CODE BEGIN 2 */
OSInit(&os_err);
if (os_err != OS_ERR_NONE)
{
while (1);
}
App_OS_SetAllHooks();
OSTaskCreate(&StartupTaskTCB,
"Startup Task",
StartupTask,
0u,
APP_CFG_STARTUP_TASK_PRIO,
&StartupTaskStk[0u],
StartupTaskStk[APP_CFG_STARTUP_TASK_STK_SIZE / 10u],
APP_CFG_STARTUP_TASK_STK_SIZE,
0u,
0u,
0u,
(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
&os_err);
if (os_err != OS_ERR_NONE)
{
while (1);
}
OSStart(&os_err);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
// HAL_GPIO_TogglePin(BUZZER_GPIO_Port,BUZZER_Pin);
// HAL_Delay(1000);
}
/* USER CODE END 3 */
}
重新定义HAL_InitTick() 和 HAL_GetTick()函数
HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
{
/* define as empty to prevent the system tick being initialized before
the OS starts */
return (HAL_OK);
}
uint32_t HAL_GetTick(void)
{
CPU_INT32U os_tick_ctr;
#if (OS_VERSION >= 30000u)
OS_ERR os_err;
os_tick_ctr = OSTimeGet(&os_err);
#else
os_tick_ctr = OSTimeGet();
#endif
return os_tick_ctr;
}
创建开始任务
static void StartupTask (void *p_arg)
{
CPU_INT32U cpu_clk;
OS_ERR os_err;
(void)p_arg;
cpu_clk = HAL_RCC_GetHCLKFreq();
/* Initialize and enable System Tick timer */
OS_CPU_SysTickInit(cpu_clk);
while (DEF_TRUE)
{
HAL_GPIO_TogglePin(BUZZER_GPIO_Port,BUZZER_Pin);
OSTimeDlyHMSM(0u, 0u, 0u, 200u,OS_OPT_TIME_HMSM_STRICT,&os_err);
}
}
这就改完了,我写的是一个蜂鸣器的任务,可以正常工作。