3.4.5 Advanced Use
CDC Override Mode
In ordinary operation, the on-board debugger is a true UART bridge between the host and the device. However, in certain use cases, the on-board debugger can override the basic Operating mode and use the CDC TX and RX pins for other purposes.
Dropping a text file into the on-board debugger’s mass storage drive can send characters out of the debugger’s CDC TX pin. The file name and extension are trivial, but the text file will start with the characters:
CMD:SEND_UART=
Debugger firmware version 1.20 or earlier has the following limitations:
- The maximum message length is 50 characters – all remaining data in the frame are ignored.
- The default baud rate used in this mode is 9600 bps, but if the CDC is already active or configured, the previously used baud rate still applies.
Debugger firmware version 1.21 and later has the following limitations/features:
- The maximum message length will vary depending on the MSC/SCSI layer timeouts on the host computer and/or operating system. A single SCSI frame of 512 bytes (498 characters of payload) is ensured, and files up to 4 KB will work on most systems. The transfer will be completed on the first NULL character encountered in the file.
- The baud rate used is always 9600 bps for the default
command:
CMD:SEND_UART=
- Do not use the CDC Override mode simultaneously with data transfer over the CDC/terminal. If a CDC terminal session is active when receiving a file via the CDC Override mode, it will be suspended for the duration of the operation and resumed once complete.
- Additional commands are supported with explicit baud
rates:
CMD:SEND_9600=
CMD:SEND_115200=
CMD:SEND_460800=
USB-Level Framing Considerations
Sending data from the host to the CDC can be done byte-wise or in blocks, chunked into 64-byte USB frames. Each frame will be queued for transfer to the debugger’s CDC TX pin. Sending a small amount of data per frame can be inefficient, particularly at low baud rates, as the on-board debugger buffers frames but not bytes. A maximum of four 64-byte frames can be active at any time. The on-board debugger will throttle the incoming frames accordingly. Sending full 64-byte frames containing data is the most efficient method.
When receiving data on the debugger’s CDC RX pin, the on-board debugger will queue up the incoming bytes into 64-byte frames, which are sent to the USB queue for transmission to the host when are full. Incomplete frames are pushed to the USB queue at approximately 100 ms intervals, triggered by USB start-of-frame tokens. Up to eight 64-byte frames can be active at any time.
An overrun will occur if the host (or the software running) fails to receive data fast enough. When this happens, the last-filled buffer frame recycles instead of being sent to the USB queue, and a complete data frame will be lost. To prevent this occurrence, the user will ensure that the CDC data pipe is continuously read, or the incoming data rate will be reduced.
Sending Break Characters
The host can send a UART break character to the device using the CDC, which can be useable for resetting a receiver state-machine or signaling an exception condition from the host to the application running on the device.
A break character is a sequence of at least 11 zero bits transmitted from the host to the device.
Not all UART receivers have support for detecting a break, but a correctly-formed break character usually triggers a framing error on the receiver.
Sending a break character using the debugger's CDC has the following limitations:
- Sending a break will cause any data being sent to be lost. Be sure to wait a sufficient amount of time to allow all characters in the transmission buffer to be sent (see above section) before sending the break, which is in line with expected break character usage. For example, reset a receiver state-machine after a timeout occurs waiting for returning data to the host.
- The CDC specification allows for debugger-timed breaks of up to 65534 ms in duration to be requested. For simplicity, the debugger will limit the break duration to a maximum of 11 bit durations at its minimum supported baud rate.
- The CDC specification allows for indefinite host-timed breaks. It is the terminal application/user's responsibility to release the break state in this case.