Thanks Hugatry, that's a wonderful video! I needed to learn how to do USB and this taught me instantly. It worked right out, with no compile error (I am using Atollic TrueStudio). One subtlety: When I subsequently implemented it in my own project hardware (STM32F446), it still worked EXCEPT that the terminal text was always "LED 0" (number 0, not letter O), rather than "LED ON" or "LED OFF". It didn't worry me TOO much since I won't really use USB in the same way as this simple test, in my project - but it did worry me a bit because it's not nice to leave little mysteries sleeping in code. I couldn't understand why that worked on the Blue Pill but not on my STM32F446. So I asked my good STM32-expert friend, who replied: "Your unsigned char data[] = "LED ON" will be created on the stack at run-time, and will only exist until execution leaves the 'if {} else {}' construct. But the USB message will only get sent some time later when the USB stack runs ... but which time it is very likely that the text on the stack will have been over-written. This is a rather obscure version of the classic (and extremely common bug) caused by passing a pointer to an automatic variable back *up* to the calling function." And so it does indeed turn out to be! When I replace the line with the CDC_Transmit_FS call with (for example): CDC_Transmit_FS((uint8_t *)"LED ON", 6); Then everything works as it should, I get "LED ON", "LED OFF" as I should. Just a minor comment in case it helps somebody... Many thanks again for the great video! Hans qrp-labs.com
Hello! I'm using Atollic TrueStudio too. I would like to ask how should I manage Run Configuration as there is no Ac6 STM32 Debugging option in TrueStudio.
Very nice video. In case some people have missed it, in order to make the USB work, CubeMX adjusted the board's clock to 48 MHz (as seen at 3:04 in the video). This adjustment is not optimal. If PLLMul and USB Prescaler are set at x9 and /1.5, respectively, the USB clock will still run at the required standard of 48 MHz, but the board clock (HCLK) will be at the full 72 MHz. For many applications this might not matter (it might even be desired for low power consumption), but in general, one should run the board at the designed 72 MHz. As a final note, my version of CubeMX runs the clock optimization with the 72 MHz HCLK, so for newer CubeMX versions this might not be an issue at all. At least it looks like ST is putting resources into making CubeMX better.
How funny. I just wrote the same code and found a few things were non-obvious. Wish I'd seen your video first! I am going to post some of my code on HaD at some point and I have a reasonable circular buffer for the receiver part. Great job on the video!
Thanks! Few things were indeed non-obvious. I hope this video will be helpful to some who are doing this for the first time. This could be a real time saver, especially if one doesn't know where to start. Looking forward to seeing that code of yours!
4 года назад
Very nice step-by-step explanation. It worked well! Thank you!
Great video! I've been struggling to get ST-Link V2 and source code debugging (OpenOCD) to work from within SW4STM32 eclipse IDE for several days now, finally managed to get it working thanks to this video. The two main items I've been missing all along were - 1) enabling SWD in CubeMX, and 2) manually editing the reset line in the .cfg file. Thanks!
A very nice upload, lods of research done by you but i need some more detailed tutorials of advanced commands and builtin functions on cubemx. Do upload some more advanced tutorials👍
Tutorial starts fine but when it comes to the pin configuration thing after the clock setup at 3:07 my STM32CubeMX 6.1.0 doesn't match with your CubeMX. Under what version of STM32CubeMX are you running your tut?
Hi, thanks for the feedback. I don't remember the version number, but whatever it was, it's now at least 5 year old :). In the video I go to "Configuration" tab to setup the default state of the GPIO pin. I think in modern version of STM32CubeMX, if you are in pinout view and click "System view" above the pinout diagram, you'll end up in a similar configuration page. Alternatively, the list with all the available peripherals on the left now has "GPIO". You can click that and you'll end up with same GPIO configuration panel. I hope this helps.
STM CDC HOST (micro USB) -> OTG -> TTL I want to make the STM as CDC HOST and connect an OTG cable to STM, later connect an USB TTL to OTG. as TTL is Virtual comm. device. Can This work?? I am trying to simulate STM as host cdc. I am not able to get this to work. Can you please suggest what else can be done??
Hi, Thanks for detailed explanation. Quite useful..!I'm using TrueSTUDIO Toolchain/IDE. IDE is not detecting target (STM32F103C8T6). Do you suggest any recommended settings for TrueSTUDIO?I see only below 3 Debugger in TrueSTUDIO. What is work-around for this issue?1) ST-LINK2) SEGGER J-TRACE Cortex-M3) SEGGER J-LINK
CAN I use STM32103C8's USB and CAN bus at the same time ? I have transferred the CAN pins to PB9 and PB8 and using USB at PA12 and PA11. In a new project which I do not use CAN bus I am able to use USB. But in the project with CAN bus, PC does not recognize my device ?
Hi, Can I change to higher baud rate for example 115200. And what role of it exist in system? like one of UART? or separate CDC with special handling input/output method?
Thank you for your comment. And you are welcome! I spent way too many hours figuring this out and I'm glad my video helps others save time on such a simple task.
What is the full line that appears in the device manager? If you are using the project created by STM32CubeMX, with no other modifications than the cfg file and you have flashed it successfully, it should work. I'm wondering if the problem is missing drivers (If you are NOT running Windows 10, try drivers from first link in the description). More lines in the config file is probably OK. There have been some updates and there are some extra options that weren't there at the time of making this video.
Yes! I deleted my comment because I figured out that it was because the missing drivers, I was forgetting that. I just installed drivers and now it works. Again, thank you very much. Keep the awesome work.
I hadn't even thought about searching for drivers, because I've been running Win10 for a while and on Win10 the built-in drivers work just fine. Another commenter mentioned about the drivers couple of days ago and I added link in the description after that. Great to hear that you figured it out and solved the problem. Good luck with the project!
I have an error code 10 on my Virtual Com in Device Manager. I managed it to work one time but after i disconnect my usb and connect ST-Link programmator to flash new program it stops working and gives error code 10... i don't know what's the problem, it can be the USB cable but I tried on 2 cables and it still doesn't work. I'm using Win10.
You can flash an Arduino bootloader on it using a usb to serial adapter. After that you can program it through the micro usb port, but you have to use the Arduino IDE.
Autocompletion and other hints during editing: What is the IDE you are using? STM32CubeMX or STM32CubeProgrammer? I'm ondering how to get this feature as well under STM32CubeIDE? Does it require a certain File type or project type to be chosen?
Autocomplete/hints works in STM32CubeIDE by pressing CTRL+Space after typing something, or by waiting 0.5s after typing ".", "->" or "::". I am not sure if this is the case by default, but you can check settings by going to "Window" -> "Preferences" -> "C/C++" -> "Editor" -> "Content Assist".
As far as I understand, this video shows how to build a virtual serial port using the SMT32F103CT8T6 (blue pill) I'm wondering though, which pins of the STM32F103 now act as the (TTL) UART Interface to the outside world? From my understanding, the flashed program behaves like an FTDI Serial Dongle, doesn't it?
Sorry, missed this older comment. To compare what I am doing in this video to those FTDI dongles/chips, this project replaces an FTDI dongle between the PC and STM32. There are no RX and TX pins, because this will only get the data from the PC to the STM32 chip. This is to get data directly to the STM32 project, without external converter dongle/chip.
Thanks! When playing with these boards, I have always started by installing the IDE and using the HAL libraries. I don't know how to do it without installing the IDE. Sorry.
I was wondering if you have experimented with any of the other USB classes. I am struggling to get a usb hid working. I think I need to set the HID ID somewhere. The examples use USBD_HID_SendReport(&hUsbDeviceFS, buffer, 8); but this does not include the ID byte at the start of the report.
I remember creating HID gamepad a while back. But it was just a quick test and it was some time ago, so I don't remember what I did to make it work... I remember that I took the example, changed the report descriptor and variable that indicates the size of the report descriptor. But what else? I have no idea... Sorry, but I don't have any tips or tricks. But good luck! STM32F103 is great platform for custom HID gadgets and I hope you'll figure out how to make it work.
I modified a project from github for WB4STM32 and that seems to work. Now I can compare it with the source generated by Stm32Cube to see what needs to be altered for it to work.
i have problem with opening port in windows 10 but when i download stm vertual com port driver for windows 10 the issue was solved :) hope help anybody else
I get issue "Unknown USB Device (Device Descriptor Request Failed" in Device Manager. I run on Windows 10 and the STM32 Virtual COM Port Driver is installed.
Hello. I'm also having this problem with STM32. I have already uninstalled the driver, deactivated it, reinstalled it but it did not work. I have this problem also with the KL05Z board from NXP Semiconductors. Did you get any solutions to this problem?
Hello Hugatry, Thanks for the detailed work! :) I found your video after two days of tryings. Unfortunatelly it didn't solve my problem that my STM32F103RET6 controller can't be seed in the device manager at all (not even with the little yellow triangle). I took a breakpoint into USBD_CDC_Init() function but it's never called (the function is located in usbd_cdc.c file at line 475). Does your code stopped at this point? Thanks, Gabor
Hi, thanks for your comment! There is a 1.5kOhm pull-up resistor in the D+ line, which tells the host (computer) that USB-device has been connected. In the board shown in the video, that pull-up resistor is wired directly to 3.3V. Even if I don't program the board to be an USB-device, it will show in the device manager (with yellow triangle though). In your board that pull-up resistor is probably controlled with GPIO pin. I don't know which and how. If you have schematic for your board, that should tell you which pin it is and if not, you could take continuity meter and try "reverse engineering".
Hello, Thank you for the help. You were right, there is a tricky 1.5K pullup resistor that can be switched on with a GPIO. Now the CDC is fully functionable! :) Greetings, Gabor
I think both of them are great boards. STM32F103 is more powerful and has features that Nano doesn't have, like USB, DMA and better ADC. On the other hand, Arduino Nano is very easy to use and well supported. Nano is great for simple and quick projects. It's my go-to development board when I need to test some new sensors or other components/modules.
Hugatry's HackVlog thanks. I want to create dynamic LED backlight using WS2812B strip for my monitor. It will be nice addition for gaming and watching movies.
Thank you very much for this great video. May you please explain when are you using the Adapter USB - TTL Serial and when the USB port? Are you plugging the Adapter to load the code and then unplugging it then plugging the USB to run de code? I am very confused, please expalin.
** Programming Started ** auto erase enabled Error: Invalid command argument image.base_address option value ('Test.elf///') is not valid ** Programming Failed ** shutdown command invoked i have no idea what i am doing wrong. Debugging works, but when i click run, it doesn't work.
Apparently that is caused by a space in the project name. That space also goes to the name of .elf file and because that name hasn't been handled safely, it messes up the programming command. As a quick fix you could either recreate the project with STM32CubeMx with project name that doesn't have spaces, or do following in the SW4STM32: 1) Clean project. 2) Rename project and remove the spaces. (Right click on project in project explorer -> Rename) 3) Build the project. 4) Select the new .elf file in Run/Debug settings. (Right click on project in project explorer -> Properties -> Run/Debug settings. Create new if needed, and select the C/C++ application with "Search project...". List should show .elf file with your new project name as a file name.) I haven't personally encountered this problem "In real life", so I don't know if there is more elegant way to solve it. But this was something I came up with after quick research and testing. I hope this helps, cheers!
Hello friend! I hope everything still good. Please help me if you know what could be happening to me, I am having issues when trying to upload the code to the microcontroller, I get the error: "OpenOCD child process termination Reason: Wrong devide detected" I am doing exactly the same than before, and I previously could upload the code with no problems, following your steps. I think the only thing I have made different is that once I tried to upload de code using Rigth Click > Target > Program Chip. It failed then I tried to use your method as always but now I cannot make it work again, I have tried changing a configurations but still the same. (I have also tried removing the Launch Configuration and creating a new one, changing the text in the .cfg file, etc) In my console I get the following log: Open On-Chip Debugger 0.10.0-dev-00010-g96aab7b (2018-07-13-06:51) Licensed under GNU GPL v2 For bug reports, read openocd.org/doc/doxygen/bugs.html trst_only separate trst_push_pull Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD adapter_nsrst_delay: 100 adapter speed: 950 kHz Info : clock speed 950 kHz Info : STLINK v2 JTAG v29 API v2 SWIM v7 VID 0x0483 PID 0x3748 Info : vid/pid are not identical: 0x0483/0x374B 0x0483/0x3748 Info : using stlink api v2 Info : Target voltage: 3.216284 Error: init mode failed (unable to connect to the target) in procedure 'program' in procedure 'init' called at file "embedded:startup.tcl", line 485 in procedure 'ocd_bouncer' ** OpenOCD init failed ** shutdown command invoked Sorry for the long comment, I hope you can help me. Thanks sir!
hey nice tutorial, please make more such tutorials with CubeMx and STWorkbench. i am running your project on my Stm32f4 disco. i usb serial device need a driver update.did you have a situation like this ?
Thanks, Kiran! I don't remember if I needed to install drivers or not. I found this page when I searched for "STM32 com port driver": www.st.com/en/development-tools/stsw-stm32102.html On that page it says that native drivers on Windows 10 should work. But as there are lots of people using older Windows versions, I'll add that link to the description. There are many interesting things one can do with STM32 using the CubeMx, but information can be hard to find. This kind of tutorials are definitely in my To Do -list!
at 8.46(when running the code) i got an OCD error stating -openOCD child process termination Reason: Unplugged target or ST LINK already in use or STlink USB driver not installed . what should i do..?? plus just to clarify we dont need any ST-LINK as per your tutorial right.?
Hi! I was using ST-Link V2 compatible programmer/debugger. I recommend getting one of those (they cost just couple of $ on eBay). One more thing to buy, but it makes life so much easier.
In CDC_Receive_FS you read Buf[0] before It's assigned, crazy! Then sending data inside receive function is a very bad practice, you have to set a flag and then send data inside main loop.