2017-01-13 12:35 PM
Hi,
I have finally dragged everything offline into Keil and it now compiles
but instantly goes into hardfault caused by the printf.
How do we fix this issue ?
2017-01-13 07:36 PM
You'd have to ensure the data goes some where rather than trap with a BKPT or SWI
//****************************************************************************
// Hosting of stdio functionality through USART2
//****************************************************************************
#include <rt_misc.h>
#pragma import(__use_no_semihosting_swi)
struct __FILE { int handle; /* Add whatever you need here */ };
FILE __stdout;
FILE __stdin;
int fputc(int ch, FILE *f)
{
while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
USART_SendData(USART2, ch);
return(ch);
}
int fgetc(FILE *f)
{
char ch;
while(USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET);
ch = USART_ReceiveData(USART2);
return((int)ch);
}
int ferror(FILE *f)
{
/* Your implementation of ferror */
return EOF;
}
void _ttywrch(int ch)
{
while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
USART_SendData(USART2, ch);
}
void _sys_exit(int return_code)
{
label: goto label; /* endless loop */
}
//****************************************************************************
�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
2017-01-14 04:31 PM
Hi Clive, excellent.
I am trying to implement the same now, but the syntax kills me.
The resulting code is attached but still hard faults because I attempt to write to STDOUT.
Compile Errors
[FILE __stdout] warning: #2681-D: name linkage conflicts with previous declaration of variable 'std::__stdout' (declared at line 138 of 'C:\Keil_v5demo\ARM\ARMCC\Bin\..\include\stdio.h')
error: #734: function 'fputc(int, std::FILE *)' conflicts with using-declaration of function 'std::fputc(int, std::FILE *)'
should there be a .h declaration of FILE ? is it nStream ?
I have implemented mostly of what you suggested, but I cannot work out the syntax to redirect stdin/stdout.
which is required to fix the printf hardfault issue in Keil when using mbed.
Please see attached skeleton uV5 project without the target or mbed
my target is a STM32F091
________________ Attachments : Nucleo_printf.uvguix.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HysO&d=%2Fa%2F0X0000000bF1%2Fg3UhhshhqGQeO5bXWAi7HxCnc1RGWOWsqgXAjrQwB6U&asPdf=false2017-01-18 02:59 PM
can you look into my issue ?
I have not been able to make the leap. to connect to STDIN and STDOUT.
I have done what I can in the included files, but there is some syntax that I am not understanding...
:(
2017-01-18 07:20 PM
The .CPP usage complicates things, and I'm not working with mbed
You need the ♯ pragma to stop the library code from being pulled in because we are trying to replace that with board specific functions.
This is a main.c example for the F4 Nucleo
The pieces for the F0 Disco
2017-01-18 07:26 PM
I am no longer working with mbed.
however, I have a huge project running online, trying to get it offline.
all my new stuff is cubeMX HAL uV5.
can you open that project ? and fix the __FILE syntax issue ? just link into one of the new putc, puts... if thats ok...
I just cannot make it mesh, spent hours trying different syntax.
:(
2017-01-18 08:53 PM
The project 'opens' but it references a lot of stuff I don't have installed.
2017-01-18 08:59 PM
the project folder compressed to 2.4MB...
I hope it is ok for you.
I have been trying to help online, but so much goes over my head.
________________ Attachments : Nucleo_printf.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hyz9&d=%2Fa%2F0X0000000bEu%2F6yBDlWBY6jSmtNDdIzHSDkfo919ferk1N.oKggJ.lMQ&asPdf=false