Reputation: 23
I'm trying to port out the Arduino Ethernet library to libmaple
for use with STM32 devices. When compiling (using the CodeSourcery GCC toolchain). I get
libraries/Ethernet/w5100.cpp:111: error: cast from 'uint8_t*' to 'uint16_t' loses precision
around the code segment:
void W5100Class::read_data(SOCKET s, uint8_t *src, uint8_t *dst, uint16_t len)
{
uint16_t size;
uint16_t src_ptr;
src_mask = (uint16_t)src & RMASK;
src_ptr = RBASE[s] + src_mask;
if( (src_mask + len) > RSIZE )
{
size = RSIZE - src_mask;
read(src_ptr, (uint8_t *)dst, size);
dst += size;
read(RBASE[s], (uint8_t *) dst, len - size);
}
else
read(src_ptr, (uint8_t *) dst, len);
}
Upvotes: 0
Views: 3230
Reputation: 31
Change src_mask = (uint16_t)src & RMASK;
to src_mask = (0xffff & src) & RMASK;
will meet your demand too. Just discard higher 16 bits as you wish.
Upvotes: 0
Reputation: 11896
Your pointer types are 32-bits, so when you try to assign that to a 16-bit, it is losing data.
Upvotes: 4