usb3sun icon indicating copy to clipboard operation
usb3sun copied to clipboard

support debug logging without disabling sun keyboard

Open delan opened this issue 2 years ago • 0 comments

unlike logging to usb cdc, logging to the debug header allows us to debug usb problems (CFG_TUSB_DEBUG), but this requires three uarts and the rp2040 only has two, so we currently disable the sun keyboard when doing so. wouldn’t it be nice if the debug header (tx + rx, but rx unused so far) could work without disabling the sun keyboard (tx + rx) or mouse (tx only)?

the good news is, SerialPIO allows us to set up a third uart, freeing up one of the hardware uarts for debugging. the docs say SoftwareSerial (and SerialPIO?) don’t support inverted mode, which are needed for the sun interfaces, but thankfully this is not (or no longer?) true.

to avoid running out of pio resources when beeping, we would need to go back to using analogWrite (hardware pwm) instead of tone (pio) for the buzzer (reverting 8922fe6f6ba269e96bbdb21e620982492abc54a7), but that’s ok.

the bad news is, there seems to be no way to actually do this without pcb changes. here are our requirements:

  • usb tx needs 1/4 sm and 22/32 instructions (usb_tx.pio)
  • usb rx needs 2/4 sm and 31/32 instructions (usb_rx.pio)
  • SerialPIO tx needs 1/4 sm and 6/32 instructions (pio_tx_inv, pio_tx_inv_program_instructions)
  • SerialPIO rx needs 1/4 sm and 7/32 instructions (pio_rx_inv, pio_rx_inv_program_instructions)
  • UART_TX wired to pin 0 (valid for UART0 or SerialPIO)
  • UART_RX wired to pin 1 (valid for UART0 or SerialPIO)
  • INT_KTX wired to pin 12 (valid for UART0 or SerialPIO)
  • INT_KRX wired to pin 13 (valid for UART0 or SerialPIO)
  • INT_MTX wired to pin 8 (valid for UART1 or SerialPIO)
  • debug console needs to be on a hardware UART?

if we move sun mouse tx to SerialPIO (and bump pio_cfg.sm_tx etc accordingly), both the sun and usb interfaces still work, and this frees up hardware UART1! but UART1 is not allowed on pins 0 + 1 (UART_TX + UART_RX).

if we move sun keyboard tx and rx to SerialPIO (and bump pio_cfg.sm_tx etc accordingly), we are guaranteed to run out of pio instruction space for usb, because 6+7+min(22,31)>32 and min(6,7)+max(22,31)>32.

if we move sun keyboard tx only to SerialPIO (and bump pio_cfg.sm_tx etc accordingly), we can free up hardware UART0 tx for debug logging! believe it or not, UART0 can be set to tx on pin 0 (UART_TX) and rx on pin 13 (INT_KRX)! but sharing it with the sun keyboard like this means we need to log at 1200 baud, which not only would need a modified picoprobe firmware, but is also extremely slow: it takes 80(!) seconds to boot usb3sun with all debug logging on.

so we have three options, unless there’s some way to run the debug console over SerialPIO:

  1. move sun mouse to SerialPIO, rewire UART_TX + UART_RX to pins valid for UART1
  2. move sun mouse to SerialPIO, move sun keyboard to UART1, rewire sun keyboard to pins valid for UART1
  3. do nothing, at least until we need a new pcb rev for some other reason

delan avatar Dec 09 '23 07:12 delan