Skip to content

Teensy 3.6 USB CDC #1223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/machine/board_teensy36.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,24 @@ func CPUFrequency() uint32 { return 180000000 }
// ClockFrequency returns the frequency of the external oscillator (16MHz)
func ClockFrequency() uint32 { return 16000000 }

const (
usb_STRING_MANUFACTURER = "Teensy"
usb_STRING_PRODUCT = "Teensy 3.6 USB Serial"

usb_DEVICE_CLASS = 0x02
usb_DEVICE_SUBCLASS = 0
usb_DEVICE_PROTOCOL = 0

usb_EP0_SIZE = 64
usb_BUFFER_SIZE = usb_EP0_SIZE

usb_VID = 0x16C0
usb_PID = 0x0483 // teensy usb serial
usb_BCD_DEVICE = 0x0277 // teensy 3.6
)

var usb_STRING_SERIAL string

// LED on the Teensy
const LED = PC05

Expand Down Expand Up @@ -99,3 +117,17 @@ const (
defaultUART4RX = D34
defaultUART4TX = D33
)

//go:linkname sleepTicks runtime.sleepTicks
func sleepTicks(int64)

func InitPlatform() {
// for background about this startup delay, please see these conversations
// https://forum.pjrc.com/threads/36606-startup-time-(400ms)?p=113980&viewfull=1#post113980
// https://forum.pjrc.com/threads/31290-Teensey-3-2-Teensey-Loader-1-24-Issues?p=87273&viewfull=1#post87273

sleepTicks(25 * 1000) // 50 for TeensyDuino < 142
// usb_STRING_SERIAL = readSerialNumber()
USB0.Configure()
sleepTicks(275 * 1000) // 350 for TeensyDuino < 142
Comment on lines +125 to +132
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason not to include this directly in postinit? It's not like you're supposed to call InitPlatform (except for the runtime).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought I would leave room for non-Teensy boards that are based on the NXP MK66F18. I believe these delays are more related to how the Teensy programmer detects boards than to the chip itself.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. So the function is only intended to be called from the runtime but put in the machine package because it is board specific? In that case, it would be useful to add a comment explaining that, so that it's clear this function isn't supposed to be called elsewhere.

}
18 changes: 15 additions & 3 deletions src/machine/usb.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build sam nrf52840
// +build sam nrf52840 nxp,mk66f18

package machine

Expand All @@ -7,13 +7,20 @@ import (
"runtime/volatile"
)

const deviceDescriptorSize = 18

var (
errUSBCDCBufferEmpty = errors.New("USB-CDC buffer empty")
errUSBCDCWriteByteTimeout = errors.New("USB-CDC write byte timeout")
)

type USBEndpointConfiguration struct {
Transmit bool
Receive bool
Handshake bool
DisableSetup bool
}

const deviceDescriptorSize = 18

// DeviceDescriptor implements the USB standard device descriptor.
//
// Table 9-8. Standard Device Descriptor
Expand Down Expand Up @@ -552,6 +559,11 @@ func newUSBSetup(data []byte) usbSetup {
return u
}

//go:inline
func (u usbSetup) wValue() uint16 {
return uint16(u.wValueH)<<8 | uint16(u.wValueL)
}

// USBCDC is the serial interface that works over the USB port.
// To implement the USBCDC interface for a board, you must declare a concrete type as follows:
//
Expand Down
Loading