anchor.diff:    then usb-pma! ;
   
   : usb-fill ( -- )  \ fill the USB outbound buffer from the TX ring buffer
  -  tx.pend @ 0= if
  -    usb-out-ring ring#
  -    ?dup if 64 min
  -      dup tx.pend !
  -      dup 0 do usb-out-ring ring> $C0 i + usb-pma-c!  loop
  -      1 1 ep-reg h! 1 3 txstat!
  -    then
  +  usb-out-ring ring# ?dup if
  +    dup tx.pend !
  +    dup 0 do usb-out-ring ring> $C0 i + usb-pma-c!  loop
  +    1 1 ep-reg h! 1 3 txstat!
     then ;
   
   : ep-out ( ep -- )  \ outgoing packets, sent from host to this device
  
positive.code:   $3003 3 ep-addr h!
    $80 USB-DADDR h! ;
  
  0 variable zero
  
  256 4 + buffer: usb-in-ring   \ RX ring buffer, ample for mecrisp input lines
   64 4 + buffer: usb-out-ring  \ TX ring buffer, for outbound bytes
  
negative.code: : usb-key? ( -- f )  pause usb-poll usb-in-ring ring# 0<> ;
  : usb-key ( -- c )  begin usb-key? until  usb-in-ring ring> ;
  : usb-emit? ( -- f )  usb-poll usb-out-ring ring? ;
  : usb-emit ( c -- )  begin usb-emit? until  usb-out-ring >ring
                       tx.pend @ 0= if usb-fill then ;
  
  : usb-io ( -- )  \ start up USB and switch console I/O to it
    23 bit RCC-APB1ENR bis!  \ USBEN
  