lancaster-university / codal-nrf52

MIT License
4 stars 15 forks source link

Serial baudrate 31250 omitted in NRF52Serial.cpp, MIDI broken on micro:bit v2 #38

Closed CaptainCredible closed 1 year ago

CaptainCredible commented 2 years ago

31250 baud is required for sending MIDI via a 5pin MIDI din

Although the enums for the makecode blocks allow you to set the baudrate to 31250 for the serial communication, doing so on microbit V2, will result in the baudrate being set to 115200. This breaks MIDI output to hardware devices, and breaks the microsoft/pxt-MIDI extension. This is seemingly because a case for 31250 is omitted in lines 196 to 205 in the file NRF52Serial.cpp:

switch(baudrate) { case 9600 : baud = NRF_UARTE_BAUDRATE_9600; break; case 38400 : baud = NRF_UARTE_BAUDRATE_38400; break; case 57600 : baud = NRF_UARTE_BAUDRATE_57600; break; case 115200 : baud = NRF_UARTE_BAUDRATE_115200; break; case 230400 : baud = NRF_UARTE_BAUDRATE_230400; break; case 921600 : baud = NRF_UARTE_BAUDRATE_921600; break; case 1000000 : baud = NRF_UARTE_BAUDRATE_1000000; break; }

The SDK for NRF52 does suggest support for 31250 baud:

/* @brief Baudrates supported by UARTE. / typedef enum { NRF_UARTE_BAUDRATE_1200 = UARTE_BAUDRATE_BAUDRATE_Baud1200, ///< 1200 baud. NRF_UARTE_BAUDRATE_2400 = UARTE_BAUDRATE_BAUDRATE_Baud2400, ///< 2400 baud. NRF_UARTE_BAUDRATE_4800 = UARTE_BAUDRATE_BAUDRATE_Baud4800, ///< 4800 baud. NRF_UARTE_BAUDRATE_9600 = UARTE_BAUDRATE_BAUDRATE_Baud9600, ///< 9600 baud. NRF_UARTE_BAUDRATE_14400 = UARTE_BAUDRATE_BAUDRATE_Baud14400, ///< 14400 baud. NRF_UARTE_BAUDRATE_19200 = UARTE_BAUDRATE_BAUDRATE_Baud19200, ///< 19200 baud. NRF_UARTE_BAUDRATE_28800 = UARTE_BAUDRATE_BAUDRATE_Baud28800, ///< 28800 baud. NRF_UARTE_BAUDRATE_31250 = UARTE_BAUDRATE_BAUDRATE_Baud31250, ///< 31250 baud. NRF_UARTE_BAUDRATE_38400 = UARTE_BAUDRATE_BAUDRATE_Baud38400, ///< 38400 baud. NRF_UARTE_BAUDRATE_56000 = UARTE_BAUDRATE_BAUDRATE_Baud56000, ///< 56000 baud. NRF_UARTE_BAUDRATE_57600 = UARTE_BAUDRATE_BAUDRATE_Baud57600, ///< 57600 baud. NRF_UARTE_BAUDRATE_76800 = UARTE_BAUDRATE_BAUDRATE_Baud76800, ///< 76800 baud. NRF_UARTE_BAUDRATE_115200 = UARTE_BAUDRATE_BAUDRATE_Baud115200, ///< 115200 baud. NRF_UARTE_BAUDRATE_230400 = UARTE_BAUDRATE_BAUDRATE_Baud230400, ///< 230400 baud. NRF_UARTE_BAUDRATE_250000 = UARTE_BAUDRATE_BAUDRATE_Baud250000, ///< 250000 baud. NRF_UARTE_BAUDRATE_460800 = UARTE_BAUDRATE_BAUDRATE_Baud460800, ///< 460800 baud. NRF_UARTE_BAUDRATE_921600 = UARTE_BAUDRATE_BAUDRATE_Baud921600, ///< 921600 baud. NRF_UARTE_BAUDRATE_1000000 = UARTE_BAUDRATE_BAUDRATE_Baud1M ///< 1000000 baud. } nrf_uarte_baudrate_t;

microbit-carlos commented 1 year ago

This was fixed with PR https://github.com/lancaster-university/codal-nrf52/pull/39, thanks @CaptainCredible!