SWDR001 icon indicating copy to clipboard operation
SWDR001 copied to clipboard

Read RX Buffer Writes Stat to Result Buffer

Open FiercestT opened this issue 3 months ago • 1 comments

I encountered this confusing problem when receiving.

As per the user manual, the first byte result of the ReadBuffer8 command is the stat1 of the command.

image

However, when using lr11xx_regmem_read_buffer8(ctx, buffer, offset, length), stat1 is passed to the first address of the buffer pointer. Additionally, when using a buffer length of 1, the buffer will always only be filled with stat1. I don't believe this is intended behaviour as I would have to have a buffer of length n + 1 and always discard/ignore the first element. This is not documented in the function header and is ultimately confusing and wasteful.

Cause: The function is passing the SPI result directly to the user defined buffer, causing the stat1 to be written to index 0.

lr11xx_status_t lr11xx_regmem_read_buffer8( const void* context, uint8_t* buffer, const uint8_t offset,
                                            const uint8_t length )
{
    const uint8_t cbuffer[LR11XX_REGMEM_READ_BUFFER8_CMD_LENGTH] = {
        ( uint8_t ) ( LR11XX_REGMEM_READ_BUFFER8_OC >> 8 ),
        ( uint8_t ) ( LR11XX_REGMEM_READ_BUFFER8_OC >> 0 ),
        offset,
        length,
    };

    return ( lr11xx_status_t ) lr11xx_hal_read( context, cbuffer, LR11XX_REGMEM_READ_BUFFER8_CMD_LENGTH, buffer,
                                                length );
}

Edit: This also makes the 255th byte of the receive buffer unobtainable without another request with offset as the 8 bit length also includes the stat1.

FiercestT avatar Mar 23 '24 05:03 FiercestT