Skip to content

Commit c9a3fca

Browse files
amergnatnashif
authored andcommitted
samples: userspace: hello_world
This sample print a hello world message through a user thread. Signed-off-by: Alexandre Mergnat <[email protected]>
1 parent e76b8e4 commit c9a3fca

File tree

5 files changed

+88
-0
lines changed

5 files changed

+88
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.13.1)
4+
5+
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
6+
project(hello_world_user)
7+
8+
target_sources(app PRIVATE src/main.c)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
.. _hello_world_user:
2+
3+
Hello World
4+
###########
5+
6+
Overview
7+
********
8+
A simple Hello World example that can be used with any supported board and
9+
prints 'Hello World from UserSpace!' to the console.
10+
This application can be built into modes:
11+
12+
* single thread
13+
* multi threading
14+
15+
Building and Running
16+
********************
17+
18+
This project outputs 'Hello World from UserSpace!' to the console.
19+
It can be built and executed on QEMU as follows:
20+
21+
.. zephyr-app-commands::
22+
:zephyr-app: samples/userspace/hello_world_user
23+
:host-os: unix
24+
:board: qemu_riscv32
25+
:goals: run
26+
:compact:
27+
28+
Sample Output
29+
=============
30+
31+
.. code-block:: console
32+
33+
Hello World from UserSpace! qemu_riscv32
34+
35+
Exit QEMU by pressing :kbd:`CTRL+A` :kbd:`x`.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CONFIG_USERSPACE=y
2+
CONFIG_APPLICATION_DEFINED_SYSCALL=y
3+
CONFIG_ASSERT=y
4+
CONFIG_LOG=y
5+
CONFIG_LOG_MINIMAL=y
6+
CONFIG_MAIN_STACK_SIZE=2560
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
sample:
2+
description: Hello World sample, the simplest userspace
3+
Zephyr application
4+
name: hello world user
5+
common:
6+
tags: introduction
7+
harness: console
8+
harness_config:
9+
type: one_line
10+
regex:
11+
- "Hello World from UserSpace! (.*)"
12+
tests:
13+
sample.helloworld:
14+
tags: introduction
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (c) 2020 BayLibre, SAS
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr.h>
8+
#include <stdio.h>
9+
#define USER_STACKSIZE 2048
10+
11+
struct k_thread user_thread;
12+
K_THREAD_STACK_DEFINE(user_stack, USER_STACKSIZE);
13+
14+
static void user_function(void *p1, void *p2, void *p3)
15+
{
16+
printf("Hello World from UserSpace! %s\n", CONFIG_BOARD);
17+
}
18+
19+
20+
void main(void)
21+
{
22+
k_thread_create(&user_thread, user_stack, USER_STACKSIZE,
23+
user_function, NULL, NULL, NULL,
24+
-1, K_USER, K_MSEC(0));
25+
}

0 commit comments

Comments
 (0)