我试图在Eclipse上实现一个小的freeRTOS项目,使用gnuarmeclipse和openstm32插件以及STM32F411RE核板。当主要功能内部使用GPIO设置和复位功能时,项目正在构建并且LED连接到PORT A引脚5闪烁。但是在使用线程时,它不起作用。我在这里添加代码。 感谢您宝贵的时间。
#include "stm32f4xx.h"
#include "cmsis_os.h"
#include "stdio.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
static void StartThread(void const * argument);
static void SecondThread(void const * argument);
static void GPIO_Init2(void);
void Delay2(int);
#ifdef __GNUC__
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
int main(void)
{
GPIO_Init2();
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
osThreadDef(USER_Thread1, StartThread, osPriorityNormal, 0, configMINIMAL_STACK_SIZE);
osThreadDef(USER_Thread2, SecondThread, osPriorityNormal, 0, configMINIMAL_STACK_SIZE);
osThreadCreate (osThread(USER_Thread1), NULL);
osThreadCreate (osThread(USER_Thread2), NULL);
/* Start scheduler */
osKernelStart();
while (1){
}
}
void Delay2(int nCount)
{
while(nCount--){
int a=5000;
while(a--){
}
}
}
void GPIO_Init2(void)
{
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA ,ENABLE);
GPIO_InitTypeDef GPIO_InitDef;
GPIO_InitDef.GPIO_Pin = GPIO_Pin_5;
GPIO_InitDef.GPIO_Mode=GPIO_Mode_OUT;
GPIO_InitDef.GPIO_OType=GPIO_OType_PP;
GPIO_InitDef.GPIO_PuPd=GPIO_PuPd_NOPULL;
GPIO_InitDef.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitDef);
GPIO_SetBits(GPIOA,GPIO_Pin_5);
osDelay(50);
GPIO_ResetBits(GPIOA,GPIO_Pin_5);
osDelay(100);
}
/* USER CODE BEGIN 4 */
/* USER CODE END 4 */
/* StartDefaultTask function */
static void StartThread(void const * argument)
{
while(1) {
GPIO_SetBits(GPIOA,GPIO_Pin_5);
osDelay(500);
GPIO_ResetBits(GPIOA,GPIO_Pin_5);
osDelay(100);
}
}
static void SecondThread(void const * argument)
{
while(1) {
}
}
#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
答案 0 :(得分:0)
您无法在osDelay()
函数中使用GPIO_Init2()
,因为调度程序尚未启动(osKernelStart()
)。