cancel
Showing results for 
Search instead for 
Did you mean: 

How to send 16 bit data using LwIP?

Raymond Buck
Senior

I'm working on a custom board that uses a STM32F407 to send data across the network to another STM32F407 board using LwIP (no OS). I created an array of 100 bytes to use as a test program. It works fine as long as the array is declared as uint8_t. I am able to send 100 bytes and the other board receives all 100 bytes correctly.

If I declare the array as uint16_t, I only receive half of the bytes. I changed the array size to 40 as a further test. That results in only 20 bytes being received by the remote board.

If I look at the ethernetif.c file in LwIP, I see the following 2 lines that indicate what may be the problem.

__ALIGN_BEGIN uint8_t Rx_Buff[ETH_RXBUFNB][ETH_RX_BUF_SIZE] __ALIGN_END; /* Ethernet Receive Buffer */

__ALIGN_BEGIN uint8_t Tx_Buff[ETH_TXBUFNB][ETH_TX_BUF_SIZE] __ALIGN_END; /* Ethernet Transmit Buffer */

If I change the uint8_t Tx to uint16_t TX and try to compile I get these warning:

warning: passing argument 3 of 'HAL_ETH_DMATxDescListInit' from incompatible pointer type [-Wincompatible-pointer-types]

I have been working on this problem for a few hours but can't find a solution. The only thing I can think of (haven't tried) is to break the 16 bit data into two 8 bit data bytes and re-assemble on the remote end. But that is not really a desirable solution.

Has anyone else encountered this problem and found a work around?

3 REPLIES 3
hs2
Senior

It’s very likely just a C language issue. I guess you mixed up number of bytes vs. number of values (sizeof uint8_t vs. sizeof uint16_t ) somewhere.

The pointer warning correctly tells you that the Ethernet driver expects buffers of ETH_T/RX_BUF_SIZE bytes.

Raymond Buck
Senior

hs2, I found the issue. You are correct on bytes vs values. I found that and fixed it but that did not correct the problem. The pointer warning is actually the key to what the problem is. LwIP expects 8 bit data and apparently there is no way to change that to 16 bit data. I have the final solution posted on another blog. It can be found here:

https://www.eevblog.com/forum/microcontrollers/how-to-send-16-bit-data-using-lwip/

Piranha
Chief II

This has nothing to do with lwIP or STM32. It's the basics of C language and programming.

  • C has sizeof() operator, which will return the object's or type's size in bytes.
  • Pointers can be casted to (void*) or the target type.