# neuralSPOT-X

neuralSPOT-X (NSX) is Ambiq's module system for bare-metal firmware on Apollo SoCs. An NSX module is a directory with an `nsx-module.yaml` description and CMake files; an NSX application lists its modules in `nsx.yml`, and the `nsx` command-line tool vendors them into the application's `modules/` directory and builds them with the board's compiler flags. heliaDSP is the module `helia-dsp`, described by [`nsx/nsx-module.yaml`](https://github.com/AmbiqAI/helia-dsp/blob/4a7b7f054eafd96ae50c12050ad3ef3ec1ebaea1/nsx/nsx-module.yaml) and entered through `nsx/CMakeLists.txt`. Applications link the CMake target `nsx::helia_dsp`.

Placeholders on this page:

- `<helia-dsp>`: an absolute path to a heliaDSP checkout with its submodule (see [Direct CMake](https://ambiqai.github.io/helia-dsp/getting-started/cmake/), step 1).
- `<app>`: the application directory.

## What the module does for the build

- It links the board's flags target, `NSX_BOARD_FLAGS_TARGET`, and the CMSIS-Core target `nsx::cmsis_core` into the CMSIS-DSP library as public usage requirements. The library and every target that links it compile with one CPU, FPU and float-ABI configuration; a mismatch would otherwise fail at link time with `uses VFP register arguments` or `conflicting CPU architectures`.
- On boards whose CPU has Helium, the vector extension of the Cortex-M55 (Apollo510 and other Apollo5 parts), it builds CMSIS-DSP's handwritten Helium kernels. `-DAUTOVECTORIZE=ON` selects the portable C kernels instead, and changes the biquad and FIR contracts (see [Contracts](https://ambiqai.github.io/helia-dsp/guide/contracts/)).
- It applies heliaDSP's compiler policy: GCC below 15 defaults to `DISABLEFLOAT16=ON` (see [Toolchains](https://ambiqai.github.io/helia-dsp/guide/toolchains/)).
- It verifies that the CMSIS-DSP source is the qualified CMSIS-DSP commit, as in a direct CMake build.

`nsx/CMakeLists.txt` stops if the board has not defined its flags target:

```text
Board must define NSX_BOARD_FLAGS_TARGET before helia-dsp is added.
```

## Add heliaDSP 2.0.0 to an application

The NSX registry records which heliaDSP revision `nsx module add helia-dsp` fetches and where its metadata file is. Until the registry lists `v2.0.0` with the metadata path `nsx/nsx-module.yaml`, register a local checkout for the application. The steps below were run with `nsx` 0.7.17, `arm-none-eabi-gcc` 14.2.1 and the board `apollo510_evb`.

Create an application, if you do not have one:

```sh
nsx create-app <app> --board apollo510_evb
cd <app>
```

Register the checkout and add the module:

```sh
nsx module register helia-dsp \
  --metadata <helia-dsp>/nsx/nsx-module.yaml \
  --project helia-dsp \
  --project-local-path <helia-dsp> \
  --override
nsx module add helia-dsp
```

Each command prints `Added 'helia-dsp' -> main`. `nsx.yml` then lists `- name: helia-dsp` under `modules:`, and `modules/helia-dsp/third_party/CMSIS-DSP/` holds the files of the qualified CMSIS-DSP commit. `--override` is needed because the packaged registry already has an entry named `helia-dsp`.

In the application's `CMakeLists.txt`, link the target:

```cmake
target_link_libraries(<app-target> PRIVATE
    nsx::board_apollo510_evb
    nsx::runtime_core
    nsx::helia_dsp
)
```

Include `arm_math.h` in the application source and call CMSIS-DSP functions. For example, a 256-point forward real FFT:

```c
#include "arm_math.h"

#define N 256
static float32_t x[N], X[N];

void spectrum(void)
{
    arm_rfft_fast_instance_f32 S;
    arm_rfft_fast_init_256_f32(&S);   /* links the 256-point tables only */
    arm_rfft_fast_f32(&S, x, X, 0);   /* x is overwritten */
}
```

Build:

```sh
nsx build
```

The build compiles CMSIS-DSP from source and ends with the size table of the image, for example:

```text
   text	   data	    bss	    dec	    hex	filename
  27080	    368	 507536	 534984	  829c8	.../<app>/build/apollo510_evb/<app>
```

To confirm that the image uses the Helium FFT kernels:

```sh
arm-none-eabi-nm build/apollo510_evb/<app> | grep _mve
```

Expected: lines ending in `_arm_radix4_butterfly_f32_mve` and `_arm_radix4_butterfly_inverse_f32_mve`.

The example above was built and inspected; it was not flashed or run on the board. Execution of CMSIS-DSP on the Apollo510 EVB is described in [Verification](https://ambiqai.github.io/helia-dsp/guide/verification/).

## One CMSIS-DSP library per image

Every NSX module that needs CMSIS-DSP should link `nsx::helia_dsp` instead of adding its own copy; the image then contains one `libCMSISDSP.a`, compiled with the board's flags, and every module sees the same header-affecting definitions. heliaDSP detects a second provider only when it is a CMake target named `CMSISDSP` (the checks are listed in [Direct CMake](https://ambiqai.github.io/helia-dsp/getting-started/cmake/#a-second-cmsis-dsp-library)). A prebuilt CMSIS-DSP archive placed on the link line by other means, for example from a copied SDK example, is not detected; the linker then takes each `arm_*` symbol from whichever archive it searches first.

`nsx-physiokit` v0.1.0 links `nsx::helia_dsp` and initializes its biquad filter with `arm_biquad_cascade_df1_init_f32`. In a Helium build that initializer gives incorrect output (see [Contracts](https://ambiqai.github.io/helia-dsp/guide/contracts/#biquad-cascade-direct-form-i-f32)); a change to physiokit that supplies the storage the Helium initializer needs is drafted and not released.

## Supported SoCs and toolchains

`nsx/nsx-module.yaml` lists eleven SoCs from Apollo2 to Atomiq110 and the toolchains `arm-none-eabi-gcc`, `armclang` and `atfe`. These are declarations of source compatibility. Execution evidence for 2.0.0 is from the Apollo510 EVB and the Corstone-300 simulator ([`COMPATIBILITY.md`](https://github.com/AmbiqAI/helia-dsp/blob/4a7b7f054eafd96ae50c12050ad3ef3ec1ebaea1/COMPATIBILITY.md)); Armclang was not run for this version.

## Next

- [Contracts](https://ambiqai.github.io/helia-dsp/guide/contracts/)
- [Toolchains](https://ambiqai.github.io/helia-dsp/guide/toolchains/)
- [Verification](https://ambiqai.github.io/helia-dsp/guide/verification/)
