大家單片機玩得很溜了,平時也很少去關注VDD波形,整機測試無異常就完事了。也確實,芯片技術發展多年 前言 最近發現IAR 發布了新版本9.30.1,在新版本中Geehy的眾多MCU都完成了支持。

/* Includes */
#include "stdio.h"
/*!
* [url=home.php?mod=space&uid=247401]@brief[/url] Redirect C Library function printf to serial port.
* After Redirection, you can use printf function.
*
* @param ch: The characters that need to be send.
*
* @param *f: pointer to a FILE that can recording all information
* needed to control a stream
*
* @retval The characters that need to be send.
*/
int fputc(int ch, FILE *f)
{
/** send a byte of data to the serial port */
USART_TxData(DEBUG_USART,(uint8_t)ch);
/** wait for the data to be send */
while (USART_ReadStatusFlag(DEBUG_USART, USART_FLAG_TXBE) == RESET);
return (ch);
}
2. 設置工程相應參數,將General Option 的 Library Configuration 選項卡下Library選擇為“Full”,CMSIS 項目勾選“Use CMSIS”。
/*******************
*
* Copyright 1998-2017 IAR Systems AB.
*
* This is a template implementation of the "__write" function used by
* the standard library. Replace it with a system-specific
* implementation.
*
* The "__write" function should output "size" number of bytes from
* "buffer" in some application-specific way. It should return the
* number of characters written, or _LLIO_ERROR on failure.
*
* If "buffer" is zero then __write should perform flushing of
* internal buffers, if any. In this case "handle" can be -1 to
* indicate that all handles should be flushed.
*
* The template implementation below assumes that the application
* provides the function "MyLowLevelPutchar". It should return the
* character written, or -1 on failure.
*
********************/
#include
#include "Board.h"
#include "apm32f4xx.h"
#pragma module_name = "?__write"
uint8_t USART_Transmit(USART_T* usart, uint8_t *pdata, uint16_t Size);
/*
* If the __write implementation uses internal buffering, uncomment
* the following line to ensure that we are called with "buffer" as 0
* (i.e. flush) when the application terminates.
*/
size_t __write(int handle, const unsigned char * buffer, size_t size)
{
if (buffer == 0)
{
/*
* This means that we should flush internal buffers. Since we
* don't we just return. (Remember, "handle" == -1 means that all
* handles should be flushed.)
*/
return 0;
}
/* This template only writes to "standard out" and "standard err",
* for all other file handles it returns failure. */
if (handle != _LLIO_STDOUT && handle != _LLIO_STDERR)
{
return _LLIO_ERROR;
}
/* Sending in normal mode */
if(USART_Transmit(USART1,(uint8_t *)buffer,size) == 1)
{
return size;
}
else
{
return _LLIO_ERROR;
}
}
uint8_t USART_Transmit(USART_T* usart, uint8_t *pdata, uint16_t Size)
{
uint8_t ch = 0;
uint16_t i = 0;
uint16_t timeout = 0x1000;
for(i=0;i
{
ch = pdata[i];
/** send a byte of data to the serial port */
USART_TxData(usart,(uint8_t)ch);
/** wait for the data to be send */
while ((USART_ReadStatusFlag(usart, USART_FLAG_TXBE) == RESET) && (timeout -- ));
if(timeout == 0)
{
return 0;
}
timeout = 0x1000;
}
return 1;
}
審核編輯 :李倩
-
芯片技術
+關注
關注
1文章
161瀏覽量
17594 -
APM
+關注
關注
1文章
71瀏覽量
13045 -
SDK
+關注
關注
3文章
1045瀏覽量
46267 -
Printf
+關注
關注
0文章
83瀏覽量
13732
原文標題:APM32芯得 EP.07 | APM32F407 使用IAR9.3調用printf打印信息
文章出處:【微信號:geehysemi,微信公眾號:Geehy極海半導體】歡迎添加關注!文章轉載請注明出處。
發布評論請先 登錄
相關推薦
怎么用Clion開發APM32

RK3588 SDK入門之編譯使用篇

用戶手冊 | 全志T113-S3開發板——SDK編譯指南

APM32F10xx進入低功耗模式的問題分析

【GD32 MCU 移植教程】8、從 STM32F4xx 系列移植到 GD32F4xx 系

RK3568 編譯sdk技巧

在IAR中使用KitProg3進行調試,無法檢測到目標是怎么回事?
芯海通用 MCU應用筆記 :在 IAR 及 MDK 開發環境下使用 printf 函數重定向移植差異指南
在macos下SW4STM32編譯,調用printf異常怎么解決?
CKS32F4xx系列FSMC功能簡介

評論