# How to Run Sample Programs

This document explains in detail how to enable, build, and run sample programs in the K230 RTOS SDK, and how to configure auto-start on boot.

## Enable Sample Programs

### Open the Configuration Menu

Run the following command from the SDK root directory (`~/rtos_k230`) to enter the interactive configuration interface:

```bash
make menuconfig
```

### Enable Compilation of Samples

The SDK has been refactored so that all sample configurations are accessed through a unified entry point:

```text
RT-Smart UserSpace Examples Configuration
```

Configure in the following order:

1. Enable the master switch first:

   ```text
   RT-Smart UserSpace Examples Configuration
   ```

   > You need to disable `CanMV Components Configuration`.

1. Then enable sub-switches by category (select as needed):

   ```text
   Enable 3rd-party examples
   Enable build peripheral examples
   Enable MPP examples
   Enable build ai examples
   Enable build integrated examples
   ```

1. If you enable a category (e.g. `Enable MPP examples`), go into its submenu to check specific samples (e.g. `sample_venc`, `sample_vdec`, etc.).

**Notes**:

- The old paths `RT-Smart Configuration > Enable build Rtsmart examples` and `MPP Configuration > Enable build MPP samples` are no longer the primary entry points for samples.
- The master sample switch depends on `!SDK_ENABLE_CANMV`. If you are using the CanMV solution, switch to the RTOS path as described in the build guide before this menu appears.

## Build Sample Programs

### Full Build (Recommended)

Run `make` from the root directory to build all enabled samples and package them into the image in one step:

```bash
make
```

### Standalone Build (For Debugging)

To build a single sample independently, go into its directory and run:

```bash
cd src/rtsmart/examples/integrated_poc  # example path
make clean && make                      # clean and rebuild
```

![make smart_ipc](https://www.kendryte.com/api/post/attachment?id=533)

**Notes**:

- ELF files produced by a standalone build must be manually copied to the board (see step 3.2).
- Ensure the corresponding category and specific sample are enabled in `RT-Smart UserSpace Examples Configuration` before building.

## Run Sample Programs

### Automatic Deployment via Image

When using `make` for a full build, RT-Smart samples are packaged into the image at `/sdcard/app/examples/` by default. After logging in to the board via serial port, run them directly:

```bash
cd /sdcard/app/examples

# Run a sample (example)
./integrated_poc/smart_ipc.elf
```

### Manual Deployment of Standalone-Built Samples

1. Copy the generated ELF file (e.g. `integrated_poc.elf`) to the board using a card reader or MTP.
1. Run it via the serial terminal:

   ```bash
   /sdcard/app/examples/integrated_poc.elf
   ```

![run smart ipc](https://www.kendryte.com/api/post/attachment?id=534)

**Serial Connection Tips**:

- Use `PuTTY` or `Minicom` to connect to the board's serial port (baud rate: `115200`).
- On Linux the serial device is usually `/dev/ttyUSB0`; on Windows it is `COMx`.

## Configure Auto-Start on Boot

### Set the Startup Command

1. In `make menuconfig`, navigate to:

   ```text
   RT-Smart Configuration > Startup command
   ```

1. `Startup command` is a runtime command string. Enter the absolute path to the sample program (e.g. `/sdcard/app/examples/integrated_poc/smart_ipc.elf`).

1. If you are configuring `Fast Boot Configuration > Fast boot file path`, you can use an absolute path or the `${SDK_*}` variables exported by `tools/mkenv.mk` (e.g. `${SDK_BUILD_IMAGES_DIR}`). **You also need to update the auto-start command, replacing the ELF path with `/bin/preload`.**

### Verify Auto-Start

After rebooting the board, the sample program will start automatically. Confirm it is working via logs or peripheral behavior.

## Frequently Asked Questions

1. **The sample is not in `/sdcard/app/examples`**
   - Check that the master switch in `RT-Smart UserSpace Examples Configuration` is enabled.
   - Check that the relevant category (e.g. MPP/AI/Integrated) and the specific sample are selected.
   - Re-run `make` and ensure there are no build errors.

1. **No output on serial port**
   - Confirm the serial cable is properly connected.
   - Check that the baud rate and terminal settings match.

Following the steps above, you can quickly master the complete workflow for running K230 RTOS SDK sample programs.
