Skip to main content
Sm.1
Associate II
Mar 31, 2023 9:14 AM UTC
Question

stm32f103c6t6 arm controller printf is not working.

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

This topic has been closed for replies.

10 replies

Tesla DeLorean
Guru
Mar 31, 2023 9:24 AM UTC

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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
Sm.1
Sm.1Author
Associate II
Mar 31, 2023 12:51 PM UTC
Sm.1
Sm.1Author
Associate II
Mar 31, 2023 9:26 AM UTC

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​ 

Tesla DeLorean
Guru
Mar 31, 2023 2:46 PM UTC
#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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
Sm.1
Sm.1Author
Associate II
Apr 1, 2023 4:13 AM UTC

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

}

Tesla DeLorean
Guru
Apr 1, 2023 3:49 PM UTC
#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 (See Profile) Up vote any posts that you find helpful, it shows what's working..