cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeMX + MDK-ARM: retargeting printf output

balazs
Associate II
Posted on November 25, 2014 at 01:21

Hi All,

I'm using the tools as per the subject.

Can you advise how I can configure printf to trace to a serial terminal?

Currently I'm using a Nucleo board (Nucleo L053R8) but soon I'm moving on to Discovery (STM32F429).

Any help is really appreciated!

Regards,

Balas

#stm32 #printf #discovery
3 REPLIES 3
Posted on November 25, 2014 at 01:38

Can't help you with Cube, probably want to ponder using the [DEAD LINK /public/STe2ecommunities/mcu/Lists/STM32Java/AllItems.aspx]other forum

[DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/printf%20keil%20stm32%20eval2%20board&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=79]https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2Fcortex_mx_stm32%2Fprintf%20keil%20stm32%20eval2%20board&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=79

There's also the SWO pin and SWV

[DEAD LINK /public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM32Discovery/ADC3%20converting%203%20inputs%20%2B%20display&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F&currentviews=276]https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2FSTM32Discovery%2FADC3%20converting%203%20inputs%20%2B%20display&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F¤tviews=276

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
rnohe
Associate
Posted on January 26, 2015 at 23:51

Hi,

Here a simple HelloWorld,

/* Includes ------------------------------------------------------------------*/

#include ''stm32f3xx_hal.h''

/* USER CODE BEGIN Includes */

#include <stdio.h>

/* USER CODE END Includes */

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

UART_HandleTypeDef huart1;

/* USER CODE BEGIN PV */

/* USER CODE END PV */

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

void SystemClock_Config(void);

static void MX_GPIO_Init(void);

static void MX_USART1_UART_Init(void);

/* USER CODE BEGIN PFP */

/**

  * @brief  Retargets the C library printf function to the USART.

  * @param  None

  * @retval None

  */

int fputc(int ch, FILE *f){

  /* Place your implementation of fputc here */

  /* e.g. write a character to the USART */

  HAL_UART_Transmit(&huart1,(uint8_t*)&ch,1,1);// 1 tick waiting (1ms) enough for 87us/byte at 115200

  return ch;

}

/* USER CODE END PFP */

/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

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();

  /* Configure the system clock */

  SystemClock_Config();

  /* Initialize all configured peripherals */

  MX_GPIO_Init();

  MX_USART1_UART_Init();

  /* USER CODE BEGIN 2 */

//HAL_SuspendTick(); // comment because needed for timeout

  /* USER CODE END 2 */

  /* USER CODE BEGIN 3 */

  /* Infinite loop */

printf(''Hello from STM32CubeMX\n'');

  while (1)

  {

  }

  /* USER CODE END 3 */

}

Regards,

Régis

joe2399
Associate II
Posted on May 10, 2015 at 07:29

rn,

That works great...thanks a ton for the post!

Joe