STM32+Keil 如何使用printf函数?
时间:11-10
来源:互联网
点击:
Keil不支持Host-semi机制,即不支持直接在IDE打印字符串。
那么只能通过程序向硬件串口发数据了,这样调用的时候用自定义的函数即可,也很方便,例如:
void send_char_to_usart(unsigned char c){}
但是可否直接使用printf函数呢?毕竟人家都做好了,我们给他定一个打印输出的接口就可以了,答案是肯定的,看ST的官方源码:
- /**
- ******************************************************************************
- *@fileLib_DEBUG/Lib_DEBUG_Example/main.c
- *@authorMCDApplicationTeam
- *@versionV1.1.1
- *@date13-April-2012
- *@briefMainprogrambody
- ******************************************************************************
- *@attention
- *
- *
COPYRIGHT2012STMicroelectronics - *
- *LicensedunderMCD-STLibertySWLicenseAgreementV2,(the"License");
- *YoumaynotusethisfileexceptincompliancewiththeLicense.
- *YoumayobtainacopyoftheLicenseat:
- *
- *http://www.st.com/software_license_agreement_liberty_v2
- *
- *Unlessrequiredbyapplicablelaworagreedtoinwriting,software
- *distributedundertheLicenseisdistributedonan"ASIS"BASIS,
- *WITHOUTWARRANTIESORCONDITIONSOFANYKIND,eitherexpressorimplied.
- *SeetheLicenseforthespecificlanguagegoverningpermissionsand
- *limitationsundertheLicense.
- *
- ******************************************************************************
- */
- /*Includes------------------------------------------------------------------*/
- #include"stm32l1xx.h"
- #include"stm32l1xx_ip_dbg.h"
- #include
- #ifdefUSE_STM32L152D_EVAL
- #include"stm32l152d_eval.h"
- #else
- #include"stm32l152_eval.h"
- #endif
- /**@addtogroupSTM32L1xx_StdPeriph_Examples
- *@{
- */
- /**@addtogroupLib_DEBUG_Example
- *@{
- */
- /*Privatetypedef-----------------------------------------------------------*/
- /*Privatedefine------------------------------------------------------------*/
- /*Privatemacro-------------------------------------------------------------*/
- /*Privatevariables---------------------------------------------------------*/
- USART_InitTypeDefUSART_InitStructure;
- /*Privatefunctionprototypes-----------------------------------------------*/
- #ifdef__GNUC__
- /*WithGCC/RAISONANCE,smallprintf(optionLDLinker->Libraries->Smallprintf
- settoYes)calls__io_putchar()*/
- #definePUTCHAR_PROTOTYPEint__io_putchar(intch)
- #else
- #definePUTCHAR_PROTOTYPEintfputc(intch,FILE*f)
- #endif/*__GNUC__*/
- /*Privatefunctions---------------------------------------------------------*/
- /**
- *@briefMainprogram
- *@paramNone
- *@retvalNone
- */
- intmain(void)
- {
- /*!
- thisisdonethroughSystemInit()functionwhichiscalledfromstartup
- file(startup_stm32l1xx_xx.s)beforetobranchtoapplicationmain.
- ToreconfigurethedefaultsettingofSystemInit()function,referto
- system_stm32l1xx.cfile
- */
- GPIO_InitTypeDefGPIOA_InitStructure;
- /*USARTxconfiguredasfollow:
- -BaudRate=115200baud
- -WordLength=8Bits
- -OneStopBit
- -Noparity
- -Hardwareflowcontroldisabled(RTSandCTSsignals)
- -Receiveandtransmitenabled
- */
- USART_InitStructure.USART_BaudRate=115200;
- USART_InitStructure.USART_WordLength=USART_WordLength_8b;
- USART_InitStructure.USART_StopBits=USART_StopBits_1;
- USART_InitStructure.USART_Parity=USART_Parity_No;
- USART_InitStructure.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
- USART_InitStructure.USART_Mode=USART_Mode_Rx|USART_Mode_Tx;
- STM_EVAL_COMInit(COM1,&USART_InitStructure);
- /*Initializeallperipheralspointers*/
- IP_Debug();
- printf("\r\nSTM32l1xxFirmwareLibrarycompiledwithFULLASSERTfunction...\n\r");
- printf("...Run-timecheckingenabled\n\r");
- /*Simulatewrongparameterpassedtolibraryfunction---------------------*/
- /*ToenableSPI1clock,RCC_APB2PeriphClockCmdfunctionmustbeusedand
- notRCC_APB1PeriphClockCmd*/
- RCC_APB1PeriphClockCmd(RCC_APB2Periph_SPI1,ENABLE);
- /*SomememberofGPIOA_InitStructurestructurearenotinitialized*/
- GPIOA_InitStructure.GPIO_Pin=GPIO_Pin_6;
- GPIOA_InitStructure.GPIO_Mode=GPIO_Mode_OUT;
- /*GPIOA_InitStruc
STM32Keilprintf函 相关文章:
- STM32+Keil 中使用printf函数(11-17)
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)