baobrien
baobrien

Reputation: 23

"cast from 'uint8_t*' to 'uint16_t' loses precision" when compiling for STM32

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

Answers (2)

CTQY
CTQY

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

TJD
TJD

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

Related Questions