-
Notifications
You must be signed in to change notification settings - Fork 244
SWO Output
GrandChris edited this page Jun 16, 2020
·
13 revisions
Simple SWO ascii console, CPU running at 72MHz, SWO at 2MHz, SWO data comes from probe itself (eg. ST-LINK)
"swoConfig":{
"enabled":true,
"source":"probe",
"swoFrequency": 2000000,
"cpuFrequency":72000000,
"decoders": [
{
"port": 0,
"type": "console",
"label": "SWO output",
"encoding":"ascii"
}
]
}
This example expects CMSIS usage
Init
/* Select the SWO interface */
DBGMCU->CR &= DBGMCU_CR_TRACE_MODE_Msk;
/* Enable the TRACE interface */
DBGMCU->CR |= DBGMCU_CR_TRACE_IOEN;
Send character
ITM_SendChar(character);
Note: Don't forget to properly configure SWO pin.
"type": "cortex-debug",
"request": "attach",
"servertype": "openocd",
"cwd": "${workspaceRoot}/build",
"executable": "NucleoProject.elf",
"name": "Debug (OpenOCD)",
"device": "STM32F303",
"svdFile": "../scripts/openOCD/STM32F303.svd", // from Google search
"showDevDebugOutput": false,
"configFiles": [
"board/st_nucleo_f3.cfg" // OpenOCD board configuration (in the OpenOCD/scripts folder)
],
"swoConfig":
{
"enabled": true,
"decoders": [
{
"type": "graph",
"port": 0, // ITM (Instrumentation Trace Macrocell) stimulus port
"encoding": "unsigned",
"graphId": "1", // ID of the corresponding graph plot
"scale": 1
},
{
"type": "graph",
"port": 1, // ITM (Instrumentation Trace Macrocell) stimulus port
"encoding": "unsigned",
"graphId": "2", // ID of the corresponding graph plot
"scale": 1
},
],
"cpuFrequency": 75000000, // Configured CPU speed
"swoFrequency": 2000000, // Maximum speed of ST-Link/V2
"source": "probe",
},
"graphConfig": [
{
"label": "Graph 1",
"timespan": 5,
"type": "realtime",
"annotate": false,
"maximum": 256,
"minimum": 0,
"plots": [
{
"graphId": "1", // ID as reference for a decoder
"label": "data 1",
"color": "#53753c"
},
{
"graphId": "2", // ID as reference for a decoder
"label": "data 2",
"color": "#955f20"
}
]
},
]
},
uint8_t ITM_SendChar(uint8_t ch, size_t const port)
{
if (((ITM->TCR & ITM_TCR_ITMENA_Msk) != 0UL) && /* ITM enabled */
((ITM->TER & (port+1) ) != 0UL) ) /* ITM Port enabled */
{
while (ITM->PORT[port].u32 == 0UL)
{
__NOP();
}
ITM->PORT[port].u8 = (uint8_t)ch;
}
return (ch);
}
Note that the maximum stable data rate with ST-Link/V2 is about 8kiB/s, the implementation of the Graph however does limit the data rate even further. The graph will skip samples, if the data rate is too high.