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
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 ?
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.
I do use ST link v2 like this one: engenhariaegambiarras.files.wordpress.com/.../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
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.
Thank you Clive, now I get it and finally found what i wanted: lujji.github.io/.../
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
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!