r/stm32 • u/johhuang12138 • Jan 31 '21
Why is it so difficult to develop USB using HAL libraries
I'm a Python engineer. I wanted to develop hardware, and I wanted to make some creative computer peripherals. However, the library using STM32 is too complex
2
u/johhuang12138 Jan 31 '21
The development board I use is Bluepill, and the chip is F103C8T6
3
u/thekakester Jan 31 '21
Start here: video #2 should help with the learning curve.
https://youtube.com/playlist?list=PLNyfXcjhOAwO5HNTKpZPsqBhelLF2rWQx
1
u/johhuang12138 Feb 03 '21
Guys, I've got it. The USB mouse program I wrote before can't be recognized when plugged into the computer.I found out yesterday that the reason was that I plugged in the USB without power off after download the program.
It turned out that after download the program, I had to power off and reconnect the USB to power on so that it could be recognized by the computer.
1
u/johhuang12138 Feb 03 '21
Thank you very much for your encouragement and suggestions, I have compiled the program according to some examples. Although I can't understand the USB protocol deeply, I can realize the basic mouse and keyboard program.
1
u/johhuang12138 Feb 03 '21
This is my work. It's kind of silly
1
u/krgoodwin Feb 03 '21
Cool, glad you got it working. What's the plan? MIDI stuff?
1
u/johhuang12138 Feb 04 '21
It's just the keyboard right now. I'll add MIDI functionality after I learn about the MIDI protocol.
1
u/Aggressive_Doughnut Feb 01 '21
"Why is it so difficult to develop USB using any real* SDK?"
There fixed it for you.
The answer is that USB can do so much. No, really, SO SO much. Much more than you think it can. So even the clearest API needs to be incredibly flexible to accommodate the insane variety of possibilities. The SDK creator doesn't make an API just to make it easy to send a key stroke. Unfortunate for you, but true.
I recommend looking through the examples that come with cube mx. I'm on the road and can't easily look through them to tell you which one to use, but I modified an ST example for my first USB HID device and it worked out very well.
Good luck, and be patient!
*In this context "real" means a (usually C-based) SDK from the platform developer. There are plenty of third party libraries/environments/etc that offer simplified APIs for beginners to accomplish the most common tasks. Keep in mind that there are reasons that these aren't commonly used in professional development.
1
u/johhuang12138 Feb 02 '21
Very good advice, I found the direction. As for example, I have found a user manual. Is this the example you said?
1
u/johhuang12138 Feb 02 '21
Sorry, I don't know how to upload pictures on my phone through the Reddit app
1
u/Aggressive_Doughnut Feb 02 '21
That's where I would begin for building new projects for interfaces and peripherals I don't already know well. However when you are just starting out with something, it can be even easier to modify a working example. Here's a source for official ST USB examples on STM32F4 MCUs: https://github.com/STMicroelectronics/STM32CubeF4/tree/master/Projects/STM32446E_EVAL/Applications/USB_Device
You would have to modify this to work on your board by changing the pins for the buttons or LEDs or whatever. There are other boards and examples in that GitHub and on other places via the ST website. Spend some time looking through them, seeing how they work and which functions they call, reading the documentation for those fictions, etc. Example code can get you started quickly, it's one of the reasons they can sell those $200 demo/eval boards. It's much faster to get started on a product when you already have some working code to modify.
0
7
u/hawhill Jan 31 '21
What exactly are you asking us for?