Understanding “SystemCoreClock” variable
While building the project, we faced the issue “SystemCoreClock” undeclared (Figure 1). That is actually there in the FreeRTOSConfig.h, which you included.
Now in Figure 2, you can see SystemCoreClock, which is a symbol. If you trace this symbol, it will take you to the microcontroller-specific file, i.e., system_stm32f4xx.c (Figure 3) given by the ST.
The system_stm32f4xx.c file contains some initialization functions in order to initialize the microcontroller clock and some other microcontroller-specific features. You can find this file under the source (Figure 4).
The SystemCoreClock is initialized to 180MHz, as shown in Figure 5. We will discuss more on this later.
But the problem we are facing here is, you have to extern the SystemCoreClock variable in FreeRTOSConfig.h because that variable is defined in the system_stm32f4xx.c file. So, you have to extern the SystemCoreClock variable, which we already did, as shown in Figure 6.
Now just copy the extern statement shown in Figure 7 and paste it, as shown in Figure 8.
After that, try to rebuild the project (Figure 9).
This time there are no compiler errors, but the linker is giving some errors, as shown in Figure 10. That is an undefined reference to vApplicationTickHook and an undefined reference to vApplicationStackOverflowHook.
vApplicationTickHook and vApplicationStackOverflowHook are the hook functions of the FreeRTOS, which you need to implement in the main.c. This error can be easily solved by going into the FreeRTOSConfig.h and switching off that feature. Now let’s switch off that feature, causing an error.
In the FreeRTOSConfig.h, you will find various macros in order to configure the FreeRTOS source code.
In Figure 11, you can see various macros that start from the word config, which is actually a configurable item. configUSE_PREEMPTION is a configurable item to configure the preemption. If you make it 1, then preemption will be enabled. If you make it 0, preemption will be disabled.
Now let’s use this hook configurable items. While building, we are facing an issue that is an undefined reference to ApplicationTickHook.
Now let’s understand the meaning of this error. This error is actually telling us that please implement a function called a vApplicationTickHook in your main.c.
But our main.c is empty (Figure 12). We have not implemented any hook functions. Because we don’t need that for the HelloWorld application, so let’s make the tick hook and idle hook macro as zero, as shown in Figure 13.
After that, we are facing an issue with a stack overflow. Check for stack overflow. Its initial value is 2 (Figure 14). Now let’s change that into 0 (Figure 15).
Let’s build the project. Now the project is built successfully (Figure 16). You have successfully built a project, which consists of FreeRTOS source code.
Now you can use your main.c in order to create various threads or tasks to take the benefits of FreeRTOS services like task management, task creation, task deletion, queue management, semaphores, Mutexes, etc.
Now you can implement all these things from main.c, and you can play with the FreeRTOS source code.
In the following article, let’s see what is the task.
FastBit Embedded Brain Academy Courses
click here: https://fastbitlab.com/course1