This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

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

Parents
  • 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 ?

Reply
  • 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 ?

Children