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

[WIP] Initial ITM port 0 test with stlink-trace tool #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ OpenOCD and GDB are used for development and debugging
$ ./scripts/openocd.sh &> /dev/null &
$ arm-none-eabi-gdb --command=scripts/openocd-oca-v1.cfg
```

# Instrumentation trace macrocell

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe some description about what this actually does

Use [stlink-trace -c 72](https://github.com/Open-Canalyzer/stlink-trace)
2 changes: 2 additions & 0 deletions scripts/openocd-oca-v1.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ source [find interface/stlink-v2.cfg]
#hla_serial "\x56\x3f\x67\x06\x67\x72\x56\x56\x31\x13\x06\x67"
transport select hla_swd
source [find target/stm32f3x.cfg]
itm port 0 on
tpiu config internal boem.fifo uart off 72000000
adapter_khz 4000
# use hardware reset, connect under reset
#reset_config trst_and_srst trst_pulls_srst srst_nogate connect_assert_srst
Expand Down
34 changes: 34 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@ static const CANConfig cancfg = {
};
// The loopback and silent mode fully disconnect the CAN transceiver

// Print a given string to ITM.
// This uses 8 bit writes, as that seems to be the most common way to write text
// through ITM. Otherwise there is no good way for the PC software to know what
// is text and what is some other data.
void ITM_Print(int port, const char *p)
{
if ((ITM->TCR & ITM_TCR_ITMENA_Msk) && (ITM->TER & (1UL << port)))
{
while (*p)
{
while (ITM->PORT[port].u32 == 0);
ITM->PORT[port].u8 = *p++;
}
}
}


/*
* DP resistor control is not possible on the STM32F3-Discovery, using stubs
Expand Down Expand Up @@ -149,6 +165,24 @@ int main(void) {
*/
halInit();
chSysInit();
/*
DBGMCU->CR |= DBGMCU_CR_TRACE_IOEN; // Enable IO trace pins

CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; // Enable access to registers
TPI->ACPR = 0; // Trace clock = HCLK/(x+1) = 8MHz
TPI->SPPR = 2; // Pin protocol = NRZ/USART
TPI->FFCR = 0x100; // TPIU packet framing enabled when bit 2 is set.
// You can use 0x100 if you only need DWT/ITM and not ETM.

ITM->LAR = 0xC5ACCE55;
ITM->TCR = (1 << ITM_TCR_TraceBusID_Pos) // Trace bus ID for TPIU
| (1 << ITM_TCR_SYNCENA_Pos) // Enable sync packets
| (1 << ITM_TCR_ITMENA_Pos); // Main enable for ITM
ITM->TER = 0xFFFFFFFF; // Enable all stimulus ports
//ITM->TPR = 0x0000000F; // unpriviledged
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this part commented?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ITM port is enabled from OpenOCD or stlink-trace, no need anymore to enable it from firmware. This must be removed...

while (true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kills all of the other functionality of the code. Maybe move this to a thread?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was just a showoff to see it works. Probably we should integrate it nicely :+)

ITM_Print(0, "UUUU\n");

/*
* Initializes a serial-over-USB CDC driver.
Expand Down