All, I created a simple program to start a virtual timer object in CMSIS OS2. After succesfully creating the periodic timer, I can't start the timer. The return code is: 0xFFFFFFFD osErrorResource. I use Keil uVision5 and an NXP LPC1768 processor
Following is my code:
#include <RTE_Components.h> #include CMSIS_device_header #include <cmsis_os2.h> /* ARM::CMSIS:RTOS:Keil RTX5 */ #include "LED.h" static void Callback (void *argument); /* Function prototype Call back function */ static uint32_t timerDelay; /* Holds timer value */ /*---------------------------------------------------------------------------- * Main Entry point, execution starts here *---------------------------------------------------------------------------*/ int main (void) { osTimerId_t periodic_id; /* Thread handle */ osStatus_t status; /* Function return status */ SystemCoreClockUpdate(); /* Evaluate clock register settings and calculate current core clock */ LED_Initialize (); /* Initialize LEDs */ osKernelInitialize (); /* Initialize CMSIS-RTOS2 */ periodic_id = osTimerNew (Callback, osTimerPeriodic, (void *)5, NULL); /* Create a periodic timer, */ /* (void*)5 is passed as argument to the callback function */ if (periodic_id != NULL) { timerDelay = 1000; /* Number of Time Ticks */ status = osTimerStart (periodic_id, timerDelay); /* Start timer */ if (status != osOK) { /* Error: Timer could not be started */ status = osTimerStop (periodic_id); /* Stop timer */ } } osKernelStart(); /* Start thread execution */ } void Callback (void *argument) { int32_t arg = (int32_t)argument; /* cast back argument '5' */ LED_Flash (); }
In RTXConfig.h, I defined 5 User Threads with 'Object Specific Memory Allocation' and 2 Timer Objects (priority 'High') also with 'Object Specific Memory Allocation'. The default 'Thread Stack size' and the 'Timer Thread Stach size' both are 200 bytes.
Does anyone have an idea what might cause this error?
You probably need to start the Kernel before you try to start the timer.
Robert, thanks for responding. Regrettably, your suggestion does not solve the problem. Starting the Kernel first results in running an OS Idle Thread, concluded with an infinite loop. The code for starting the timer in Main() isn't even executed.
Well, technically it DID remove the osErrorResource problem! (HaHa)
It looks like you will need to create at least 1 thread of your own using osThreadNew() before you start the kernel; This thread should be able to start the timer. The osStartKernel() does not return if all goes well...
Robert, thanks. That worked out well. The timer now starts.