Adds new error message for SAMD busio UART RX buffer size#3902
Adds new error message for SAMD busio UART RX buffer size#3902AdamCummick wants to merge 0 commit into
Conversation
|
Thanks for noticing this. I think we should explore the causation behind the error: whether SAMD actually requires this or we are doing something wrong somewhere. We suggest creating a branch in your forked repo, instead of changing your own |
dhalbert
left a comment
There was a problem hiding this comment.
See non-review comment as well.
| } | ||
|
|
||
| if (receiver_buffer_size % 4 != 0) { | ||
| mp_raise_msg_varg(&mp_type_ValueError, translate("Invalid RX buffer size of %d, must be a multiple of 4"), receiver_buffer_size); |
There was a problem hiding this comment.
This is a long message, and we need to save space. We don't need to print out the input argument, so I'd suggest this (using the argument name in shared-bindings/busio/UART.c):
| mp_raise_msg_varg(&mp_type_ValueError, translate("Invalid RX buffer size of %d, must be a multiple of 4"), receiver_buffer_size); | |
| mp_raise_ValueErorr( translate("receiver_buffer_size must be a multiple of 4"), receiver_buffer_size); |
It looks like it's based on the requirements of the ATMEL hal ringbuffer: https://github.com/adafruit/asf4/blob/84f56af13292d8f32c40acbd949bde698ddd4507/samd51/hal/utils/src/utils_ringbuffer.c#L53 Looks like my assumptions were wrong anyhow, power of 2 instead of multiples of 4. |
We might consider rounding up to the nearest power of 2, and changing the documentation to note that the buffer size might be bigger. And/or noting that some platforms might have specific requirements. |
Raises an error when a busio UART "receiver_buffer_size" is not a multiple of 4. Behavior referenced in issue #3901 and tested using same setup: SAMD51 and CircuitPython 6.0.0
Example:
Will raise an error with the message:
ValueError: Invalid RX buffer size of 5, must be a multiple of 4