cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f103c6t6 arm controller printf is not working.

Sm.1
Associate III

hi im using stm32f103c6t6 arm controller printf is not working i followed steps which provided a peace of code attached. 0693W00000bhHG0QAM.png

10 REPLIES 10

Ok so Keil

You initialize the UART, pis, etc.

Does that work for outputting using the HAL_UART_Transmit() directly?​

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

yes its working fine but i need to print it using printf if i put printf its not working.

for that im enabling led in EV board if i put printf the loop is not running.

@Community member​ 

https://community.st.com/s/article/how-to-redirect-the-printf-function-to-a-uart-for-debug-messages

This example i referred which is from stm community. not worked

#include <rt_misc.h>
 
#if 0 // enable for Keil 5.xx compilers
#pragma import(__use_no_semihosting_swi)
struct __FILE { int handle; /* Add whatever you need here */ };
FILE __stdout;
FILE __stdin;
#endif

Make sure "Use MicroLIB" is checked in Target window

Use #include <stdio.h>

and above fragment

Still doesn't work, going to need to use the debugger

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

hey @Community member​  its not working same problem if i put printf in while loop the loop not executing.i pasted my code down please resolve my problem.

#include "main.h"

#include <stdio.h>

#include <rt_misc.h>

/* Private includes ----------------------------------------------------------*/

/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/

/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/

/* USER CODE BEGIN PD */

/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/

/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/

ADC_HandleTypeDef hadc1;

UART_HandleTypeDef huart2;

/* USER CODE BEGIN PV */

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/

void SystemClock_Config(void);

static void MX_GPIO_Init(void);

static void MX_USART2_UART_Init(void);

static void MX_ADC1_Init(void);

/* USER CODE BEGIN PFP */

#if 0 // enable for Keil 5.xx compilers

#pragma import(__use_no_semihosting_swi)

struct __FILE { int handle; /* Add whatever you need here */ };

FILE __stdout;

FILE __stdin;

#endif

//#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)

//PUTCHAR_PROTOTYPE

//{

// HAL_UART_Transmit(&huart2, (uint8_t *)&ch, 1, 0xffff);

// return ch;

//}

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/

/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

/**

 * @brief The application entry point.

 * @retval int

 */

int main(void)

{

 /* USER CODE BEGIN 1 */

 /* USER CODE END 1 */

 /* MCU Configuration--------------------------------------------------------*/

 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */

 HAL_Init();

 /* USER CODE BEGIN Init */

 /* USER CODE END Init */

 /* Configure the system clock */

 SystemClock_Config();

 /* USER CODE BEGIN SysInit */

 /* USER CODE END SysInit */

 /* Initialize all configured peripherals */

 MX_GPIO_Init();

 MX_USART2_UART_Init();

 MX_ADC1_Init();

 /* USER CODE BEGIN 2 */

 /* USER CODE END 2 */

 /* Infinite loop */

 /* USER CODE BEGIN WHILE */

 char a[]={"\n"};

int AD_RES=0;

float Voltage;

char AD_RES_r[1]={0};

uint8_t data[1]={0}; 

 /* Infinite loop */

 /* USER CODE BEGIN WHILE */

 while (1)

 {

  /* USER CODE END WHILE */

HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13);

HAL_Delay(100);

//HAL_UART_Transmit(&huart2,a, sizeof(a),0xffff );

   printf("hello sln\r\n");

//puts(a);

  /* USER CODE BEGIN 3 */

 }

 /* USER CODE END 3 */

}

#include "main.h"
 
#include <stdio.h>
#include <rt_misc.h>
 
ADC_HandleTypeDef hadc1;
UART_HandleTypeDef huart2;
 
void SystemClock_Config(void);
 
static void MX_GPIO_Init(void);
static void MX_USART2_UART_Init(void);
static void MX_ADC1_Init(void);
 
//****************************************************************************
// Hosting of stdio functionality through USART
//****************************************************************************
 
/* Implementation of putchar (also used by printf function to output data)    */
 
int __io_putchar(int ch)  /* Write character to Serial Port     */
{
// SWV Method using PB3 / SWO
//  ITM_SendChar(ch); // From core_cm4.c
 
  HAL_UART_Transmit(&huart2, (uint8_t *)&ch, 1, 0xffff);
 
  return(ch);
}
 
//****************************************************************************
 
#if 0 // enable for Keil 5.xx compilers
#pragma import(__use_no_semihosting_swi)
struct __FILE { int handle; /* Add whatever you need here */ };
FILE __stdout;
FILE __stdin;
#endif
 
int fputc(int ch, FILE *f) { return (__io_putchar(ch)); }
 
int ferror(FILE *f)
{
  /* Your implementation of ferror */
  return EOF;
}
 
void _ttywrch(int ch) { __io_putchar(ch); }
 
void _sys_exit(int return_code)
{
label:  goto label;  /* endless loop */
}
 
//****************************************************************************
 
/**
 * @brief The application entry point.
 * @retval int
 */
 
int main(void)
{
  char a[]={"\n"};
  int AD_RES=0;
  float Voltage;
  char AD_RES_r[1]={0};
  uint8_t data[1]={0};
  int i = 0;
 
  /* MCU Configuration--------------------------------------------------------*/
 
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();
 
  /* Configure the system clock */
  SystemClock_Config();
 
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USART2_UART_Init();
  MX_ADC1_Init();
 
  /* Infinite loop */
  while(1)
  {
    HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13);
 
    HAL_Delay(100);
 
    printf("hello sln #%d\r\n", i++);
  }
}

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

0693W00000bhNE0QAM.jpg 

the problem is same for this code too. i loaded your code see suddenly the loop is hanging and led not working i'm not getting why its not working. In other stm family that small code is working but here not working.

Perhaps try using the debugger?​

USART2 PA2 PA3 ?​

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

yea some problem with usart2 its not working. but for usart one also unable to print but its working fine in debug mode.