[技术问答]

ML51 IAR Compile printf出错

[复制链接]
824|3
手机看帖
扫描二维码
随时随地手机跟帖
superdos|  楼主 | 2019-10-22 20:42 | 显示全部楼层 |阅读模式
刚刚用IAR搭起来ML51的环境,编译sample code时,发现每次编译到printf,就报如下错误:
Error[Pe167]: argument of type "char __code *" is incompatible with parameter of type "char const *"

代码就是Nuvoton提供的参考代码,例如:

#include "ML51_IAR.h"

/******************************************************************************
The main C function.  Program execution starts
here after stack initialization.
******************************************************************************/
void main (void)
{
    MFP_P31_UART0_TXD;                //Setting P31 multi function pin as TXD
    P31_PUSHPULL_MODE;                //Output mode for TXD

    UART_Open(24000000,UART0_Timer3,115200);
    ENABLE_UART0_PRINTF;
    ADC_INPUT_VBG;                    //Find in "Function_define.h" - "ADC INIT"


  while(1)
    {
      clr_ADCCON0_ADCF;
      set_ADCCON0_ADCS;                                  // Each time ADC start trig signal
      while(ADCCON0&0x10 == 0);
      printf ("\n Value = 0x%bx",ADCRH);
      printf ("\n Value = 0x%bx",ADCRL);
//      Timer2_Delay(24000000,128,200,1000);
      _nop_();
    }
}

哪位老大给指点一下,多谢!

使用特权

评论回复
jasontu| | 2019-10-23 08:24 | 显示全部楼层
應該是要呼叫printf_p

使用特权

评论回复
jasontu| | 2019-10-23 11:18 | 显示全部楼层
試過用IAR內建的PRINTF,會有印錯誤字串。
自已改了PRINTF,

#include "ML51_IAR.H"
void UART_UART0(uint8_t c)
{
        SFRS = 0;
        TI = 0;
        SBUF = c;
        while(TI==0);
        TI = 0;
   
}
/*---------------------------------------------------------------------------------------------------------*/
/*  Simple printf() function                                                                                          */
/*---------------------------------------------------------------------------------------------------------*/
void printf_UART(uint8_t *str, ...);
void printInteger(uint32_t u32Temp)
{
    uint8_t print_buf[16];
    uint32_t i = 15, j;

    *(print_buf + i) = '\0';
    j = u32Temp >> 31;
    if(j)
        u32Temp = ~u32Temp + 1;
    do
    {
        i--;
        *(print_buf + i) = '0' + u32Temp % 10;
        u32Temp = u32Temp / 10;
    }
    while(u32Temp != 0);
    if(j)
    {
        i--;
        *(print_buf + i) = '-';
    }
    printf_UART(print_buf + i);
}
void printHex(uint32_t u32Temp)
{
    uint8_t print_buf[16];
    uint32_t i = 15;
    uint32_t temp;

    *(print_buf + i) = '\0';
    do
    {
        i--;
        temp = u32Temp % 16;
        if(temp < 10)
            *(print_buf + i) = '0' + temp;
        else
            *(print_buf + i) = 'a' + (temp - 10) ;
        u32Temp = u32Temp / 16;
    }
    while(u32Temp != 0);
    printf_UART(print_buf + i);
}
void printf_UART(uint8_t *str, ...)
{
    va_list args;
    va_start(args, str);
    while(*str != '\0')
    {
        if(*str == '%')
        {
            str++;
            if(*str == '\0') return;
            if(*str == 'd')
            {
                str++;
                printInteger(va_arg(args, int));
            }
            else if(*str == 'x')
            {
                str++;
                printHex(va_arg(args, int));
            }
        }
        //SendChar_ToUART(*str++);
  //UART_Send_Data(UART0,*str++);  
UART_UART0(*str++);
    }
}

/*******************************************************************************
* FUNCTION_PURPOSE: Main function
******************************************************************************/
void main (void)
{

/* Initial UART0 for printf */
  unsigned char t1=0x5a;
    MFP_P31_UART0_TXD;
    P31_PUSHPULL_MODE;
    UART_Open(24000000,UART0_Timer3,115200);
    UART_UART0(0x55);
printf_UART("test\n\r");
  printf_UART("%d\n\r",t1);
  printf_UART("%x\n\r",t1);
    while(1);
   
}
  

使用特权

评论回复
superdos|  楼主 | 2019-10-24 17:50 | 显示全部楼层
jasontu 发表于 2019-10-23 11:18
試過用IAR內建的PRINTF,會有印錯誤字串。
自已改了PRINTF,

Compile 出错原因找到了。
在Options -> General Options -> Location for constants and strings,选择“RAM memory”,就可以Compile通过了。只是在PC端还没看到串口的输出,需要再查。
还是感谢你的代码分享!

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

2

主题

5

帖子

0

粉丝