Debug the remote core through CCS#
CCS provides many powerful debug tools that Linux does not have access to: pausing code, stepping through instructions, viewing internal registers, etc.
Attach CCS to the remote core#
In order to debug the program running on the remote core, we will change the instructions in the MCU+ SDK document CCS Launch, Load and Run.
Wait for Linux to be up on the A53 core before connecting to the target CPU. This ensures that the Linux RemoteProc driver has properly initialized the remote core. After you can login to the Linux terminal, then it is safe to connect CCS to the processor.
Note
After connecting CCS to the remote core, DO NOT reset the remote core! Instead, select Load > Load Symbols, and select the firmware binary that is currently running on the remote core.
You DO NOT want to reset the remote core, because if RPMsg code is running on the remote core, it will wait for Linux to re-supply the information that Linux wrote into the resource table when Linux first initialized the core. Since Linux already wrote that information once, and Linux is not aware that CCS reset the core, the remote core will hang until the entire processor is rebooted.
CCS debugging resources#
The MCU+ SDK Academy contains additional information about debugging in CCS at: “MCU+ SDK Fundamentals > Part 6: Debugging Basics”.
Please note that the MCU+ SDK Academy was written before SDK 9.1, so it will NOT include documentation about the memory configurator tool.
Example of debugging with CCS#
Let’s start by creating an infinite loop in front of System_init. That way the code will not progress into System_init until after we have attached the CCS debugger and started stepping through the code. Modify the examples/hello_world/<board>/<remote_core>/main.c file like this:
int main(void)
{
DebugP_log("Before System_init\r\n");
volatile uint32_t loop = 1;
while(loop != 0U){ ; }
/* init SOC specific modules */
System_init();
DebugP_log("After System_init\r\n");
Board_init();
DebugP_log("After Board_init\r\n");
Rebuild the MCU+ project, put the new project .out file into the Linux filesystem, and reload the project.
Now when you connect CCS to the remote core and Load Symbols, you should see the program is paused at the while() loop.
In the Variables window, select the Value of loop and change it to 0. This allows us to break out of the loop and start stepping through the code.
Use the “Step into” function to step into System_init and start stepping through the code.
We could be stepping through the code for a very long time, but once we go into function PowerClock_init > Module_clockEnable > SOC_moduleClockEnable, we can start to guess our problem. The remote core is checking the state of a module with function Sciclient_pmGetModuleState. However, I am not expecting the hello_world application to use any peripherals. Let’s look and see which peripheral is getting checked.
There is a variable named moduleId. Let’s stop and look up which module our code is making Sciclient calls for.
Open the TISCI docs, and go to the AM64x family specific documentation.
We will find the moduleID numbers on page AM64X Device Descriptions.
moduleId 146 corresponds to AM64X_DEV_UART0. When we check the Linux devicetree file, we can see that Linux is already using the main_uart0! Thus, we have a peripheral allocation conflict.
ti-linux-kernel/arch/arm64/boot/dts/ti$ grep -r --include=k3-am64* main_uart0
k3-am64-main.dtsi: main_uart0: serial@2800000 {
k3-am642-evm.dts: main_uart0_pins_default: main-uart0-pins-default {
k3-am642-evm.dts:&main_uart0 {
k3-am642-evm.dts: pinctrl-0 = <&main_uart0_pins_default>;
k3-am64.dtsi: serial2 = &main_uart0;
k3-am642-sk.dts: main_uart0_pins_default: main-uart0-pins-default {
k3-am642-sk.dts:&main_uart0 {
k3-am642-sk.dts: pinctrl-0 = <&main_uart0_pins_default>;
&main_uart0 {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&main_uart0_pins_default>;
};
If you want to keep stepping through the code to find the exact location where the remote core hangs, you can. Within ti_power_clock_config.c, the function “Module_clockSetFrequency” fails to set the clock frequency for UART0. This call fails because the Device Management core has already given Linux control of the UART0 peripheral, so it will block the remote core from modifying the UART0 settings. After the function fails, the code loops forever in _DebugP_assertNoLog:
void BOOT_SECTION _DebugP_assertNoLog(int32_t expression)
{
if(expression==0)
{
volatile uint32_t assert_loop = 1;
(void) HwiP_disable();
while(assert_loop!= 0U)
{
/* loop forver */
}
}
}
Let’s disable the UART in the hello_world project, since we will be using the Linux trace log to see the hello_world output.
Open SysConfig for the project. We can see that there is in fact a UART0 instance that was created for the debug console:
Go to the TI DRIVER PORTING LAYER > Debug Log section. Uncheck the “Enable UART Log” box. You will see the UART instance disappear from the TI DRIVERS > UART section.
Save the SysConfig changes. One final time, rebuild the MCU+ project, put the new project .out file into the Linux filesystem, and reload the project.
If everything went as expected, you should finally see the hello_world output in the trace log!
root@am64xx-evm:~# cat /sys/kernel/debug/remoteproc/remoteproc1/trace0
[unknown] 0.000000s : Before System_init
[r5f0-0] 0.000118s : After System_init
[r5f0-0] 0.000128s : After Board_init
[r5f0-0] 0.000311s : Before Drivers_open
[r5f0-0] 0.000322s : after Drivers_open
[r5f0-0] 0.000331s : Hello World!