Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a (not so) basic users guide #89

Merged
merged 26 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ All notable changes to this project will be documented in this file.
This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log...

## [unreleased][unreleased]
- Added initial version of the user guides (@GameTec-live)
- Added support for pasting several command lines at once with prompt_toolkit (@doegox)
- Added support for interrupting sleep sequence with a button press during animation (@doegox)
- Fixed logs corruption and app reset on FDS write, added logs flush on sleep (@doegox)
- Added support for long-press of buttons (@nemanjan00)
- Changed `hw slot delete`, now it can always delete from slot. (@augustozanellato)
- Refactor CI pipeline. (@augustozanellato)
- Added offline copy EM card uid for btnpress.(@nemanjan00)
- Added offline copy ic card uid for btnpress.(@xianglin1998)
- Added `hw settings btnpress` to get and set button press function.(@xianglin1998)
- Changed `hw slot delete`, now it can always delete from slot (@augustozanellato)
- Refactor CI pipeline (@augustozanellato)
- Added offline copy EM card uid for btnpress (@nemanjan00)
- Added offline copy ic card uid for btnpress (@xianglin1998)
- Added `hw settings btnpress` to get and set button press function (@xianglin1998)
- Added `hw battery` to get battery informartion (@xianglin1998)
- Added `hw slot delete` to delete HF or LF out of a HF+LF slot (@augustozanellato)
- Changed CLI prompt autocompletion, saved history and internal cmd registration (@szymex73)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Anywhere else: [Sneaktechnology][go_to_buy_sneaktechnology] / [Aliexpress by RRG
# How to use ?

- ChameleonUltra: [Technical White Paper][tech_white_paper] (Old content of this readme in here)
- ChameleonUltra: [Firmware][how_use_firmware]
- ChameleonUltra: [Firmware][./docs/development.md]

More Coming Soon.

Expand Down
Empty file added docs/chameleonultragui.md
Empty file.
131 changes: 131 additions & 0 deletions docs/cli.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# CLI

The CLI (**C**ommand **L**ine **I**nterface) is the official way to control your Chameleon.

## Installing

There are multiple ways to install the CLI, depending on your OS.

### Windows

Windows users have the choice of 4 options:

#### ProxSpace

Using ProxSpace to build the CLI is the easiest and most comfortable way to get started.

1. Download ProxSpace from the [official GitHub](https://github.com/Gator96100/ProxSpace/releases/latest)

2. [Download 7zip](https://www.7-zip.org/) to extract the archive

3. Install 7zip by double clicking the Installer and clicking `Install`

4. Right-click on the downloaded archive and select `7zip -> Unpack to "ProxSpace"`

5. Open a terminal in the proxspace folder. If you are on a new Windows install, you should be able to just right-click and select `Open in Terminal`. If that option is not visible and the ProxSpace folder is still in your downloads folder, press `win+r` and type `powershell` followed by enter. In Powershell now type `cd ~/Downloads/ProxSpace`

6. Run the command `.\runme64.bat`. After successful completion, you should be dropped to the `pm3 ~ $` shell.

7. Clone the Repository by typing `git clone https://github.com/RfidResearchGroup/ChameleonUltra.git`

8. Now go into the newly created folder with `cd ChameleonUltra/software/src`

9. Prepare for package installation with `pacman-key --init; pacman-key --populate`

10. Proceed by installing Ninja with `pacman -S ninja --noconfirm`

11. Build the required config by running `cmake .`

12. And the binaries with `cmake --build .`

13. Copy the binaries by running `cp -r ~/ChameleonUltra/software/bin/* ~/ChameleonUltra/software/script/`

14. Go into the script folder with `cd ~/ChameleonUltra/software/script/`

15. Install python requirements with `pip install -r requirements.txt`

16. Finally run the CLI with `python chameleon_cli_main.py`

To use after installing, just do the following:

1. Run `runme64.bat`

2. Go into the script folder with `cd ~/ChameleonUltra/software/script/`

3. Run the CLI with `python chameleon_cli_main.py`

#### WSL2

Coming Soon

#### WSL1

Coming Soon

#### Build Natively

Building natively is a bit more advanced and not recommended for beginners

1. Download and install [Visual Studio Community](https://visualstudio.microsoft.com/de/downloads/)

2. On the workload selection screen, choose the `Desktop development with C++` workload. Click `Download and Install`

3. Download and install [git](https://git-scm.com/download). When asked, add to your path

4. Download and install [cmake](https://cmake.org/download/). Again, when asked, add to your path

5. Download and install [python](https://www.python.org/downloads/). When asked, add to your path (small checkbox in the bottom left)

6. Choose a suitable location and open a terminal. Clone the repository with `git clone https://github.com/RfidResearchGroup/ChameleonUltra.git`

7. Change into the binaries folder with `cd ChameleonUltra/software/src`

8. Build the required config by running `cmake .`

9. And the binaries with `cmake --build .`

10. Copy the binaries by running `cp -r ../bin/Debug/* ../script/`

11. Go into the script folder with `cd ../script/`

12. Create a python virtual environment with `python -m venv venv`

13. Activate it by running `.\venv\Scripts\Activate.ps1`

14. Install python requirements with `pip install -r requirements.txt`

15. Finally run the CLI with `python chameleon_cli_main.py`

To run again after installing, just do the following:

1. Activate venv by running `.\venv\Scripts\Activate.ps1`

2. Run the CLI with `python chameleon_cli_main.py`

### Linux

*Coming Soon*

### MacOS

*Coming Soon*

## Usage

When in the CLI, plug in your Chameleon and connect with `hw connect`. If autodetection fails, get the Serial Port used by your Chameleon and run `hw connect -p COM11` (Replace `COM11` with your serial port, on Linux it may be `/dev/ttyACM0`)

### Common activities

- Change slot: hw slot change -s [1-8]

*More examples coming soon*

### Available Commands

In `()` is the argument description, `[]` are possible entries for that argument (eg `[1-8]`)

| Command | Arguments | Description |
|:----------------:|:-------------------------------------------------------------------------:|:-----------------------------------------:|
| `hw factory_reset` | `--i-know-what-im-doing` (Make sure you really want to wipe your Chameleon) | Returns the Chameleon to factory settings |
| | | |
| | | |
71 changes: 48 additions & 23 deletions How_to_use_Firmware.md → docs/development.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# How to use the Firmware
# Development

In this file you can look up how to [install requirements](#Prerequisites-for-compiling), [edit](#Editing-the-code), [compile](#Compiling-the-code) and [debug](#Debugging-the-code) the code!
In this file you can look up how to [install requirements](#Prerequisites-for-compiling), [edit](#Editing-the-code), [compile](#Compiling-the-code) and [debug](#Debugging-the-code) the firmware!

## Prerequisites for compiling

Expand All @@ -25,7 +25,7 @@ Moreover it does not contain the `gdb` debugger.
* **Windows using Chocolatey:**
* Open a PowerShell terminal with administrator privileges.
* If not yet installed, run the following command to install Chocolatey:
``` Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) ```
``` Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) ```
* In the same PowerShell terminal, run the following command to install Make using Chocolatey: `choco install make`
* **macOS:**
* Open a terminal.
Expand All @@ -35,34 +35,35 @@ Moreover it does not contain the `gdb` debugger.
### install nRF tools

- Install nRF Util tool [nrfutil](https://www.nordicsemi.com/Products/Development-tools/nrf-util)
- Move it to a known path like `C:\nrfutil\` or `/usr/local/bin/`
- Add this path to the `PATH` Environment Variable if not yet there.
- Move it to a known path like `C:\nrfutil\` or `/usr/local/bin/`
- Add this path to the `PATH` Environment Variable if not yet there.
- Install nRF Util packages:
- `nrfutil install completion device nrf5sdk-tools trace`
- `nrfutil install completion device nrf5sdk-tools trace`
- Install [nRF Command Line Tools](https://www.nordicsemi.com/Products/Development-tools/nrf-command-line-tools/download) to get `nrfjprog`, `mergehex` etc.

### install programmer tools

Depending on the hardware programmer you want to use, additional tools are needed.

- If you are using a J-Link:
- Install [Segger J-Link Software](https://www.segger.com/downloads/jlink)
- alternatively, you can use openocd as described below
- Note: a JLink OB (or a STLink reflashed as a JLink OB) will not work on a nRF.

- Install [Segger J-Link Software](https://www.segger.com/downloads/jlink)
- alternatively, you can use openocd as described below
- Note: a JLink OB (or a STLink reflashed as a JLink OB) will not work on a nRF.

- If you are using a ST-Link V2:
- Install [openocd](https://openocd.org/pages/getting-openocd.html)
- If under Windows, install [ST-Link drivers](https://www.st.com/en/development-tools/stsw-link009.html), extract the zip and run `dpinst_amd64.exe`


- Install [openocd](https://openocd.org/pages/getting-openocd.html)
- If under Windows, install [ST-Link drivers](https://www.st.com/en/development-tools/stsw-link009.html), extract the zip and run `dpinst_amd64.exe`

### configure the project

- Edit `Makefile.defs`:
- Change `GNU_INSTALL_ROOT` (path of previously installed Compiler `bin` folder)
- Change `GNU_VERSION` (Version of the installed Compiler) (FIXME: is it really used?)
- Change the other paths to match your system if needed
- Don't forget to remove the `#` in front of the changed lines
- Alternatively, if you are committing often code, it may be easier to leave `Makefile.defs` intact and to invoke `make` with the desired variables from a script, e.g. `make GNU_INSTALL_ROOT=../../../arm-gnu-toolchain-12.2.rel1-x86_64-arm-none-eabi/bin/`
- Edit `Makefile.defs`:
- Change `GNU_INSTALL_ROOT` (path of previously installed Compiler `bin` folder)
- Change `GNU_VERSION` (Version of the installed Compiler) (FIXME: is it really used?)
- Change the other paths to match your system if needed
- Don't forget to remove the `#` in front of the changed lines
- Alternatively, if you are committing often code, it may be easier to leave `Makefile.defs` intact and to invoke `make` with the desired variables from a script, e.g. `make GNU_INSTALL_ROOT=../../../arm-gnu-toolchain-12.2.rel1-x86_64-arm-none-eabi/bin/`

## Editing the code

Expand All @@ -74,18 +75,19 @@ install it!
the [C++ Extension Pack](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools-extension-pack) in
VS-Code.
- Create a new IntelliSense Configuration:
- press F1 in VS-Code and enter `C/C++: Edit Configurations (UI)`
- Add a new Configuration and name it
- Specify your Compiler path (path of previously installed Compiler `bin` folder)
- Change IntelliSense mode to `gcc-arm (legacy)`
- Add include path `${workspaceFolder}/**`
- press F1 in VS-Code and enter `C/C++: Edit Configurations (UI)`
- Add a new Configuration and name it
- Specify your Compiler path (path of previously installed Compiler `bin` folder)
- Change IntelliSense mode to `gcc-arm (legacy)`
- Add include path `${workspaceFolder}/**`

## Compiling the code

- Install prerequisites (for instructions have a look at [Prerequisites for compiling](#Prerequisites-for-compiling))
- Run `build.sh` or try to execute its steps manually if your platform is not yet properly supported. Feedback is always welcome.

The script produces several images in `objects`.

* `fullimage.hex` to be used with a programmer over the SWD pins
* `dfu-app.zip` and `dfu-full.zip` to be used with DFU mode

Expand All @@ -94,6 +96,7 @@ The script produces several images in `objects`.
If the bootloader and the SoftDevice are already properly installed on the Chameleon, you can reflash it directly over DFU.

To set the device in DFU mode:

* you can use the Python client and issue the command `hw dfu`
* you can use the script `resource/tools/enter_dfu.py` that does exactly the same but may be easier to call from your scripts
* you can unplug the device, wait for it to sleep, then press the button B and plug it. If the application is bogus, this is the only way.
Expand All @@ -115,6 +118,7 @@ Under Linux you can use the scripts `flash-dfu-app.sh` and `flash-dfu-full.sh`,
Connect pins GND, SWC (swclk) and SWD (swdio) to your programmer.

With a JLink and `nrfjprog`

```
# application only:
nrfjprog -f nrf52 --program objects/application.hex --sectorerase --verify --reset
Expand All @@ -123,6 +127,7 @@ nrfjprog -f nrf52 --program objects/fullimage.hex --sectorerase --verify --reset
```

With a JLink and `openocd`

```
# application only:
openocd -f interface/jlink.cfg -f target/nrf52.cfg -c "program objects/application.hex verify reset ; shutdown"
Expand All @@ -144,6 +149,7 @@ openocd -f interface/stlink.cfg -f target/nrf52.cfg -c "program objects/fullimag
If you are adventurous it is possible to flash the device over BLE (DFU mode).

To put the device in DFU mode

* you can use the Python client and issue the command `hw dfu` **TODO:** this will be possible only when the client will be able to work over BLE...
* you can use the script `resource/tools/enter_dfu_over_ble.py`

Expand Down Expand Up @@ -208,10 +214,12 @@ Then use the official [nRF Device Firmware Update](https://www.nordicsemi.com/Pr
## Debugging the code with gdb and openocd

See first if you can execute `arm-none-eabi-gdb` from the installed tools.

* gcc-arm-none-eabi-10.3-2021.10 gdb requires `libncurses5`
* arm-gnu-toolchain-12.2.rel1 gdb requires Python 3.8

In case Python 3.8 is not available anymore on your distro, to install a local copy you can do

```
wget https://www.python.org/ftp/python/3.8.17/Python-3.8.17.tgz
tar zxvf Python-3.8.17.tgz
Expand All @@ -223,23 +231,29 @@ make install
```

Connect openocd to the device with a JLink or a ST-Link V2

```
openocd -f interface/jlink.cfg -f target/nrf52.cfg
```

```
openocd -f interface/stlink.cfg -f target/nrf52.cfg
```

Then run gdb as follows

```
PYTHONHOME=~/opt/python-3.8.17/ arm-gnu-toolchain-12.2.rel1-x86_64-arm-none-eabi/bin/arm-none-eabi-gdb
```

and tell gdb to connect to openocd

```
target extended-remote localhost:3333
```

## BlackMagicProbe with RTT support, out of a ST-Link V2

You can reflash a ST-Link V2 to use it as a BlackMagicProbe, to get support for RTT and see NRF_LOG messages.
Some clones have only 64kb, this is too short.
Even 128kb is too small when enabling RTT, but we can comment parts of the BMP source code.
Expand All @@ -248,25 +262,31 @@ Even 128kb is too small when enabling RTT, but we can comment parts of the BMP s
git clone --recursive git@github.com:blackmagic-debug/stlink-tool.git
( cd stlink-tool && make )
```

Then put the `stlink-tool` binary in your path.

Get [BMP full sources](https://github.com/blackmagic-debug/blackmagic/releases)

Comment out all probes except Nordic nrf51 in `src/target/cortexm.c` big switch for probes. It should remain

```c
switch (t->designer_code) {
case JEP106_MANUFACTURER_NORDIC:
PROBE(nrf51_probe);
break;
}
```

```
make -j PROBE_HOST=stlink ST_BOOTLOADER=1 ENABLE_RTT=1
```

Then flash the ST_Link V2

```
stlink-tool src/blackmagic.bin
```

See [src/platforms/stlink/README.md](https://github.com/blackmagic-debug/blackmagic/blob/main/src/platforms/stlink/README.md) for more details.
Unplug/plug.
Every time you plug the ST-Link, you have to run `stlink-tool` to enable BMP.
Expand All @@ -285,7 +305,9 @@ stlink-tool
sleep 1
screen /dev/ttyBmpTarg
```

In another terminal

```
$ arm-none-eabi-gdb
(gdb) target extended-remote /dev/ttyBmpGdb
Expand All @@ -305,7 +327,9 @@ cf https://embeddedexplorer.com/nrf52-nrf-log-tutorial/
```
JLinkExe -if SWD -device nrf52 -speed 4000 -autoconnect 1
```

in a second terminal:

```
JLinkRTTClient
```
Expand All @@ -318,5 +342,6 @@ UART works at 115200 bauds. E.g. one can use a FTDI dongle and `screen /dev/ttyU
Contrary to RTT that needs to be activated by a JTAG probe, UART logs are immediately available.

Limitations:

* SWO pin is shared with... SWO so when e.g. reflashing the device, garbage may appear on the monitoring terminal.
* SWO pin is also shared with the blue channel of the RGB slot LEDs, so faint blue may appear briefly when logs are sent and LED might not work properly when supposed to be blue.
Empty file added docs/faq.md
Empty file.
Loading
Loading