-
Notifications
You must be signed in to change notification settings - Fork 909
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
Teensy 3.6 USB CDC #1223
base: dev
Are you sure you want to change the base?
Teensy 3.6 USB CDC #1223
Conversation
At one point, it looked like this version was working. Or at least I was seeing far more log messages from the USB ISR. But now it doesn't get past the device descriptor:
Except now, I'm not even getting that... All I get is "usb done" (indicating that @deadprogram @aykevl Any ideas? As far as I can tell, things are failing early enough that Wireshark doesn't see anything. |
6e47b80
to
06c1568
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I never worked directly with USB-CDC so I don't think I can help you much debugging it, unfortunately.
(one quick comment below, I haven't really looked through the code)
// 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 |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand the purpose of this PR. It doesn't seem to implement USB-CDC support, so what does it add in functionality?
// 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 |
There was a problem hiding this comment.
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.
"unsafe" | ||
) | ||
|
||
const debugUSB = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this intentional? It looks like it should be false
.
|
||
import ( | ||
"device/nxp" | ||
"fmt" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't import fmt in the machine package. This is a huge dependency with a large dependency graph and importing it in the machine package may lead to circular dependencies. It also bloats the binary and increases compile time.
Instead, I would suggest to use println
for debugging (and disabled by default).
slice := (*reflect.SliceHeader)(unsafe.Pointer(&data)) | ||
|
||
*bde.retain = data | ||
bde.record.address.Set(uint32(slice.Data)) | ||
bde.Describe(uint32(slice.Len), data1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reflect package is a relatively large dependency and shouldn't be used in the machine package. It is also possible to do without in this case:
slice := (*reflect.SliceHeader)(unsafe.Pointer(&data)) | |
*bde.retain = data | |
bde.record.address.Set(uint32(slice.Data)) | |
bde.Describe(uint32(slice.Len), data1) | |
*bde.retain = data | |
bde.record.address.Set(uint32(uintptr(unsafe.Pointer(&data[0])))) | |
bde.Describe(len(data), data1) |
slice := (*reflect.SliceHeader)(unsafe.Pointer(&data)) | ||
slice.Len = uintptr(length) | ||
slice.Cap = uintptr(length) | ||
slice.Data = uintptr(bde.record.address.Get()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does bde.record.address
come from? I'm guessing it is some sort of DMA buffer, did you put it in a global somewhere (for example) to make sure it is not garbage collected?
I think it would be much better to somehow keep the original slice around and use that, to avoid some unsafe code.
Log []string | ||
} | ||
|
||
func (u *USB) logf(format string, args ...interface{}) { | ||
u.Log = append(u.Log, fmt.Sprintf(format, args...)) | ||
} | ||
|
||
func (u *USB) debugf(format string, args ...interface{}) { | ||
if debugUSB { | ||
u.logf(format, args...) | ||
} | ||
} | ||
|
||
func (u *USB) DumpLog() []string { | ||
var log []string | ||
|
||
state := interrupt.Disable() | ||
log, u.Log = u.Log, nil | ||
interrupt.Restore(state) | ||
|
||
if log == nil { | ||
return []string{} | ||
} | ||
return log | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like debug code. While functions that aren't called won't take up extra space (they get optimized away), the Log
buffer cannot be optimized away. Maybe you can make it a separate global (separate from the USB
type) if you want to keep it?
Handshake: true, | ||
}) | ||
|
||
// clear all ending interrupts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo?
// clear all ending interrupts | |
// clear all pending interrupts |
} | ||
|
||
func (u USBCDC) WriteByte(byte) { | ||
panic("not implemented") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems strange, you implement a USBCDC
type that doesn't actually work?
usb_TOK_PID_SETUP = 0xD | ||
) | ||
|
||
type register8Aligned32 struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to be clear, this struct is not aligned on a 32-bit (4 byte) boundary. It is still 8 bit aligned but simply takes up four bytes. Was this intentional?
USB CDC support for Teensy 3.6 (NXP MK66F18)