We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello,
I'm trying to implement a basic application on an embedded device using lwIP. I got the basic project set up, the retarget-ing works as expected.
However when I add lwIP into the project and call lwip_init() I have no more output. If I leave out the call to lwip_init() everything is back to normal.
What's more interesting, is that if I call fopen() the same behavior appears as before, I have no other output on the serial. I get no output no matter if I use the retarget-ed printf() function or if I use the driver's function USART_SendData().
What did I got wrong?
I posted below the retarget.c file and my Main.cpp (if I un-comment either BLOCK 1 or BLOCK 2, I have no more output).
Note: the retarget-ed functions send data to USART3 and USART_SendData() sends it to USART1.
retarget.c:
#include <stdio.h> #include <LibSTM/stm32f10x_usart.h> #include <rt_sys.h> #pragma import(__use_no_semihosting_swi) struct __FILE { int handle; }; FILE __stdout; FILE __stdin; FILE __stderr; FILE *__aeabi_stdin; FILE *__aeabi_stdout; FILE *__aeabi_stderr; int fputc(int ch, FILE *f) { while (!(USART3->SR & 0x0080)); USART3->DR = ch; return (ch); } int ferror(FILE *f) { return EOF; } void _ttywrch(int ch) { fputc(ch, stdout); } void _sys_exit(int return_code) { label: goto label; } //retargeting since otherwise lwIP inclusion produces errors //infocenter.arm.com/.../index.jsp #define DEFAULT_HANDLE 0x100 const char __stdin_name[] = "my_stdin"; const char __stdout_name[] = "my_stdout"; const char __stderr_name[] = "my_stderr"; int _sys_write(FILEHANDLE fh, const unsigned char * buf, unsigned len, int mode){ int i; for(i=0;i<len;i++) { fputc(buf[i], stdout); } return 0; } FILEHANDLE _sys_open(const char* name, int openmode){ return DEFAULT_HANDLE; } int _sys_istty(FILEHANDLE fh){ return 0; } int _sys_seek(FILEHANDLE fh, long pos){ return -1; } long _sys_flen(FILEHANDLE fh){ return 0; } int _sys_close(FILEHANDLE fh){ return 0; } int _sys_ensure(FILEHANDLE fh){ return 0; }
main.cpp:
#include <HW/HWSetup.h> #include <stdio.h> #include "lwip/init.h" int main() { HWSetup(); printf("Start!\r\n"); /* //BLOCK 1 FILE *f; f = fopen("foobar", "r"); */ /* //BLOCK 2 lwip_init(); */ printf("End!\r\n"); while(1){ USART_SendData(USART1, 'x'); } }
TCP/IP, Filesystem might be trivial to developers like Andrew Neil or Westonsupermare Pier; but personally, I think TCP/IP, Filesystem are very difficult.
It is necessary for a beginner to start with a working evaluation board + working lwIP example code; otherwise it costs too much time.
On the other hand, we become experienced by solving a lot of problems.