Mutex
This chapter covers the basics of the C/C++ ZephyrRTOS RISC-V projects including creating, building, running, and debugging ZephyrRTOS RISC-V applications. The project referred to in this chapter is called Mutex. This application creates two threads that modify a shared resource while using a mutex lock for synchronization. The application can also be built and run on a QEMU emulator.
Note: To build, run and debug ZephyrRTOS applications with QEMU emulator, please install the xplor-studio-zephyr blueprint first. Please refer to Guidelines for more information.
Create a new project
The easiest way to use Zephyr RTOS is to start with one of the pre-configured demo application projects by selecting “File - New - C/C++ Project”, choose Zephyr application and Next.
Select Toolchains: RISC-V Custom Toolchains and enter the Project name Then click Next.
Enter Author then click Next
Select Zephyr Base Path then click Next:
Select target board configuration:
Select toolchain path then click Next and Finish.
Build project
The build step is the same as the quick-start project’s step. Please refer to Build project for more information.
If there is any problem related to the CMake, such as:
Please make sure that the version of CMake is 3.20 or higher.
After building successfully, you will see the messages in the Console view:
Running and Debugging project with QEMU emulator
Run project on QEMU Emulator
- Right-click on current project > Run As > RISV-C application with QEMU
The output of the application is shown in the Console view:
Debug project on QEMU Emulator
The XploR Studio offers several ways to debug applications:
- Select the Helloworld project entry in the Project Explorer then open the Debug Configuration Dialog. Doing so will enable eclipse to automatically fill out the necessary debug configuration information.
In Debug Configuration Dialog, create new one by double click on RISC-V Debugging:
On tab Debugger, choose option QEMU in Virtual Platforms. Click Apply then click Debug.
- Select the Helloworld project entry in the Project Explorer then clicking Debug As/RISC-V application with QEMU
- Right-click on current project > Debug As > RISV-C application with QEMU
After selecting Debug As RISC-V application with QEMU, the IDE changes to the debug perspective and automatically sets a breakpoint in the first line of code in the main() function.
Other functions of debugging (such as Resume, Step Into, Step Over, Step Return, Terminate, …) are the same as the quick-start project’s. Please refer to Running and Debugging project with QEMU emulator for more information.
Besides, users can see more about Mutex object:
About other ZephyrRTOS views (Thread view, … ), please refer to Zephyr OS views for more information.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.