Keil Logo Arm Logo

debug STM32F103

Next Thread | Thread List | Previous Thread Start a Thread | Settings

Details Message
Author
paul svc
Posted
7-Jul-2017 13:47 GMT
Toolset
ARM
New! debug STM32F103

Hi everyone
I'm kinda new to Keil and STM32 MCU
I managed to build very small projects but now I want to try something more complicated and I would like to use the debug, especially the debug (printf) viewer
My MCU is a STM32F103C8T6

I simply tried with the printf function but I see nothing in the debug windows.
I tried to find a tutorial for this MCU especially but I found nothing (or nothing understandable).
I just want to try to have something easy to set up in order to know what is happening.

Also, I tried to set up a timer interrupt. How I'm supposed to know if it's working well in the debug ? because apparetnly, it's not.

Thank you for your help

Author
Clive One
Posted
7-Jul-2017 17:17 GMT
Toolset
ARM
New! RE: debug STM32F103

>>I tried to find a tutorial for this MCU especially but I found nothing (or nothing understandable).

It is exactly like every other Cortex-M3 in this context.

http://www.keil.com/download/files/labst.pdf

Configure the Trace settings, making sure that the core clock matches what you're using, probably 72 MHz, and add hosting code to direct the STDIO data to the SWV/ITM unit.

http://community.st.com/message/114080?commentID=114080#comment-114081

http://community.st.com/message/140299-re-a-lot-of-embedded-pi-left-to-eat?commentID=140299#comment-140299

Author
paul svc
Posted
10-Jul-2017 08:37 GMT
Toolset
ARM
New! RE: debug STM32F103

Hi Clive,
Thank you for your help
I tried several things but without success

here is my blinky code:

#include "stm32f10x.h"
#include "stm32f10x_rcc.h"
#include "stm32f10x_gpio.h"
#include <stdio.h>

void delay(unsigned int nCount);

GPIO_InitTypeDef GPIO_InitStruct;

void ITM_SendString(char *s)
{
  while(*s)
    ITM_SendChar(*s++);
}
int main (void)
{
        // Enable clock for GPIOA
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);

        // Configure PA0 as push-pull output
        GPIO_InitStruct.GPIO_Pin = GPIO_Pin_13;
        GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
        GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
        GPIO_Init(GPIOC, &GPIO_InitStruct);
         int i;
  volatile int j;

  ITM_SendString("SWD Testing\r\n");

  printf("Hello World!\r\n");

  i = 0;
        printf("test");
        while (1)
        {
                /* Toggle LED on PA0 */
                // Reset bit will turn on LED (because the logic is interved)
                GPIO_ResetBits(GPIOC, GPIO_Pin_13);
                delay(100);
                // Set bit will turn off LED (because the logic is interved)
                GPIO_SetBits(GPIOC, GPIO_Pin_13);
                delay(100);
                ITM_SendString("0123456789 ");

    if ((i++ & 0x07) == 0x07)
      ITM_SendString("\r\n");

    for(j=0; j<10000000; j++);
                printf("test2");
        }
}

// Delay function
void delay(unsigned int nCount)
{
        unsigned int i, j;

        for (i = 0; i < nCount; i++)
                for (j = 0; j < 0x2AFF; j++);
}

//******************************************************************************
// Hosting of stdio functionality through SWV - Serial Wire Viewer
//******************************************************************************

#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 = '?';

  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 */
}

//****************************************************************************

#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *   where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t* file, uint32_t line)
{
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  /* Infinite loop */
  while (1)
  {
  }
}
#endif

//******************************************************************************

and here is my set up:
http://hpics.li/86e8799
http://hpics.li/309fc7e
http://hpics.li/7d02929

I tried with both 36 and 72Mhz core clock, and both Port 23..16, port 15..8 port 7..00 check or only port 7..0 checked

Thank you for your help
I still have the error message "no synchronization"
Did i have something wrong in my main.c ?

Author
Clive One
Posted
10-Jul-2017 15:19 GMT
Toolset
ARM
New! RE: debug STM32F103

You seem to have more items checked than necessary.

Your board/connection, which you fail to describe, must provide the PB3 SWO signal to the debugger. For the DISCO and NUCLEO boards you'd want to double check the connectivity, and if solder bridges (SB) need to be made to effect that connectivity. Read documentation for the board, or review schematic.

The internal speed of the core can be checked by emitting a clock via the PA8 MCO pin.

Author
paul svc
Posted
12-Jul-2017 13:02 GMT
Toolset
ARM
New! RE: debug STM32F103

I do use ST link v2 like this one:
https://engenhariaegambiarras.files.wordpress.com/2017/06/pic6_.jpg

st link v2 -> STM32F103
SWDIO -> PA13
GND -> GND
SWCLK -> PA14
3.3v -> 3.3

I tried to connect PB3 with SWIM but it doesn't work, same for SWDIO -> PB3

and keil config:
http://hpics.li/86c1c79
http://hpics.li/6e66788

I don't know what I'm missing here

Author
Clive One
Posted
12-Jul-2017 14:10 GMT
Toolset
ARM
New! RE: debug STM32F103

Instead of trying random stuff, think a bit. As I explained you need the SWO pin connected from the SWV functionality to work, it is the pin the TRACE data uses.

From the pod on the right
Pin 8 T_JTDO/T_SWO (PB3)

You might want to consider a real ST-LINK vs the fake/clone ones.

Author
paul svc
Posted
12-Jul-2017 14:42 GMT
Toolset
ARM
New! RE: debug STM32F103

Thank you Clive, now I get it and finally found what i wanted:
https://lujji.github.io/blog/stlink-clone-trace/

here is what I need to do

I also have a ST link with my official stm32f411RE but i'm stick to STM32f103 for now ;)

Thanks again for your help

Author
Andrew Neil
Posted
12-Jul-2017 23:40 GMT
Toolset
ARM
New! RE: ST-Link rip-offs

Note that there are at least 2 identical-looking versions of those ST-Link rip-offs, but they have different and incompatible pinouts!

So make sure you check very carefully - do not assume that any 2 will be the same, and do not assume they will match the photos in that article!

Next Thread | Thread List | Previous Thread Start a Thread | Settings

Keil logo

Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

ARM’s Privacy Policy has been updated. By continuing to use our site, you consent to ARM’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.