Zephyr Hello World

Zephyr OS projects hello world examples

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 “HelloWorld.” This application prints Hello world text and runs a simple for-loop for a simple demonstration. 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.

example image

Select Toolchains: RISC-V Custom Toolchains and enter the Project name Then click Next.

example image

Enter Author then click Next

example image

Select Zephyr Base Path then click Next:

example image

Select target board configuration:

example image

example image

example image

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:

example image

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:

example image

Running and Debugging project with QEMU emulator

Run project on QEMU Emulator

  • Right-click on current project > Run As > RISV-C application with QEMU

example image

The output of the application is shown in the Console view:

example image

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.

example image

In Debug Configuration Dialog, create new one by double click on RISC-V Debugging:

example image

On tab Debugger, choose option QEMU in Virtual Platforms. Click Apply then click Debug.

example image

  • Select the Helloworld project entry in the Project Explorer then clicking Debug As/RISC-V application with QEMU

example image

  • Right-click on current project > Debug As > RISV-C application with QEMU

example image

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.

example image

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.

About ZephyrRTOS views, please refer to Zephyr OS views for more information.