Hello,
I'm using JN518x over DK6 board and trying to debug feature with SWO trace. It may work but it has some issues on my place.
- Issue#1: The initial linking to SWO fails so many times.
- Issue#2: Console messages is not output properly when using Newlib or NewlibNano.
The attachment is newly built from project wizard and made a small modification using SDK2_6_4.
In pin_mux.c: added PIO14 entry as SWO.
// ADDED PIO14 ENTRY AT pin_mux.c
IOCON->PIO[0][14] = ((IOCON->PIO[0][14] &
(~(IOCON_PIO_FUNC_MASK | IOCON_PIO_DIGIMODE_MASK)))
| IOCON_PIO_FUNC(PIO0_14_FUNC_ALT5)
| IOCON_PIO_DIGIMODE(PIO0_14_DIGIMODE_DIGITAL));
In clock_config.h: change clock as 3MHz (may not be necessary)
CLOCK_SetClkDiv(kCLOCK_DivTraceClk, 16U, false); /*!< Set TRACECLKDIV divider to value 1 */
In JN5189_Project3.c: SWO initial code grabbing from Serial_SwoInit() at serial_port_swo.c (to make it simple).
static bool s_SwoInit()
{
serial_port_swo_config_t swoConfig = {
.clockRate = 3000000UL,
.baudRate = 3000000UL,
.port = 1ul,
.protocol = kSerialManager_SwoProtocolNrz,
};
uint32_t prescaler = swoConfig.clockRate / swoConfig.baudRate - 1U;
/* enable the ITM and DWT units */
CoreDebug->DEMCR = CoreDebug_DEMCR_TRCENA_Msk;
if ((CoreDebug->DEMCR & CoreDebug_DEMCR_TRCENA_Msk) == 0U)
{
return false;
}
/* Lock access */
ITM->LAR = 0xC5ACCE55U;
/* Disable ITM */
ITM->TER &= ~(1U << swoConfig.port);
ITM->TCR = 0U;
/* select SWO encoding protocol */
TPI->SPPR = swoConfig.protocol;
/* select asynchronous clock prescaler */
TPI->ACPR = prescaler & 0xFFFFU;
/* allow unprivilege access */
ITM->TPR = 0U;
/* enable ITM */
ITM->TCR = ITM_TCR_ITMENA_Msk | ITM_TCR_SYNCENA_Msk
| ITM_TCR_TraceBusID_Msk
| ITM_TCR_SWOENA_Msk | ITM_TCR_DWTENA_Msk;
/* enable the port bits */
ITM->TER = swoConfig.port;
return true;
}
The code above works by the following procedure:
- start debugger with holding RESET button of JN5189.
- when the first error dialogue is shown, press [OK] button and release RESET button at the same time. (without this procedure, the linking establishment fails so frequently...)
- At [SWO Trace Config] tab, go to [Configuration] tab and press [Change] button of target clock speed and set 3MHz (as set above) and press [OK] button.
- Then go to [Status] tab and check if [probe back end] turns green. If not, linking is failed.
The first question is that it's very hard for me to establish link of SWO. The procedure 2. is too tricky. I don't think it's normal behavior but has something missed.
The second question is [SWO ITM Console] message output. Of course the SWO link is established well by seeing other screen like [SWO Interrupts].
The my sample code works as below:
- on SysTick_Handler() running at 1000Khz, it outputs '.' to USART message and ITM console every 128 ticks.
- type 'a' to output a longer message using PRINTF() call (same message to USART as well).
- type 'b' to output a longer message using _write() call (same message to USART as well).
My code does not output correct messages via PRINTF() call, but _write() works. The PRINTF is defined as printf() in the code and the printf() should call _write() in the final. However, only corrupted bytes are output. I tried using PUTCHAR(), but it's also corrupted.
The correct output is done by:
- The low level access, _write() or ITM_SendChar()
- By building with REDLIB
I guess there is something wrong at buffering part in printf() or putchar(). But no idea what is wrong.
Thanks in advance!