Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

UART receive buffer full #300

Closed
Closed
@davesto

Description

@davesto

(sysname='FiPy', nodename='FiPy', release='1.20.0.rc8', version='v1.9.4-7b83c6d on 2019-03-06', machine='FiPy with ESP32', lorawan='1.0.2', sigfox='1.0.1')

The UART receive buffer seems to fill after ~600 bytes of data have been received
In machuart.c, MACHUART_RX_BUFFER_LEN is defined as 4096 but the buffer seems to run out of steam well before that.

Test configuration is an Expansion board with pin 9 wired to pin 10.
Test code transmits N bytes, reads N bytes and bails when receive data is inconsistent.

Test code:

def uart_buffer_test():
    '''uart buffer test function'''

    uart = machine.UART(
        1, baudrate=9600, bits=8, parity=None, stop=1, pins=('P9', 'P10'))

    tx_start = 32
    tx_stop = 8192
    tx_step = 32
    tx_buffer = bytearray('')

    # create data block
    block_end = tx_stop / 2
    block = bytearray('')
    for num in range(1, block_end):
        block += num.to_bytes(2, 'big')

    # multiple blocks
    for num in range(tx_stop / len(block)):
        tx_buffer += block

    try:
        for size in range(tx_start, tx_stop, tx_step):
            rx_data = bytearray('')
            tx_data = bytearray('')
            # send data
            tx_data = tx_buffer[0:size]
            written = uart.write(tx_data)

            time.sleep(1)

            # receive data
            rx_data = uart.read(len(tx_data))
            #test
            #rx_data = tx_buffer[0:size]
            #rx_data = rx_data[0:3] + b'\00' + rx_data[4:]

            # compare data
            if not rx_data == tx_data:
                print('Error sending ', size, ' bytes')
                if rx_data:
                    print('Sent ', written, ' received ', len(rx_data),
                        ' bytes')
                    error = 0
                    for index, _ in enumerate(rx_data):
                        if rx_data[index] != tx_data[index]:
                            error = index
                            break
                    print('First error at offset ', error)
                    print('Tail expected \r\n', tx_data[error:])
                    print('Tail received \r\n', bytearray(rx_data[error:]))
                    break
                else:
                    print('Sent ', written, ' received no bytes')
            else:
                print('Sent and received ', size, ' bytes')

    except Exception as ex:  # pylint: disable=broad-except
        print('exception ', ex)

Test output:

Sent and received  32  bytes
Sent and received  64  bytes
[snip]
Sent and received  672  bytes
Sent and received  704  bytes
Error sending  736  bytes
Sent  736  received  607  bytes
First error at offset  600
Tail expected
bytearray(b'\x01-\x01.\x01/\x010\x011\x012\x013\x014\x015\x016\x017\x018\x019\x01:\x01;\x01<\x01=\x01>\x01?\x01@\x01A\x01B\x01C\x01D\x01E\x01F\x01G\x01H\x01I\x01J\x01K\x01L\x01M\x01N\x01O\x01P\x01Q\x01R\x01S\x01T\x01U\x01V\x01W\x01X\x01Y\x01Z\x01[\x01\\\x01]\x01^\x01_\x01`\x01a\x01b\x01c\x01d\x01e\x01f\x01g\x01h\x01i\x01j\x01k\x01l\x01m\x01n\x01o\x01p')
Tail received
bytearray(b'm\x01n\x01o\x01p')

Metadata

Metadata

Assignees

Labels

InvestigateProblem needs more investigation

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions