What does baudrate mean in Serial.begin (for USB)

I was looking through the firmware code for the USB Serial device and this is what I see in the call back function that handles the setting of the baud rate.

void system_lineCodingBitRateHandler(uint32_t bitrate)
{
#ifdef START_DFU_FLASHER_SERIAL_SPEED
    if (bitrate == start_dfu_flasher_serial_speed)
    {
        //Reset device and briefly enter DFU bootloader mode
        System.dfu(false);
    }
#endif
#ifdef START_YMODEM_FLASHER_SERIAL_SPEED
    if (!network_listening(0, 0, NULL) && bitrate == start_ymodem_flasher_serial_speed)
    {
        //Set the Ymodem flasher flag to execute system_serialFirmwareUpdate()
        set_ymodem_serial_flash_update_handler(Ymodem_Serial_Flash_Update);
        RGB.control(true);
        RGB.color(RGB_COLOR_MAGENTA);
        SPARK_FLASH_UPDATE = 3;
        TimingFlashUpdateTimeout = 0;
    }
#endif
}

So I can readily believe that the baud rate is ignored for the purposes of hardware, as USB serial doesn’t really have a baud rate. However, it looks like instead this parameter has been usurped as two sentinel values to either enter DFU mode or do something else which is for flashing the firmware. These two values are 14400 and 28800 respectively. Seems like some unwitting programmer who tries to set their USB serial to one of these two values is going to get a behavior much different than they asked for.

Am I reading this code right? I really should try this, but my only Photon is in use.

@rvnash, you are correct. Setting the port to 14400 baud will cause the Photon to go into DFU mode while 28800 will allow a YMODEM download of firmware. It should be documented (!)

1 Like