Hello.
When developing I.MX9352 Cortex-M33 with IAR1 9.50.2, it was not possible to output floating-point data via redirected printf.
The SDK used is SDK_2_16_000_MIMX9352xxxxM
The following Settings have been made in the IAR Settings.
Here's my code:
/*
* Copyright (c) 2015, Freescale Semiconductor, Inc.
* Copyright 2016-2017 NXP
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "pin_mux.h"
#include "clock_config.h"
#include "board.h"
#include "fsl_debug_console.h"
#include "fsl_rgpio.h"
/*******************************************************************************
* Definitions
******************************************************************************/
#define BOARD_LED_RGPIO GPIO3
#define BOARD_LED_RGPIO_PIN 26U
#define EXAMPLE_RGPIO_CLOCK_ROOT kCLOCK_Root_BusWakeup
#define EXAMPLE_RGPIO_CLOCK_GATE kCLOCK_Gpio3
double Pi = 3.1415926;
/*******************************************************************************
* Prototypes
******************************************************************************/
/*!
* @brief delay a while.
*/
void delay(void);
/*******************************************************************************
* Variables
******************************************************************************/
/*******************************************************************************
* Code
******************************************************************************/
/*!
* @brief Main function
*/
int main(void)
{
/* Define the init structure for the output LED pin*/
rgpio_pin_config_t led_config = {
kRGPIO_DigitalOutput,
0,
};
/* Board pin, clock, debug console init */
/* clang-format off */
const clock_root_config_t rgpioClkCfg = {
.clockOff = false,
.mux = 0, // 24Mhz Mcore root buswake clock
.div = 1
};
/* clang-format on */
BOARD_InitBootPins();
BOARD_BootClockRUN();
BOARD_InitDebugConsole();
CLOCK_SetRootClock(EXAMPLE_RGPIO_CLOCK_ROOT, &rgpioClkCfg);
CLOCK_EnableClock(EXAMPLE_RGPIO_CLOCK_GATE);
CLOCK_EnableClock(kCLOCK_Gpio2);
/* Set PCNS register value to 0x0 to prepare the RGPIO initialization */
BOARD_LED_RGPIO->PCNS = 0x0;
/* Print a note to terminal. */
PRINTF("\r\n RGPIO Driver example\r\n");
PRINTF("\r\n The LED is taking turns to shine.\r\n");
/* Init output LED GPIO. */
RGPIO_PinInit(BOARD_LED_RGPIO, BOARD_LED_RGPIO_PIN, &led_config);
while (1)
{
PRINTF("output float value:Pi=%f %lf\r\n", Pi, Pi);
SDK_DelayAtLeastUs(1000000U, SystemCoreClock);
RGPIO_PortToggle(BOARD_LED_RGPIO, 1u << BOARD_LED_RGPIO_PIN);
}
}The actual effect is as follows:
Hi @HL_G
Please refer this case to modify PRINTF function in SDK:
https://community.nxp.com/t5/i-MX-Processors/i-MX8MP-Cannot-print-float-values-from-SDK-M7-examples/...
Best Regards
Zhiming
Hi.@Zhiming_Liu
Thanks.
It seems that this approach is no better than using the sprintf function to convert to string output. Is there a way to print floating-point data directly using PRINTF?
Like this:
main()
{
double pi = 3.1415926;
PRINTF("pi = %f\r\n", pi);
}The output:
pi = 3.141593
Hello,
The existing PRINTF has a bit of a problem with float, or if you're not using serial printing and use printf inside the IAR
Best Regards,
Zhiming