Skip to content

Commit

Permalink
zephyr: hello world: update for codespaces
Browse files Browse the repository at this point in the history
Replace instructions and mentions KASM with those of Codespaces

Signed-off-by: Mike Szczys <[email protected]>
  • Loading branch information
szczys committed Jan 5, 2024
1 parent e148e47 commit 07af1e7
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 39 deletions.
2 changes: 1 addition & 1 deletion website/docs/zephyr-training/02_helloworld/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ description: |
In this module we will build, flash, and run our first Zephyr App. Along the way
you will learn:

* Familiarity with the Kasm build container used throughout this training
* Familiarity with the Codespaces build container used throughout this training
* How to build a Zephyr application using the `west` meta tool
* How to add an in-tree library (Logging) to a project
* How to use `menuconfig` to adjust Kconfig symbols
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
59 changes: 37 additions & 22 deletions website/docs/zephyr-training/02_helloworld/compile-hello-world.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
sidebar_position: 2
description:
Get familiar with VS Code, Kasm, and `west`
Get familiar with VS Code, Codespaces, and `west`
---

import HowToDownload from '/docs/\_partials/download-from-codespaces.md'
Expand All @@ -21,8 +21,8 @@ Now is a great time to get comfortable with the workflow.

* **Desired outcome(s)**
1. Understand how to use the `west` metatool to build an application
2. Learn the process of downloading a compiled binary from the Kasm build
environment used in this training
2. Learn the process of downloading a compiled binary from the Codespaces
build environment used in this training
3. Know how to use Nordic's graphical programmer and serial terminal tools
* **Time Estimate:** 15 minutes

Expand All @@ -40,26 +40,41 @@ mouse, we will build/flash from the command line to get comfortable with how the

:::

### Build in the Kasm container
### Build in the Codespaces container

1. In the Kasm container, open the `zephyr-training` project in VS Code
1. Create your codespace for Golioth's zephyr-training repository

