# Debugging SCP/LCP/RSE

## In this learning path

- [Introduction](https://learn.arm.com/learning-paths/servers-and-cloud-computing/refinfra-debug/)
- [Set up your development environment](https://learn.arm.com/learning-paths/servers-and-cloud-computing/refinfra-debug/setup-1/)
- [Debugging SCP/LCP/RSE](https://learn.arm.com/learning-paths/servers-and-cloud-computing/refinfra-debug/debugging-scp-lcp-rse-2/)
- [Debugging BL1](https://learn.arm.com/learning-paths/servers-and-cloud-computing/refinfra-debug/debugging-bl1-3/)
- [Debugging BL31](https://learn.arm.com/learning-paths/servers-and-cloud-computing/refinfra-debug/debugging-bl31-4/)
- [Debugging BL33 / UEFI](https://learn.arm.com/learning-paths/servers-and-cloud-computing/refinfra-debug/debugging-bl33-uefi-5/)
- [Next Steps](https://learn.arm.com/learning-paths/servers-and-cloud-computing/refinfra-debug/_next-steps/)

## Setting up a connection

SCP firmware debug uses the `-Og` argument. This optimizes some variables that make debugging difficult. To replace `-Og` with `-O0`, do the following:

- Navigate to `rd-infra/scp/cmake/Toolchain`.
- Modify the appropriate `<compiler>-Baremetal.cmake` file for your toolchain.

For example, change `GNU-Baremetal.cmake`:

```cmake
string(APPEND CMAKE_${language}_FLAGS_DEBUG_INIT "-Og")
```

to

```cmake
string(APPEND CMAKE_${language}_FLAGS_DEBUG_INIT "-O0")
```

After starting the model, click **New Debug Connection…** from the **Debug Control** panel.

![Figure 1. New debug connection](https://learn.arm.com/learning-paths/servers-and-cloud-computing/refinfra-debug/images/new_debug_connection.png)
<span>Figure 1. New debug connection</span>

Create a connection name. This can be whatever you prefer.

![Figure 2. Debug connection name](https://learn.arm.com/learning-paths/servers-and-cloud-computing/refinfra-debug/images/debug_connection_name.png)
<span>Figure 2. Debug connection name</span>

Next, click on **Add a new model…**.

![Figure 3. Add new model](https://learn.arm.com/learning-paths/servers-and-cloud-computing/refinfra-debug/images/add_new_model.png)
<span>Figure 3. Add new model</span>

Select the appropriate Model Interface, for example **CADI**.

Click **Browse for model running on local host**.

Select the correct model, and click **Finish**.

![Figure 4. Connect model](https://learn.arm.com/learning-paths/servers-and-cloud-computing/refinfra-debug/images/connect_model.webp)
<span>Figure 4. Connect model</span>

In the **Edit configuration and launch** panel, in the **Connection** tab, select the correct target.

For the `SCP` code, select **ARM_Cortex-M7_1**.

### Selecting the correct core

For different platforms (e.g., RD-N2, RD-V3, etc.), you will see a list of numbered M7 and M55 cores. Typically, even-numbered M7 cores correspond to the MCP, while odd-numbered cores are assigned to the SCP. Additionally:

- `ARM_Cortex-M55_0` to `ARM_Cortex-M55_(N-1)` represent LCP cores.
- `ARM_Cortex-M55_N` represents the RSE.

To verify core assignments, you can set up alerts (e.g., print statements or store variables), connect to a debugger, and test the configuration.

![Figure 5. Select target](https://learn.arm.com/learning-paths/servers-and-cloud-computing/refinfra-debug/images/select_cortexm7.png)
<span>Figure 5. Select target</span>

In the **Files** panel, select **Load Symbols from file**, **File System**, and select the **SCP RAMFW ELF** file, located at:

```plaintext
rd-infra/scp/output/rdn2/0/scp_ramfw/bin/rdn2-bl2.elf
```

RSE debug symbol file location:

```
rd-infra/tf-m/cmake_build/<plat>/<cfg>/bin/bl1_1.elf
rd-infra/tf-m/cmake_build/<plat>/<cfg>/bin/bl1_2.elf
rd-infra/tf-m/cmake_build/<plat>/<cfg>/bin/bl2.elf
```

LCP debug symbol file location:

```
rd-infra/scp/output/<plat>/<cfg>/lcp_ramfw/rdv3-lcp-bl2.elf
```

![Figure 6. Load SCP symbols](https://learn.arm.com/learning-paths/servers-and-cloud-computing/refinfra-debug/images/scp_symbols.png)
<span>Figure 6. Load SCP symbols</span>

Select **Apply** then **Debug**. The debugger now connects to the model.

## Setting breakpoints

Once connected, you can set breakpoints in the source code. This can be done by searching for the function in the **Functions** tab, double-clicking next to the line number, or in the **Command** view.

Set a breakpoint at `cmn700_discovery()`. Continue execution and the code stops at the breakpoint you specify.

```plaintext
break cmn700_discovery
continue
```

![Figure 7. cmn700_discovery() breakpoint](https://learn.arm.com/learning-paths/servers-and-cloud-computing/refinfra-debug/images/scp_breakpoint1.webp)
<span>Figure 7. cmn700_discovery() breakpoint</span>

Set another breakpoint at a debug print statement.

![Figure 8. SCP breakpoint 2](https://learn.arm.com/learning-paths/servers-and-cloud-computing/refinfra-debug/images/scp_breakpoint2.webp)
<span>Figure 8. SCP breakpoint 2</span>

Observe the output in the SCP UART window.

Disconnect from the FVP.
