Hi !
I’m trying to use FreeRTOS on Windows.
Currently, the project is building and the main() is executing.
My problem is that once vTaskStartScheduler is invoked, It’s as if my program falls into an infinite loop: breakpoints won’t trigger and print won’t display.
You can’t make Windows system calls at high rate from multiple tasks. The official demo calls printf() every three or five seconds from one task - which you can get away with most of the time. However, if you call printf() at high rate you will create contention in Windows system calls that try to access the console. That will cause Windows to suspend a thread that FreeRTOS thinks it has complete control over and the system will crash. In your case you are calling printf() at a lower rate - but still at the (pseudo) same time from two tasks. Try replacing the printf() calls with just incrementing a variable, with each task incrementing a separate variable, pause the debugger and see if both variables are incrementing. If so, the code is running.
If you want to write to the console at a high rate then take a look at the vLoggingPrintf() function provided with the Windows demo. That sends messages to print out to a separate Windows thread that is not under the control of FreeRTOS via a simple lockless RAM buffer.
I was confused about the “official demo” you mentioned.
After some digging, I found that the demo is only part of the “FreeRTOS 202212.01” release, not the “FreeRTOS 202406.01 LTS” release I was using.
I tested the WIN32-MSVC demo with Visual Studio and it works on my machine without problem. The WIN32-MinGW also work, but I’m not a gdb pro so hard to tell.
I’m gonna study those demos to observe what would be the difference with my code.
The “FreeRTOS 202406.01 LTS” release seems to have a CMake example, wish will be useful.
I see no example of using the clang compiler with FreeRTOS. Is there a reason?
addendum:
I also noticed that the WIN32-MSVC demo produces a 32bits executable, while the WIN32-MinGW produced a x64bis exe. Is this because of a MSVC limitation?
@aggarg thanks for sharing this repo.
This looks like an updated version of the demo “FreeRTOS 202212.01” release, wich is pretty useful.
I notice that in the POSIX_GCC folder, the printf problem is solved with a mutex in console.h.
I’m not sure why in this case it doesn’t need a critical section. Maybe it’s because the POSIX_GCC backend is pthread instead of Windows native threads?
You can use clang compiler for building POSIX demo
To my understanding, this demo won’t work for clang on Windows.
I could be wrong, but to my understanding clang will use the MSVC header for compiling.
Therefore, Linux-specific headers like pthread.h.