hmjames 发表于 2024-8-9 10:36

printf 不能打印float类型数据

使用AT-START-F437开发板,用printf 打印float类型的变量在串口输出里面是空的,其他整形和字符是正常的。AT32芯片是不是不支持float的printf?搜索发现很多单片机是不支持的,但是我在一个stm32F407VET6的例程中发现有printf float的代码,可知stm32F407VET6是支持printf float的。按理说AT32F437性能更强不应该不支持吧?

muyichuan2012 发表于 2024-8-9 13:43

可以的,你使用的keil还是iar?
你这样测试一下,打开AT32F435_437_Firmware_Library/ project / at_start_f435 / templates / mdk_v5 路径下keil工程
在main函数增加如下蓝色部分代码:int main(void){
float i=0.0;
system_clock_config();

at32_board_init();

button_exint_init();
usart_init(115200);
while(1)
{
    printf("i=%f\r\n",i++);
    at32_led_toggle(LED2);
    delay_ms(g_speed * DELAY);
    at32_led_toggle(LED3);
    delay_ms(g_speed * DELAY);
    at32_led_toggle(LED4);
    delay_ms(g_speed * DELAY);
}
}


串口助手打印效果如下


丙丁先生 发表于 2024-8-9 17:30

xionghaoyun 发表于 2024-8-10 09:26

你断点仿真 看数据是不是浮点数

hmjames 发表于 2024-8-12 13:56

补充:
我用keil是可以的,用vscode+eide+gcc toolchain就是帖子说的那样,float没有输出。设置了floatingPointHardware和float-abi-type也还是不行

hmjames 发表于 2024-8-12 13:57

xionghaoyun 发表于 2024-8-10 09:26
你断点仿真 看数据是不是浮点数

debug看变量是float的

hmjames 发表于 2024-8-12 13:57

muyichuan2012 发表于 2024-8-9 13:43
可以的,你使用的keil还是iar?
你这样测试一下,打开AT32F435_437_Firmware_Library/ project / at_start_f ...

用keil是可以的,用vscode+eide+gcc不行

muyichuan2012 发表于 2024-8-12 16:29

本帖最后由 muyichuan2012 于 2024-8-12 16:30 编辑

对于GCC编译器而言,需要加如下链接指令(-u _printf_float)

在FAQ0145里有写:https://www.arterytek.com/downlo ... E9%A1%B9_V2.0.0.pdf
页: [1]
查看完整版本: printf 不能打印float类型数据