# ATS3085S BSP

This document contains instructions for advanced usage of the BSP project.

It assumes the setup documented in the main [README](./README.md).

## Core Application

The Zephyr application can be found in the `/core` directory, where the C application logic will be developed. Currently, it includes a simple "Hello World" example. Developers have the option to enable or disable the VEE by modifying the Kconfig option `CONFIG_ENABLE_VEE=y` in the prj.conf file.

Setting this option to `y` will compile and link the VEE with the main application. Conversely, if the option is not enabled, the VEE will be ignored, and the core application will operate in a fully isolated C environment.


## Build & Run Scripts

In the directory `bsp/vee/scripts/` are scripts that can be used to build and flash the BSP. The
`.bat` and `.sh` scripts are meant to run in a Windows and Linux environment respectively.

- The `build*` scripts are used to compile and link the BSP with a MicroEJ Application to produce a
  MicroEJ Firmware (`application.out`) that can be flashed on a device.

  The `build*` scripts work out of the box, assuming the toolchain is installed in the default path.
- The `run*` scripts are used to flash a MicroEJ Firmware (`application.out`) on a device.

_Note:_ Refer to the following public documentation link to get more details on this part:
- [VEE Port BSP Connection specification](https://docs.microej.com/en/latest/VEEPortingGuide/platformCreation.html#bsp-connection)
- [VEE Port Creation Training](https://docs.microej.com/en/latest/Trainings/tutorialCreatePlatformBuildAndRunScripts.html)

### Build the project

After an application build has been deployed to this BSP project (in `bsp/vee/lib`: `microejapp.o`
& `microejruntime.a`), a firmware image can be re-built after making changes in the BSP and/or VEE
port source files without requiring to rebuild the application using MICROEJ SDK 6.

To build the `bsp` project, use the IAR IDE or the MICROEJ build scripts.

**On Windows:**
```sh
./bsp/vee/scripts/build.bat
```

**On Linux / macOS:**
```sh
./bsp/vee/scripts/build.sh
```

The BSP project build is launched. Wait for the final message:
```console
Build succeeded
```

### Flash the Board 

The ATS3085S board can be flashed using the the MICROEJ run scripts:

**On Windows:**
```sh
./bsp/vee/scripts/run.bat
```

**On Linux / macOS:**
```sh
./bsp/vee/scripts/run.sh
```

The firmware is launched. Wait for the final message:

```console
Download verified successfully

MCU Reset

Software reset is performed
```

## Firmware Debugging

Firmware debugging can be done using [Ozone](https://www.segger.com/products/development-tools/ozone-j-link-debugger/) debugger platform.

1. Open **Ozone**.
2. Click on **File** then click **Open**.
3. Go in `bsp/vee/scripts` and select `actions.jdebug`.
4. Try **Attaching** or **Downloading** the program.

_Note_: You can manually change the compiler optimizations enabling KConfig options such as `CONFIG_DEBUG=y` in **prj.conf**

## Firmware Profiling

Firmware profiling can be done using SEGGER System View.
For information about System View, please visit [SEGGER website](https://www.segger.com/products/development-tools/systemview/) or [MicroEJ documentation](https://docs.microej.com/en/latest/VEEPortingGuide/systemView.html#microej-core-engine-os-task).

Follow these steps to run a System View live analysis:

* Execute `runOnDevice` gradle task. Use a J-Link probe to flash your target.
* Open System View PC application
* Go to **Target** > **Start Recording**
* Select the following Recorder Configuration:
  * J-Link Connection = **USB**
  * Target Connection = **LEOPARD**
  * Target Interface = **SWD**
  * Interface Speed (kHz) = **4000**
  * RTT Control Block Detection = **Address**
  * Find the address corresponding to the symbol **_SEGGER_RTT** in `bsp/core/outdir/ats3085s_dev_watch_ext_nor/zephyr/zephyr.map`. It should be an address as `0x3800xxxx`.
  * Enter the **_SEGGER_RTT** address.
  * Click Ok


_Markdown_  
_Copyright 2025 MicroEJ Corp. All rights reserved._  
_MicroEJ Corp. PROPRIETARY/CONFIDENTIAL. Use is subject to license terms._  