* use the icon on the desktop to open VS Code
* Choose File&rarr;Open Folder
* Navigate to `~/Desktop/zephyr-training/` and open it
* Confirm that you trust the authors in the window that appears
* [Use this direct](https://codespaces.new/golioth/zephyr-training) link to
open our prebuilt Codespaces image for this training.

![Open the zephyr-training folder in VS Code](./assets/kasm-vscode-open-folder-trust.jpg)
![Create new codespace](./assets/codespaces-create-new.png)

* Leave all settings at their defaults and click "Create codespace".
* Give it a few seconds to finish loading.

[![VS Code running in a codespace](./assets/codespaces-vscode-first-open.png)](./assets/codespaces-vscode-first-open.png)

:::note We expect VS Code to complain a little bit

* Use the 'x' to dismiss the two dialogs on the bottom right
* There will be a message about failing to parse `compile_commands.json`
because that file will not exist until we build an app in this workspace.

:::

2. Open main.c and start the VS Code terminal

* In the VS Code Explore, click on `app` to unfold it
* Unfold the `02_helloworld` and `src` folders
* Double click on `main.c` to open it in the editor
* Open a terminal by right-clicking on `app` and selecting `Open in
Integrated Terminal`
* In the bottom pane, click "TERMINAL". We start in the `workspace` folder
so be sure to move into the `app` folder:

```
cd app
```
![Opening VS Code terminal in the app folder](./assets/kasm-vscode-open-terminal.jpg)
[![VS Code ready to compile Hello World](./assets/codespaces_vscode_ready_to_build.png)](./assets/codespaces_vscode_ready_to_build.png)
3. Build the example
Expand All @@ -69,16 +84,16 @@ mouse, we will build/flash from the command line to get comfortable with how the
`~/Desktop/zephyr-training/app` folder. The build process will create a
`build` subfolder inside any folder where the `west build` command is used.
This contains all prepocessor and compiler output (including our firmware
binary which will be locate at `build/zephyr/zephyr.hex`).
binary which will be locate at either `build/zephyr/zephyr.hex` or
`build/zephyr/merged.hex` depending on the board you are using).
Running all builds from the same location helps reduce the risk of human
error when looking at or copying from the wrong build folder.
:::
* The terminal at the bottom of the VS Code window will open in the `app`
folder
* Run the following code to build the `02_helloworld` app
* Run the following code in the VS Code terminal pane to build the
`02_helloworld` app
```bash
# for nRF7002
Expand All @@ -88,21 +103,21 @@ mouse, we will build/flash from the command line to get comfortable with how the
west build -b nrf9160dk_nrf9160_ns 02_helloworld
```
![Build command for Hello World](./assets/kasm-vscode-prebuild-hello-world.jpg)
![Build command for Hello World](./assets/codespaces-vscode-prebuild-hello-world.png)
* Upon successful build you will see device resource usage information
* Upon a successful build you will see device resource usage information
![Build Hello World](./assets/kasm-vscode-build-hello-world.jpg)
![Build Hello World](./assets/codespaces-vscode-build-hello-world.png)
4. Download the binary
<HowToDownload/>
:::tip `west kasm download` is a custom command
:::tip `west download` is a custom command
The `west` metatool allows you to add custom commands called
[Extensions](https://docs.zephyrproject.org/latest/develop/west/extensions.html).
We added this command in the repository to make downloading from Kasm
We added this command in the repository to make downloading from Codespaces
easier. You can see how this was accomplished in the
`zephyr-training/utility/west-commands` folder.
Expand Down
21 changes: 13 additions & 8 deletions website/docs/zephyr-training/02_helloworld/convert_to_logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ void main(void)

</details>

### Build in the Kasm container
### Build in the Codespaces container

1. Build the example

Expand All @@ -278,7 +278,11 @@ void main(void)
* Build app

```bash
# for nRF7002
west build -b nrf7002dk_nrf5340_cpuapp 02_helloworld

# for nRF9160
west build -b nrf9160dk_nrf9160_ns 02_helloworld
```

2. Download the binary
Expand All @@ -287,21 +291,22 @@ void main(void)

The normal workflow when using a development environment installed locally
is to use `west flash` to program the board. We are using a different
approach here because the Kasm container doesn't have access to your local
USB port.
approach here because the Codespaces container doesn't have access to your
local USB port.
:::
* In the VS Code terminal, run `west kasm download` to package the compiled
code and make it available for download
* In the VS Code terminal, run `west download` to package the compiled code
and make it available for download
* Use the Download option in Kasm's left sidebar to download
`<devicename>_<appfolder>_<hhmmss>.hex` to your local machine.
* Unfold the Download folder in VS Codes file explorer. Right-click on the
`<devicename>_<appfolder>_<hhmmss>.hex` firmware file you just build and
select "Download..." to download it to your local machine.
:::caution
Verify the filename you're downloading matches the one output by the `west
kasm download` command.
download` command.

:::

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ then you have already installed these tools. Please move on to the next page.

## Why Do I Need These Tools?

Our live Zephyr training uses a Kasm container to host the build environment. The
good news is that the tools will already be set up for you. The bad news is that
Zephyr's `west flash` command that is commonly used to program devices is not
available because of USB sharing issues between the browser-based Kasm and your
computer.
Our live Zephyr training uses a Codespaces container to host the build
environment. The good news is that the tools will already be set up for you. The
bad news is that Zephyr's `west flash` command that is commonly used to program
devices is not available because of USB sharing issues between the browser-based
Codespaces and your computer.

The solution to this issue is to download your compiled application binary from
the Kasm container, and flash it to the device using Nordic's desktop tools on
your local machine.
the Codespaces container, and flash it to the device using Nordic's desktop
tools on your local machine.

## Installation

Expand All @@ -40,6 +40,6 @@ On your local machine, follow these installation instructions:

<InstallNrfConnect/>

### Install the nRF Connect for Destkop Serial App
### Install the nRF Connect for Desktop Serial App

<UseNrfConnectSerial/>

0 comments on commit 07af1e7

Please sign in to comment.