2022-02-22 09:45 PM
Hello.
Hi Forum. I am new to the H743 line of processors and the first thing I tried is getting printf() output on the traceswo pin of my nucleo-H743ZI. What I have tried:
1. The 'Everything out of the box' way:
Use cubeMX to configure sys to async trace, configure clocks, enable master clock out (to verify clock speed with a logic analyser).
Import the project to stm32cubeide and configure debugging to use the SWF, with the specific baud rate and core clock.
Write simples main loop:
while(1)
{
ITM_Sendchar('E');
HAL_Delay(2000);
}
Start a debugging session, configure trace port 0 and start tracing -> no output in atollic truestudio, no output on PB3 (verified with logic analyser)
I' m add example of Initialization file
uint32_t SystemCoreClock = 480000000;
void DebugSetup (void)
{
DBGMCU->CR |= DBGMCU_CR_DBG_CKD3EN | DBGMCU_CR_DBG_CKD1EN | DBGMCU_CR_DBG_TRACECKEN;
//UNLOCK FUNNEL
*(__IO uint32_t*)(0x5C004FB0) = 0xC5ACCE55; // SWTF_LAR
*(__IO uint32_t*)(0x5C003FB0) = 0xC5ACCE55; // SWO_LAR
//SWO current output divisor register
//This divisor value (0x000000C7) corresponds to 400Mhz
//To change it, you can use the following rule
// value = (CPU Freq/sw speed )-1
*(__IO uint32_t*)(0x5C003010) = ((SystemCoreClock / 2000000) - 1); // SWO_CODR
//SWO selected pin protocol register
*(__IO uint32_t*)(0x5C0030F0) = 0x00000002; // SWO_SPPR NRZ
//Enable ITM input of SWO trace funnel
*(__IO uint32_t*)(0x5C004000) |= 0x00000001; // SWFT_CTRL
MODIFY_REG(GPIOB->MODER, GPIO_MODER_MODE3, 0x2 << GPIO_MODER_MODE3_Pos);
MODIFY_REG(GPIOB->OSPEEDR,GPIO_OSPEEDR_OSPEED3,0x0 << GPIO_OSPEEDR_OSPEED3_Pos);
MODIFY_REG(GPIOB->PUPDR, GPIO_PUPDR_PUPD3, 0x00 << GPIO_PUPDR_PUPD3_Pos);
MODIFY_REG(GPIOB->AFR[0], GPIO_AFRL_AFSEL3, 0x0 << GPIO_AFRL_AFSEL3_Pos);
}
__STATIC_INLINE uint32_t ITM_SendChar (uint32_t ch)
{
if (((ITM->TCR & ITM_TCR_ITMENA_Msk) != 0UL) && /* ITM enabled */
((ITM->TER & 1UL ) != 0UL) )
{
while (ITM->PORT[0U].u32 == 0UL)
{
__NOP();
}
ITM->PORT[0U].u8 = (uint8_t)ch;
}
return (ch);
}
Start a debugging session, configure trace port 0 and start tracing -> no output in atollic truestudio, no output on PB3 (verified with logic analyser)
2022-02-22 09:48 PM
Are you using the ZI2 board with the ST-LINK/V3 ?
Because the SWD clock is NOT 2 MHz, and the baud rate computation vs the core will not be correct.
2022-02-22 10:10 PM
I' m using ST-LINK/V2.
CPU frequency 480 MHz.
quote: "Because the SWD clock is NOT 2 MHz, and the baud rate computation vs the core will not be correct."
I didn't understand. Can I explain in more detail ?
2022-02-22 10:31 PM
Line 13 of the posted code assumes a SWCLK of 2 MHz (2000000 Hz)
2022-02-22 10:36 PM
Is Atollic up to date? Or a the very least have drivers and DLLs for the ST-LINK that aren't too old?
The current version of STM32 Cube Programmer should have an SWV Viewer, does that work?
2022-02-22 11:23 PM
I' m check signal on pin PB3 oscilloscope. Not signal on pin PB3.
2022-02-23 12:05 AM
Read out content of registers you've written and check/post.
> if (((ITM->TCR & ITM_TCR_ITMENA_Msk) != 0UL) && /* ITM enabled */
Is ITM enabled?
JW
2022-02-23 12:38 AM
I update code:
void DebugSetup (void)
{
uint32_t SWOSpeed = 2000000;/* we have default 2 Mbps SWO speed in ST-Link SWV viewer */
uint32_t SWOPrescaler = (SystemCoreClock / SWOSpeed) - 1; /* SWOSpeed in Hz */
DBGMCU->CR |= DBGMCU_CR_DBG_CKD3EN | DBGMCU_CR_DBG_CKD1EN | DBGMCU_CR_DBG_TRACECKEN;
//UNLOCK FUNNEL
*(__IO uint32_t*)(0x5C004FB0) = 0xC5ACCE55; // SWTF_LAR
*(__IO uint32_t*)(0x5C003FB0) = 0xC5ACCE55; // SWO_LAR
//SWO current output divisor register
//This divisor value (0x000000C7) corresponds to 400Mhz
//To change it, you can use the following rule
// value = (CPU Freq/sw speed )-1
*(__IO uint32_t*)(0x5C003010) = SWOPrescaler; // SWO_CODR
//SWO selected pin protocol register
*(__IO uint32_t*)(0x5C0030F0) = 0x00000002; // SWO_SPPR NRZ
//Enable ITM input of SWO trace funnel
*(__IO uint32_t*)(0x5C004000) |= 0x00000001; // SWFT_CTRL
TPI->SPPR = 0x00000002; /* 'Selected PIN Protocol Register': Select which protocol to use for trace output (2: SWO UART NRZ, 1: SWO Manchester encoding) */
TPI->ACPR = SWOPrescaler; /* 'Async Clock Prescaler Register'. Scale the baud rate of the asynchronous output */
ITM->TCR = ITM_TCR_SWOENA_Msk | ITM_TCR_ITMENA_Msk;
ITM->TER = 0x1;
ITM->TPR = ITM_TPR_PRIVMASK_Msk; /* ITM Trace Privilege Register */
MODIFY_REG(GPIOB->MODER, GPIO_MODER_MODE3, 0x2 << GPIO_MODER_MODE3_Pos);
MODIFY_REG(GPIOB->OSPEEDR,GPIO_OSPEEDR_OSPEED3,0x0 << GPIO_OSPEEDR_OSPEED3_Pos);
MODIFY_REG(GPIOB->PUPDR, GPIO_PUPDR_PUPD3, 0x00 << GPIO_PUPDR_PUPD3_Pos);
MODIFY_REG(GPIOB->AFR[0], GPIO_AFRL_AFSEL3, 0x0 << GPIO_AFRL_AFSEL3_Pos);
}
I' m check signal on pin PB3 oscilloscope. Not signal on pin PB3.
2022-02-23 12:50 AM
Read out content of registers you've written and check/post.
JW
2022-02-23 04:39 AM
On my several Nucleo's H743, never had any issues with ITM_Sendchar and printf redirection,
besides of flaky Eclipse software.
Would advise to begin from SystemCoreClock 400 MHz and let the debugger host initialize the SWO,
Use the old good ST-LINK utility on Windows, or CubeProgrammer, Atollic, CubeIDE...
When you see the output, read the registers and compare.
Again, if you want just debug prints in CubeIDE, let it set up the ITM, you don't need to do anything in your code. Remember to click the red button in the ITM terminal to see the output (Cube IDE won't start it automatically, this was discussed here several times)