This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

No serial output when using lwIP

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'); } }

Parents
  • I'm trying to implement a basic application on an embedded device using lwIP.

    Do you have any successful experiences with Filesystem or TCP/IP on MCU?

    You need to prepare and initialize something, before you can call fopen(). On X86 platform, what you need is simply [ #include <stdio.h> ].

Reply
  • I'm trying to implement a basic application on an embedded device using lwIP.

    Do you have any successful experiences with Filesystem or TCP/IP on MCU?

    You need to prepare and initialize something, before you can call fopen(). On X86 platform, what you need is simply [ #include <stdio.h> ].

Children