8000 UART receive buffer full · Issue #300 · pycom/pycom-micropython-sigfox · GitHub
[go: up one dir, main page]

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

UART receive buffer full #300

Closed
davesto opened this issue May 10, 2019 · 1 comment
Closed

UART receive buffer full #300

davesto opened this issue May 10, 2019 · 1 comment
Assignees
Labels
Investigate Problem needs more investigation

Comments

@davesto
Copy link
davesto commented May 10, 2019

(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')
@iwahdan88 iwahdan88 added the Investigate Problem needs more investigation label May 29, 2019
iwahdan88 pushed a commit that referenced this issue Jul 15, 2019
### New Features
- Adding CoAp Micropython module
- Disable RGBLED functionality with Makefile switch RGB_LED=disable

### Improvments
- Updated pycom.nvs_get to support return of a predefined `NoExistValue` for unmatched Keys
- PYFW-104: Add timestamp metadata to files and folders
- Updated modlte
- [PYFW-86] Implement Fallback to Wifi when lte is disconnected
- [PYFW-214] Increase App partition Size For FIPy, GPy and LoPy4 to 1980K
- [PYFW-344] Refactor BLE
- Lorawan: Added support for the CN470 region

### Bug Fixes
- PYFW-348: Make RX buffer of machuart module configurable #300
@iwahdan88
Copy link
Contributor
iwahdan88 commented Aug 6, 2019

@davesto The MACHUART_RX_BUFFER_LEN is set to 512 in the development firmware starting from v1.20.0.rc0 and you are using v1.20.0.rc8 so I believe the UART Rx buffer is filled at 512 , however as of v1.20.0.rc12, we made the rx buffer size configurable via Micropython see 81167ed.
so please try testing with

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

on v1.20.0.rc12.1 and see if that fixes the problem.

Thanks

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Investigate Problem needs more investigation
Projects
None yet
Development

No branches or pull requests

3 participants
0