2025-01-28 06:45 AM - last edited on 2025-01-28 08:02 AM by SofLit
Moved from the Feedback forum. Please don't post product questions in the Feedback forum.
Recently I have been working on a simple gamepad-like controller using stm32 (link) since this is a hobby project I wanted to learn how to use USB from first principles, given that I only have some basic understanding on how USB works and wanted to improve on that.
Unfortunately I have run into, what seems like, a massive drought of information regarding this topic (implementing usb from scratch on embedded), yes, there's this fantastic example I found (link) and was able to follow while referencing the manual and learning more about USB on embedded, unfortunately I have run into issues regarding Windows OS not being able to read/recognize the USB device. I don't know what exactly is the problem with my usb code (link), but I think I have narrowed it down, it seems to be something with the packets, device request is being sent 4 times, all with different sizes (64, 64, 18, 64 bytes). At first I thought it could be something with fifo-copying but that wasn't it, so I think it might actually be something with interrupts?
When it comes to embedded I have very limited knowledge, I _do know_ a fair bit about USB, although not as much as I'd like hence the project. If someone more experienced could look into the code (link) and help me piece together what is actually going on I'd be greatful. Also, before someone says it, I am aware that STM32CubeIDE exists and I have implemented this exact project in it, however I really do want to implement this from scratch, I did try to follow their code but it's a little obfuscated below layers and layers of call stack.
(1) Board I'm using: STM32F401CCU6 (84 Mhz) (link), reference manual in the linked repo (link) as well.
(2) The bug happens immediately, right after hitting the first breakpoint (link) in USB Device/Descriptor Request.
(3) Wireshark on windows won't let me monitor invalid devices, can't even try to monitor it as 'new plugged in device'
2025-01-28 08:50 AM - edited 2025-01-28 08:51 AM
In usb_init_periph() USB registers are accessed before enabling the OTG peripheral - definitely an error. Also, usb_init_device() is quite different from a known working stuff.