cancel
Showing results for 
Search instead for 
Did you mean: 

Keil Rtx5 rtos timing issue

EMutt
Associate II

Hello. I am learning rtos and using led blink example. Here is my code: Main:

#include "RTE_Components.h"	
#include "cmsis_os2.h"
#include "stm32f4xx_rcc.h"              // Keil::Device:StdPeriph Drivers:RCC
#include "STM32F4XX.h"
#include "Threads.h"
 
#ifdef RTE_Compiler_EventRecorder
#include "EventRecorder.h"
#endif
 
void app_main (void *argument) {
 
  for (;;) {
		Thread1_Sus();
	}
}
 
struct message {
	uint8_t start;
	uint8_t function;
	uint8_t data1;
	uint8_t data2;
	uint8_t checksum;
};
 
int main (void) {
	
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
	GPIO_InitTypeDef GPIO_LED;
	
	GPIO_LED.GPIO_Pin	= GPIO_Pin_15 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14;
	GPIO_LED.GPIO_Mode= GPIO_Mode_OUT;
	GPIO_LED.GPIO_Speed	= GPIO_Speed_50MHz;
	GPIO_LED.GPIO_OType	= GPIO_OType_PP;
	
	GPIO_Init(GPIOD , &GPIO_LED);
	
  // System Initialization
  SystemCoreClockUpdate();
#ifdef RTE_Compiler_EventRecorder
  // Initialize and start Event Recorder
  EventRecorderInitialize(EventRecordError, 1U);
#endif
  // ...
 
  osKernelInitialize();                 // Initialize CMSIS-RTOS
  osThreadNew(app_main, NULL, NULL);    // Create application main thread
	Init_Thread1();
	Init_Thread2();
	Init_Thread3();
	Init_Thread4();
  osKernelStart();                      // Start thread execution
  for (;;) {}
}

thread1.c:

#include "Threads.h"
 
osThreadId_t tid_Thread1;
 
int Init_Thread1 (void) {
 
  tid_Thread1 = osThreadNew (Thread1, NULL, NULL);
  if (!tid_Thread1) return(-1);
  
  return(0);
}
 
void Thread1_Sus(void)
{
	osThreadSuspend (tid_Thread1);
}
 
void Thread1_Res(void)
{
	osThreadResume (tid_Thread1);
}
 
void Thread1 (void *argument) {
 
  while (1) {
    GPIO_ToggleBits(GPIOD , GPIO_Pin_15);
		osDelay (1000);
    osThreadYield ();                                         // suspend thread
  }
}

Thread 2 , 3 , 4 are identical to thread1 only leds and durations are different.

My issue is , I use "osKernelGetTickFreq" and it returns "1000" (and the value of "osDelay" is "1000" as well ) but still the duration of the led on my board is close to 3 seconds. What can this be cauesed by and how can i fix it ?

1 REPLY 1
EMutt
Associate II

My HSE_VALUE was wrong , after i corrected it the problem was gone.