Thank you all, dear friends, for your replies.
I am sorry for the delay in responding, but I am still travelling for business reasons, and sometimes I remain absent for a little while.
As I had to solve my problem fast because I need STM32 for new pending jobs, I decided to do the following:
1. installed
Visual Studio Code.
2. added the
PlatformIO extension to it.
3. added the Arduino extension to it.
4. added the STM32F103C8T6 board to it.
5. also some other useful and necessary extensions, boards such as Arduino NANO.
6. some time ago I have also installed the STM32 tools
STM32CubeIDE,
STM32CubeMX,
STM32CubePogrammer.
7. fully erased the FLASH of my 3 Bluepills (fake versions),
eliminating the HID bootloader
8. return to use the
ST-Link V2 (chinese version)
last time I visited this community the status was that, surely because of my ignorance about STM32
as a newbie, I was unable to implement an interrupt generated by TIM2_CH1 in PWM mode. I appreciate all the information gathered but it resulted overwhelming for a newbie in STM32.
My STM32 experience started some time ago using STM32CubeIDE with HAL and using the builtin initialization wizard. At that time I didn't know that the chips on my Bluepills, although marked "ST", were fake. Now I know CPUTAPID is 0x2ba01477 for fakes vs. 0x1ba01477 for originals.)
STM32CubeIDE refused to program fake parts, even after many attempts of editing configuration files to avoid checks. This once worked but ST probably has other methods to know what kind of chip is connected as target. The STM32CubeProgrammer perfectly FLASHED and erased all of my parts, but ST doesn't allow debugging of fakes. Bad news for me.
Totally reasonable for ST.
Also, using Arduino + STM32 for learning and trying so many frustrating experiments to make my program work, I reached the point in which
I had to re FLASH the HID bootloader each time before Arduino uploads. Later I found that this is a
very well known issue. Sometimes the bootloader simply fails to switch between USB mode to COM mode so Arduino can't program the part.
With these elements I have, I found that
one possible working formula if you need to quickly start using STM32 is to
use STM32CubeMX to generate the code needed to completely initialize the chip and also to provide the main(), the basic calls and all the few modules needed for the interrupts including the empty user handlers.
These is simply a couple of .c and .h files.
Later, and with the examples working, it is much easier to sit down and study step by step how al this works with a coffee mug, bottom-up. Not the other way around because of the complexity and flexibility of these machines compared to their classic 8 bits counterparts, and with a very different learning curve.
After this, I created a PlatformIO STM32F103C8T6 project. Then simply drag and drop the generated initialization files into the project. All of the comments that STM32CubeMX and STM32CubeIDE generate can be eliminated as they are useless in a VSCode/PlatformIO project. My last learning step was that, although STM32CubeMX perfectly generates all the needed code, HAL function calls are needed in main() to start timers and enable interrupts, one for each timer or peripheral. Once there, is simply C programming as usual.
As in Arduino, there is no need to worry about fake chips and programming dongles. PlatformIO fixes this by simply a dding a configuration line in the platform.ini file (there is one for each user project). Here is the way STM32F103C8T6 is configured in my project:
Code: Select all
[env:bluepill_f103c8]
platform = ststm32
board = bluepill_f103c8
framework = stm32cube
upload_protocol = stlink
debug_tool = stlink
upload_flags = -c set CPUTAPID 0x2ba01477
; change MCU frequency
board_build.f_cpu = 72000000L
Notice that the single upload_flags = -c set CPUTAPID 0x2ba01477 works to recognize fake chips.
Finally I could make my TIM2_CH1 interrupt work easily.
To finish my report, I just want to say 2 things:
1.
I hate the fake industry and I understand that manufacturers such as ST need to fight against it being 65% fakes of the chips in the market . In the other hand the common man from the plain also needs to survive, specially when the origin of the parts is uncertain at first sight.
2. I tried Arduino because I sometimes use it for the 8 bit family and I consider it an extremely valuable tool.
I appreciate each and every contribution and time dedicated to help me start. But it is important for contributors to understand what happens in the newbie's head. The examples given should be, IMHO, short, concise, given in step by step fashion considering the level of the information, and should be working examples for the family component in focus. Equivalent examples with pieces of code are hard to fit and make them work, because there are differences between components of the same family (e.g.: F1 to F4, etc) impossible to handle at start level with an ARM chip. I am a contributor myself in lots of forums, and as a teacher, I always keep this in mind.
Thank you all - problem solved
Roberto