Skip to content

Commit

Permalink
implement tud_cdc_line_coding_cb
Browse files Browse the repository at this point in the history
This handles changing the UART baud rate.
Or rebooting as soon as the baud 1200 is specified
  • Loading branch information
josuah committed Apr 20, 2024
1 parent 8e92021 commit 8d0fd06
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/ice_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "hardware/gpio.h"
#include "hardware/uart.h"
#include "hardware/watchdog.h"
#include "pico/bootrom.h"
#include "pico/multicore.h"
#include "pico/stdlib.h"

Expand Down Expand Up @@ -307,6 +308,31 @@ void (*tud_cdc_rx_cb_table[CFG_TUD_CDC])(uint8_t) = {
#endif
};

void tud_cdc_line_coding_cb(uint8_t itf, cdc_line_coding_t const *coding)
{
printf("%s: coding=%p baud=%d\n", __func__, coding, coding->bit_rate);

/* Mimick the Arduino reboot signal:
* https://arduino.github.io/arduino-cli/dev/platform-specification/#1200-bps-bootloader-reset */
if (coding->bit_rate == 1200) {
reset_usb_boot(0, 0);
assert(!"not reached");
}

switch (itf) {
#ifdef ICE_USB_UART0_CDC
case ICE_USB_UART0_CDC:
uart_set_baudrate(uart0, coding->bit_rate);
break;
#endif
#ifdef ICE_USB_UART1_CDC
case ICE_USB_UART1_CDC:
uart_set_baudrate(uart1, coding->bit_rate);
break;
#endif
}
}

#if ICE_USB_UART0_CDC || ICE_USB_UART1_CDC || ICE_USB_FPGA_CDC || ICE_USB_SPI_CDC

void tud_cdc_rx_cb(uint8_t cdc_num)
Expand Down

0 comments on commit 8d0fd06

Please sign in to comment.