大家單片機(jī)玩得很溜了,平時(shí)也很少去關(guān)注VDD波形,整機(jī)測試無異常就完事了。也確實(shí),芯片技術(shù)發(fā)展多年 前言 最近發(fā)現(xiàn)IAR 發(fā)布了新版本9.30.1,在新版本中Geehy的眾多MCU都完成了支持。
?我這邊剛好有APM32F407IG的MINIBOARD,想著使用IAR編譯一下工程下載運(yùn)行一下程序。不料卻發(fā)現(xiàn)了問題,APM32F4xx_SDK_V1.1中的IAR例程是基于 IAR8.5制作的,關(guān)于printf的重定向都已經(jīng)在工程內(nèi)進(jìn)行了設(shè)置。使用8.5的工程也可以正常使用printf功能。但在9.x的IAR對printf重定向有了新的要求,導(dǎo)致IAR 9.x版本無法運(yùn)行含有printf功能的例程。
本文檔就解決APM32F4xx_SDK_V1.1中使用IAR9.3進(jìn)行編譯使用printf功能進(jìn)行記錄分享。
值得注意的是:
- printf重定向前需完成對應(yīng)串口的初始化操作。
1 IAR 8.x的printf重定向
IAR 8.x的printf重定向與Keil并無差異,僅需在內(nèi)部的任意一個(gè)C文件中重定向printf后設(shè)置工程的相應(yīng)參數(shù)即可完成。
1. 重定向printf代碼如下(發(fā)送串口為串口1,頭文件需包含stdio.h)
/* 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. 設(shè)置工程相應(yīng)參數(shù),將General Option 的 Library Configuration 選項(xiàng)卡下Library選擇為“Full”,CMSIS 項(xiàng)目勾選“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;
}
審核編輯 :李倩
-
芯片技術(shù)
+關(guān)注
關(guān)注
1文章
172瀏覽量
18316 -
APM
+關(guān)注
關(guān)注
1文章
72瀏覽量
13706 -
SDK
+關(guān)注
關(guān)注
3文章
1091瀏覽量
50859 -
Printf
+關(guān)注
關(guān)注
0文章
84瀏覽量
14576
原文標(biāo)題:APM32芯得 EP.07 | APM32F407 使用IAR9.3調(diào)用printf打印信息
文章出處:【微信號:geehysemi,微信公眾號:Geehy極海半導(dǎo)體】歡迎添加關(guān)注!文章轉(zhuǎn)載請注明出處。
發(fā)布評論請先 登錄
請問如何在 Keil μVision 或 IAR EWARM 中使用觀察點(diǎn)進(jìn)行調(diào)試?
env scons 編譯找不到stm32f4xx.h,這個(gè)怎么解決?
【RA-Eco-RA6M4開發(fā)板評測】1、開發(fā)環(huán)境搭建和串口打印信息
為APM32F411打造可自動化的命令行工作流
極海APM32F411微控制器硬件FPU使用指南
在IAR Arm開發(fā)工具鏈中--function_sections編譯選項(xiàng)的使用
k230 sdk編譯報(bào)錯(cuò)的原因?
EE-88:使用21xx編譯器在C中初始化變量
stdio.h實(shí)現(xiàn)了printf函數(shù)?
怎么用Clion開發(fā)APM32
RK3588 SDK入門之編譯使用篇
用戶手冊 | 全志T113-S3開發(fā)板——SDK編譯指南

APM32F4xx_SDK_V1.1中使用IAR9.3進(jìn)行編譯使用printf功能
評論