cancel
Showing results for 
Search instead for 
Did you mean: 

how to recieve input from PC keyboard on target in a debug session

ferro
Senior III

Hi,

With Keil uVision I could type to a console and reicieve that on target with SER_GetChar ().
I implemented SER_GetChar () but the code below does not go to case 'a'.

switch ( SER_GetChar() )
{
	case 'a' :
		dbg_print ( "Pressed 'a'\n" );
		break;
	default :
		break;
}

ferro_0-1728991295369.png


What am I doing wrong ?

Any idea how to recieve input from PC keyboard on target in a debug session, to replicate uVision's functionality ?

Thank you

10 REPLIES 10

@ferro wrote:

With Keil uVision I could type to a console and receive that on target with SER_GetChar ().


You've posted this in the STM32CubeIDE section - does this mean that you're now trying to get the same thing working in CubeIDE?

You'll need to show your implementation of SER_GetChar() - see the Posting Tips for how to post source code:

 https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/ta-p/575228

Is it receiving anything at all ?

What board are you using, and how is it connected to the PC?

ferro
Senior III

@Andrew Neil, thanks for prompt reply. I use CubeIDE 1.16.1, custom board and STLink v3.

extern volatile int32_t ITM_RxBuffer;
volatile int32_t        ITM_RxBuffer = ITM_RXBUFFER_EMPTY;


int SER_GetChar (void)
{
    return ITM_ReceiveChar();
}

Breakpoint at Line 2687 is never reached.

ferro_0-1728992865287.png

 

SofLit
ST Employee

Hello @ferro ,

AFAIK, you need to retarget the "get char" to the ITM:

volatile int32_t ITM_RxBuffer=ITM_RXBUFFER_EMPTY; 

int __io_getchar(void)
{
   return ITM_ReceiveChar();
}

Inspired from this thread: 

https://community.st.com/t5/stm32-mcus-products/itm-receivechar-void-gives-undefined/td-p/538168

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

@ferro wrote:

ferro_0-1728992865287.png

 


This means that you didn't receive any character as the buffer is empty according to the if condition.

Also, look at this article. It may help.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
ferro
Senior III

Thanks @SofLit , so far no success with your __io_getchar().

https://community.st.com/t5/stm32-mcus/how-to-use-semihosting-with-stm32cubeide-and-stm32/ta-p/49742

Thanks, might try that next.

 

I remembered ITM settings in uVision - is something similar in Cube ? Is ITM in Cube set for semihosting internally ?

ferro_0-1728994740153.png

 

Clearly it is a black magic to me. I checked what ITM is - part of Cortex M debuging suite. So, is not this supported by STLink ? There is GBD, STLink, some code on target, Cube. Anything else in the chain ? Cannot be Cube in control of this chain so that console printf/read is woking smoothly ? Very confusing.

 

@Andrew Neilthanks for the links, will take some time to get through them.

"Right, so you're using the Instrumentation Trace Macrocell (ITM):"

As I said, I have no clue what I am doing. Just trying to copy what is working (ITM) on my other project (Cortex M3, Ulink, uVision, clang) where someone else got it working. It does not need to be ITM.

 

 

See this video, especially at @1:12 for ITM configuration.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

@ferro wrote:

It does not need to be ITM


A common(er?) alternative would be to use a UART instead - that was the focus of my 2nd reply.