cancel
Showing results for 
Search instead for 
Did you mean: 

stm32 evaluation board & printf in Keil uVsion5

lartigue
Associate II
Posted on August 06, 2015 at 00:25

Hi everybody,

I think i tried anything i could have in mind so i decided to start a new discussion...

Material :

- Evaluation board with stm32l152RCT6 with st-link integrated

My question is : Is anybody tried to use the debug viewer and display data streams from ITM stimulus port ?

I tried to follow some advices from many forums without success. Do you know if it is possible ? if yes, could tell me how to redirect printf to the debugger console using SWD/ITM ?

I already configured my Keil uVision :

- Core Clock

- Trace Enable

- ITM stimulus Ports

- redefine the fputc function

...

Regards,

#keil-uvision-printf-itm-swd-debu
8 REPLIES 8
Posted on August 06, 2015 at 01:15

Can't say I've tried it with uv5 but I'd imagine it works the same way as uv4

The STM32L1-DISCO board? You'd need to make sure SB101 is made so the PB3/SWO connectivity is made. You'd want to make sure the ST-LINK has the most current firmware on it, as some of the original ones will be quite old at this point. The frequency in the Trace configuration Pane for the debug must be the same as the core.

// Keil SWV Semi-Hosting - STM32L1-DISCO needs SB101 Solder Bridge made
/**************************************************************************************/
#include <
stdio.h
>
#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)
{
ITM_SendChar(ch);
return(ch);
}
int fgetc(FILE *f)
{
char ch;
ch = 1;
return((int)ch);
}
int ferror(FILE *f)
{
/* Your implementation of ferror */
return EOF;
}
void _ttywrch(int ch)
{
ITM_SendChar(ch);
}
void _sys_exit(int return_code)
{
label: goto label; /* endless loop */
}
/**************************************************************************************/

/public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/setup%20SWV%20on%20STM32F429_Discovery%20board&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F&currentviews=117

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
lartigue
Associate II
Posted on August 06, 2015 at 23:16

Good evening,

Thanks for you anwser but i didn't mentionned that SB101 and PB3 are already connected.

I also configured the Xtal and the Core Clock (inside the ''Trace'' tab) to 32MHz, value given in the ''system_stm32l1xx.c''.

My program is pretty simple, as you can see below :

/* Includes ------------------------------------------------------------------*/

#include ''stm32l1xx_conf.h''

#include ''stm32l1xx.h''

#include ''stm32l152_eval.h''

#include <stdio.h>

#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)

{

  ITM_SendChar(ch);

  return(ch);

}

 

int fgetc(FILE *f)

{

    char ch;

    ch = 1;

    return((int)ch);

}

 

int ferror(FILE *f)

{

  /* Your implementation of ferror */

  return EOF;

}

 

void _ttywrch(int ch)

{

    ITM_SendChar(ch);

}

 

void _sys_exit(int return_code)

{

label:  goto label;  /* endless loop */

}

void delay(unsigned int time);

void delay(unsigned int time) {

    for (time; time > 0; time--);

}

int main(void)

{

    while (1)

    {

        delay(5000000);

        printf(''test printf'');

    }

}

Do you have any other suggestion ?

Posted on August 07, 2015 at 02:41

If the bottom of the screen says ''Trace : No synchronization'' you have the frequency wrong.

Here a quick test with uv5 and a Nucleo L152RE, as I don't have a L1-DISCO immediately to hand.

/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Attachments/56353/l1keilswv.jpg

________________

Attachments :

l1keilswv.jpg : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0vo&d=%2Fa%2F0X0000000bfv%2FlZSEdP1DK55iTXUk6FaXneGMawlRmgwV9ZLr_RVLTag&asPdf=false
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on August 07, 2015 at 18:42

Working on an STM32L1-DISCO (STM32L152R8T6 - MB963 B), I definitely soldered SB101 manually, despite the documentation stating it being closed by default.

0690X0000060MnGQAU.gif

0690X000006033gQAA.jpg

0690X000006033lQAA.jpg

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
lartigue
Associate II
Posted on August 08, 2015 at 16:31

Hi,

Thank you for your answer but I can't make it work:

- The frequency of my stm32 is set to 32MHz, as you can see below:

0690X00000605IJQAY.png

I also have the xtal value set to 32MHz:

0690X00000605IOQAY.png

Debug and trace tabs  are as follows :

0690X00000605J7QAI.png

0690X00000605CMQAY.png

At this point, I'm afraid I don't know where else to look.

Posted on August 09, 2015 at 00:34

The Xtal setting in Keil does nothing useful.

If the clocks don't start properly it won't start the PLL either. SystemCoreClock is only going to be valid if everything starts properly. You could uncheck ''Run to main()'' and walk over this code to be sure it's running as expected.

If the HSE is supplied via the MCO pin of the ST-LINK, then you need to configure the HSE in BYPASS mode.

Suggest you just remove the call to SystemInit in startup_stm32l1xx.s, then the processor will start, and remain, on it's 2.1 MHz clock. Set the trace clock to that.

If you still don't have the SWV working you need to look very closely at how the SWO/PB3 is connected, and that it appears to be functioning.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
lartigue
Associate II
Posted on August 11, 2015 at 22:32

Thank you for your help and your kindness.

I just removed the call to systemInit in startupxxxxxx.s and configured the trace on it's 2.1 MHz and it's working very well.

I will try to understand what's going on during the systemInit and if I can't find what is the problem i will get back to you (or maybe you have already have an idea ? :)).

Thank you again.

Posted on August 11, 2015 at 23:01

I'd conjecture that you don't have the X3 crystal fitted and SB17 is not made, and the code in system_stm32l1xx.c is selecting an HSE source that isn't there and doesn't start.

With SB17 made you'd have an 8 MHz source coming from the ST-LINK, and you could select HSE BYPASS mode to use that clock, and drive the PLL at 32 MHz.

0690X000006030dQAA.jpg

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