-
Notifications
You must be signed in to change notification settings - Fork 501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable custom UART baudrate for nRF52 #712
base: master
Are you sure you want to change the base?
Conversation
though nRF52 platform supported csutom baudrated for UART, it was supported in the uart.cpp core driver. It is enabled to support the same in this patchset
Sorry for late response, I have been busy before and after the TET with lots of other works. This PR is great update. However, we still need some tweak to get it right. Here is the sketch and its output result
The compute function in this PR used the suggestion by nordic employee here https://devzone.nordicsemi.com/f/nordic-q-a/391/uart-baudrate-register-values |
The pre-computed values are also slightly different e.g 14401 instead of 14400. Since the default values are used by most of other user, using different baud register can cause drift e.g when communicating with other nrf board via uart running pre-computed value. Could you mind explaining why would you need a custom baudrate ? and specifically which value that you need. #define UARTE_BAUDRATE_BAUDRATE_Pos (0UL) /*!< Position of BAUDRATE field. */
#define UARTE_BAUDRATE_BAUDRATE_Msk (0xFFFFFFFFUL << UARTE_BAUDRATE_BAUDRATE_Pos) /*!< Bit mask of BAUDRATE field. */
#define UARTE_BAUDRATE_BAUDRATE_Baud1200 (0x0004F000UL) /*!< 1200 baud (actual rate: 1205) */
#define UARTE_BAUDRATE_BAUDRATE_Baud2400 (0x0009D000UL) /*!< 2400 baud (actual rate: 2396) */
#define UARTE_BAUDRATE_BAUDRATE_Baud4800 (0x0013B000UL) /*!< 4800 baud (actual rate: 4808) */
#define UARTE_BAUDRATE_BAUDRATE_Baud9600 (0x00275000UL) /*!< 9600 baud (actual rate: 9598) */
#define UARTE_BAUDRATE_BAUDRATE_Baud14400 (0x003AF000UL) /*!< 14400 baud (actual rate: 14401) */
#define UARTE_BAUDRATE_BAUDRATE_Baud19200 (0x004EA000UL) /*!< 19200 baud (actual rate: 19208) */
#define UARTE_BAUDRATE_BAUDRATE_Baud28800 (0x0075C000UL) /*!< 28800 baud (actual rate: 28777) */
#define UARTE_BAUDRATE_BAUDRATE_Baud31250 (0x00800000UL) /*!< 31250 baud */
#define UARTE_BAUDRATE_BAUDRATE_Baud38400 (0x009D0000UL) /*!< 38400 baud (actual rate: 38369) */
#define UARTE_BAUDRATE_BAUDRATE_Baud56000 (0x00E50000UL) /*!< 56000 baud (actual rate: 55944) */
#define UARTE_BAUDRATE_BAUDRATE_Baud57600 (0x00EB0000UL) /*!< 57600 baud (actual rate: 57554) */
#define UARTE_BAUDRATE_BAUDRATE_Baud76800 (0x013A9000UL) /*!< 76800 baud (actual rate: 76923) */
#define UARTE_BAUDRATE_BAUDRATE_Baud115200 (0x01D60000UL) /*!< 115200 baud (actual rate: 115108) */
#define UARTE_BAUDRATE_BAUDRATE_Baud230400 (0x03B00000UL) /*!< 230400 baud (actual rate: 231884) */
#define UARTE_BAUDRATE_BAUDRATE_Baud250000 (0x04000000UL) /*!< 250000 baud */
#define UARTE_BAUDRATE_BAUDRATE_Baud460800 (0x07400000UL) /*!< 460800 baud (actual rate: 457143) */
#define UARTE_BAUDRATE_BAUDRATE_Baud921600 (0x0F000000UL) /*!< 921600 baud (actual rate: 941176) */
#define UARTE_BAUDRATE_BAUDRATE_Baud1M (0x10000000UL) /*!< 1Mega baud */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR generate different value than the pre-computed in the bit-field. It is close enough, and may or may not cause the issue. But I would rather stay on the safe side. Please let me know why would you need the custom baud in the first place. If there is a good reason behind, we would find an way to fit this in.
Hello @hathach , There are multiple reason that I would want to submit this change:
https://github.com/adafruit/Adafruit_nRF52_Arduino/blob/master/cores/nRF5/Uart.cpp:
https://github.com/NordicSemiconductor/nrfx/blob/master/mdk/nrf52_bitfields.h:
With my patchset all the values are matching as per definition of nrf52_bitfields.h.
Please let me know if you have any other concerns in the commit. |
super late response, due to various reason. Custom baudrate is great to have, however, common value still need to use the stock one from nordic defines. |
Though nRF52 platform supported csutom baudrated for UART,
it was supported in the uart.cpp core driver. It is enabled
to support the same in this patchset