Hello,
I am trying FileSystem example on FRDM K64F. However I can't get it working without ULINK. It says I need it in order to get it working. Is there any work around? Can I use serial port instead to INPUT/OUTPUT commands. Any help will be appreciated! I just tried a simple printf but can't get it out to serial port or debug printf viewer.
printf would be dependent of you providing retargeting code to output via SWV or UART
What exact changes I need to make in default retarget code. Sorry I am novice...appreciate your input.
www.keil.com/.../gsac_lowlevelroutinescortex.htm http://www.keil.com/support/man/docs/gsac/gsac_retargetcortex.htm
Thanks for directions. It seems I made good progress. But I am still not able to see output. Used retarget template you provided. Added stdout_UART.c/stdin_UART/stderr_UART.c in project using templates. Now changed the functions in retarget.c to use them. Configured UART1 to be used in these function and then enabled UART1 in RTE_Device.c. I added below code to init UART. I can see them initialized properly as no error returned. But still I can't see printf output in serial viewer connect on same baud rate I configured. Based LED blicking seems like it's output but not sure where to see. I have serial viewer connected but nothing there. Not sure what I am missing. Can you please advise? Please note I am using FRDM K64F with MDK latest.
status = stdout_init (); if(!status) { status = stdin_init (); if(!status) { status = stderr_init (); if(status){ printf ("Error Initializing stderr 0x%x\n> ", status); } else { printf ("All STDIO completed 0x%x\n> ", status); } } }
UART init for stdout:
/*----------------------------------------------------------------------------- * Name: stdout_USART.c * Purpose: STDOUT USART Template * Rev.: 1.0.0 *-----------------------------------------------------------------------------*/
#include "Driver_USART.h"
//-------- <<< Use Configuration Wizard in Context Menu >>> --------------------
// <h>STDOUT USART Interface
// <o>Connect to hardware via Driver_USART# <0-255> // Select driver control block for USART interface #define USART_DRV_NUM 1
// <o>Baudrate #define USART_BAUDRATE 115200
// </h>
#define _USART_Driver_(n) Driver_USART##n #define USART_Driver_(n) _USART_Driver_(n)
extern ARM_DRIVER_USART USART_Driver_(USART_DRV_NUM); #define ptrUSART (&USART_Driver_(USART_DRV_NUM))
/** Initialize stdout
\return 0 on success, or -1 on error. */ int stdout_init (void) { int32_t status;
status = ptrUSART->Initialize(NULL); if (status != ARM_DRIVER_OK) return (-1);
status = ptrUSART->PowerControl(ARM_POWER_FULL); if (status != ARM_DRIVER_OK) return (-1);
status = ptrUSART->Control(ARM_USART_MODE_ASYNCHRONOUS | ARM_USART_DATA_BITS_8 | ARM_USART_PARITY_NONE | ARM_USART_STOP_BITS_1 | ARM_USART_FLOW_CONTROL_NONE, USART_BAUDRATE); if (status != ARM_DRIVER_OK) return (-1);
status = ptrUSART->Control(ARM_USART_CONTROL_TX, 1); if (status != ARM_DRIVER_OK) return (-1);
return (0); }
/** Put a character to the stdout
\param[in] ch Character to output \return The character written, or -1 on write error. */ int stdout_putchar (int ch) { uint8_t buf[1];
buf[0] = ch; if (ptrUSART->Send(buf, 1) != ARM_DRIVER_OK) { return (-1); } while (ptrUSART->GetTxCount() != 1); return (ch); }
Here is my retarget.c:
/******************************************************************************/ /* RETARGET.C: 'Retarget' layer for target-dependent low level functions */ /******************************************************************************/ /* This file is part of the uVision/ARM development tools. */ /* Copyright (c) 2005 Keil Software. All rights reserved. */ /* This software may only be used under the terms of a valid, current, */ /* end user licence from KEIL for a compatible version of KEIL software */ /* development tools. Nothing else gives you the right to use this software. */ /******************************************************************************/
#include <stdio.h> #include <time.h> #include <rt_misc.h>
#pragma import(__use_no_semihosting_swi)
extern int stdout_putchar(int ch); extern int stdin_getchar(void); extern long timeval;
struct __FILE { int handle; /* Add whatever you need here */ }; //FILE __stdout; //FILE __stdin;
int fputc(int ch, FILE *f) { return (stdout_putchar(ch)); }
int fgetc(FILE *f) { return (stdout_putchar(stdin_getchar())); }
int ferror(FILE *f) { /* Your implementation of ferror */ return EOF; }
void _ttywrch(int ch) { stdout_putchar (ch); }
void _sys_exit(int return_code) { while (1); /* endless loop */ }
Thanks again. I was able to figure out. I had to change to UART0. Now I can see IN/OUT but I have issue in INPUT. It doesn't flush the characters on ENTER. SO next time take last character entered. Below is my getc function and I use scanf to take string in.
int fgetc(FILE *f) { int ch; ch = stdin_getchar(); fflush(stdin); stdout_putchar(ch); fflush(stdin); return ch; }
Thanks again. What I found is it only happens if in debug mode. If I take out of debug mode and connect board through serial, then is no issue at all. I am using CMSIS-DAP as a debugger. As I said issue is only with input. I have core clock frequency set to 120MHz. Operating system is set to RTX Kernel. Do I need to do some other debug setting to avoid this mis-behavior?