cancel
Showing results for 
Search instead for 
Did you mean: 

Why is the debugging output not working on my Nucleo STM32F303K8 Board

recently
Associate II

Hello

My toolchain is CubeMx + Keil

I generated a brandnew environment using CubeMx.

I did all the steps explained at http://www.keil.com/support/man/docs/uv4/uv4_db_dbg_printf_viewer.htm

Just before the main while-loop I entered the line printf("\nstart");

compiling is error free

There is no output in the debug-window and the program seems to crash at the printf line.

Thank you for help

9 REPLIES 9

>> program seems to crash at the printf line

Does it crash or not? Should be pretty easy to see where it got too. Does it trap out of the debugger? Where is it when you press the STOP button.

The trace settings need to accurately reflect the core speed.

Make sure there is code in the project to support the retargeting.

Make sure the SWO solder bridges on the board are made.

//****************************************************************************
// Hosting of stdio functionality through SWV
//****************************************************************************
 
/* Implementation of putchar (also used by printf function to output data)    */
int SendChar(int ch)                    /* Write character to Serial Port     */
{
  ITM_SendChar(ch); // From core_cm4.c
 
  return(ch);
}
 
//****************************************************************************
 
#include <rt_misc.h>
 
#pragma import(__use_no_semihosting_swi)
 
struct __FILE { int handle; /* Add whatever you need here */ };
FILE __stdout;
FILE __stdin;
 
int fputc(int ch, FILE *f) { return (SendChar(ch)); }
 
int ferror(FILE *f)
{
  /* Your implementation of ferror */
  return EOF;
}
 
void _ttywrch(int ch) { SendChar(ch); }
 
void _sys_exit(int return_code)
{
label:  goto label;  /* endless loop */
}
 
//****************************************************************************

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
recently
Associate II

You are right, the program is not crashing.

Now I have a printf("\n%d",i++) inside the main while-loop an can set a breakpoint.

Program is stopping and continuing at this breakpoint,

but there is no output in the debug window.

In MxCube in clock_configuration I see that HCLK=8MHz

In Debug/ST-Link Debugger Settings/Trace I entered 8 MHz (overwrote 10MHz)

I entered "Trace Enable" to get ITM Stimulus Ports available

and changed Enable to 1 and Priviledge to 0 (following the Keil instructions)

I do not now what I can do with your code .. I need to think about htis

Check the solder bridges, SWO not connected, no data transits..

Perhaps add an ITM_SendChar('#'); into the loop? Try the SWV viewer in the ST-LINK Utilities?

Sorry, not using the RTE, just need the provided code to support printf() out the SWO. Not magically complicated, just hosts the board hardware, could use the VCP also.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
recently
Associate II

First I searched solder bridges in the manual: https://www.st.com/resource/en/user_manual/dm00231744.pdf

I found that sb2 and sb3 are matching ( is named "Connect VCP TX to ST-LINK" )

Unfortunaltely ... the bridges are present, I can see the both 0 Ohm resistors.

I replaced the printf with the ITM_SendChar and can step into the function.

Surprisingly I can make a breakpoint in line 8 but not in line 10. line 10 is grey ...

 if (((ITM->TCR & ITM_TCR_ITMENA_Msk) != 0UL) &&      /* ITM enabled */
      ((ITM->TER & 1UL               ) != 0UL)   )     /* ITM Port #0 enabled */
  {
    while (ITM->PORT[0U].u32 == 0UL)
    {
      __NOP();
    }
    ITM->PORT[0U].u8 = (uint8_t)ch;
  }
  return (ch);
}

The VCP would be a COM port you open in a Terminal, it's not the SWV channel "Serial Debug (printf)"

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
recently
Associate II

Ok ... them I had a view on the wrong bridges. But which bridge can be responsible for my debug-output-problem ?

"SWO not connected, no data transits.."

Reviewing the schematic

https://www.st.com/content/ccc/resource/technical/document/user_manual/e3/0e/88/05/e8/74/43/a0/DM00231744.pdf/files/DM00231744.pdf/jcr:content/translations/en.DM00231744.pdf

It is apparent that the PB3/SWO pin does not connect to the ST-LINK's SWO input. You're gonna need to wire that up, or use the USART connectivity instead, and add code to bring up the USART and retarget the IO through it.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
recently
Associate II

I need a translation ... does that mean debug-output is not possible with this little board ?

I`m confused:

I see PB3 is connected with D13 and over SB15 the green LED is connected to PB3.

If PB3 is "SWO" does this show swo-activity ?

In Figure 9 I see a not connected Pin named SWO (a red x).

What exactly can I wire up ? At one end of the wire you recommend PB3,

but what is the other end ?

Do you mean I have to solder a wire between PB3 (MCU) and PA10 (STLINK) ?

recently
Associate II

Ok, I see it clearer now. Your "apparent" matches with my "red x" .

This means that debug messages over swo are not intended with this board.

In my little world the capability of sending debug messages has such a high priority,

that I couldn`t believe this for a while :)

I will try your proposed plan B with the USART.

Thank you for your support, Clive Two.Zero

friendly regards

recently