|
楼主 |
发表于 2015-5-2 16:41:17
|
显示全部楼层
谢谢,贴上代码,在Debug时发现
osTimerId myTimer01Handle; 为"NULL"
osTimerId myTimer02Handle; 为"NULL"
osTimerId myTimer03Handle; 正常
MDK的优化设最低,则myTimer01Handle,myTimer03Handle正常 还有myTimer02Handle为NULL
/* Includes ------------------------------------------------------------------*/
#include "stm32f1xx_hal.h"
#include "cmsis_os.h"
osTimerId myTimer01Handle;
osTimerId myTimer02Handle;
osTimerId myTimer03Handle;
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
void Callback01(void const * argument);
void Callback02(void const * argument);
void Callback03(void const * argument);
void Callback01(void const * argument)
{
HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_3);
}
void Callback02(void const * argument)
{
HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_4);
}
void Callback03(void const * argument)
{
HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_5);
}
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
osTimerDef(myTimer01, Callback01);
myTimer01Handle = osTimerCreate(osTimer(myTimer01), osTimerPeriodic, NULL);
osTimerStart(myTimer01Handle,1001);
osTimerDef(myTimer02, Callback02);
myTimer02Handle = osTimerCreate(osTimer(myTimer02), osTimerPeriodic, NULL);
osTimerStart(myTimer02Handle,501);
osTimerDef(myTimer03, Callback03);
myTimer03Handle = osTimerCreate(osTimer(myTimer03), osTimerPeriodic, NULL);
osTimerStart(myTimer03Handle,101);
osKernelStart();
while (1)
{
}
}
/** System Clock Configuration
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = 16;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI_DIV2;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL16;
HAL_RCC_OscConfig(&RCC_OscInitStruct);
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);
__HAL_RCC_AFIO_CLK_ENABLE();
}
void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
/* GPIO Ports Clock Enable */
__GPIOE_CLK_ENABLE();
__GPIOC_CLK_ENABLE();
/*Configure GPIO pin : PE5 */
GPIO_InitStruct.Pin = GPIO_PIN_5;
GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
/*Configure GPIO pins : PC3 PC4 PC5 */
GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* USER CODE END 6 */
}
#endif
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
|