Electronics Lab Philippines

STM32 Tutorial

Offline zirlou21

  • *******
  • 750
  • 84
  • Gender: Male
  • I wish there is GOD...
    • ARDUINO,ATMEL-AVR,ZILOG ENCORE,PIC..CIRCUITS/APPS
Re: STM32 Tutorial
« Reply #200 on: August 15, 2018, 08:22:37 PM »
 :) :) :)


...me too,let's get it on...ty
...NO OFFENSE pls..usapang teknikal lang,walang personalan.....

Offline motion55

  • *****
  • 3169
  • 520
  • Gender: Male
  • Been at this longer than you've been alive.
Re: STM32 Tutorial
« Reply #201 on: August 16, 2018, 11:15:08 AM »
Bago mag start ng tutorial. I would like to make a short introduction to the STM32 microcontroller.

For starters, the STM32 is a family of microcontrollers produced by the European company ST Microelectronics. Ang kalaban ng STM32 ay ang Atmel (Microchip) SAM microcontrollers, NXP Kinetis and LPC Cortex Microcontrollers.Lahat sila are members of the ARM Cortex M series microcontrollers.

Why STM32?

1. Because it is very popular. Ang sample boards ng STM32 are very easy to get and are cheap. Outside of the Arduino camp, these boards are the next best thing in terms of availability.

2. Because the development tools are widely available and easy to use. I am long time user of the Atmel Studio. I like it a lot. May time, walang maganda para sa STM32 aside from the tools ng Keil and other na kailangan pa bilhin. But lately, nakakahabol na rin ang STM32 with their free development tools.

3. Right balance of peripherals and features. Okay lahat sila ARM Cortex M microcontrollers. Mahihilo ka sa dami ng variants lalo na sa SAM line Atmel. May development board ako ng Atmel (SAM E70) in addition to the bunch of Arduino Due boards. Matagal na rin akong user ng Atmel Studio. Pero on the latest project ko, I used a STM32 after trying out NXP and Atmel.

"Set your mind free!"

Offline S73172DP

  • **
  • 20
  • 1
Re: STM32 Tutorial
« Reply #202 on: August 16, 2018, 10:30:49 PM »
Noted on the introduction Sir. Nice info.

Kindly explain just a bit what made STM32 or other ARM Cortex MCUs have “the right balance of peripherals and features”?

Offline motion55

  • *****
  • 3169
  • 520
  • Gender: Male
  • Been at this longer than you've been alive.
Re: STM32 Tutorial
« Reply #203 on: August 17, 2018, 07:27:24 PM »
Kindly explain just a bit what made STM32 or other ARM Cortex MCUs have “the right balance of peripherals and features”?

The balance part nag dedepend sa applications ng microcontroller.  So possible na balanced para sa akin pero di balanced para sa inyo. In my case, naghahanap akong range of 32-bit MCUs that can come is a small 48-pins to as big as 144-pins or higher. I was looking for strong USB support as well as options to add Ethernet. Gusto ko may native Ethernet mach support. Ayoko ng crappy Ethernet thru SPI interface na ginagamit sa Arduino. I also like the ability add memory using an SRAM or DRAM controller. The Atmel SAM3X8E ng Arduino Due would have fit the requirements except na nilagay ni Atmel as legacy part. Meaning, pwede ma phase out anytime. The replacement is the super fast Atmel SAME70 but nag iisa lang siya and not suited for my other applications. Ang STM32 may ilang similar devices na pwede. Once example is the STM32F746 na may built-in support for external memory as  well as TFT LCD controller.

On the other end of the application, I just need a fast MCU to replace an aging 20 year motor driver design. That design used a PIC16F73. Sinubukan ko palitan ng drop in replacement PIC18F24K42 with negligible improvement in performance. The PIC18F24K42 runs at 64MHz while the PIC16F73. May hardware multiply na pero di pa rin nakaya ang computational load sa PID calculaztions.  Pina stop na lang ng employer ko in order to move to other projects. In the future babalikan ko pa rin pero instead of using a faster PIC, I plan to replace it with a STM32F303. Not only is it 32-bit from 8-bit, may math coprocessor na to speed up calculations while running at 72MHz. Almost the same price din naman.

As you can see, maraming kailangan i-consider. It takes time to evaluate. By sharing my experience baka makatulong in your choices.
"Set your mind free!"

Offline S73172DP

  • **
  • 20
  • 1
Re: STM32 Tutorial
« Reply #204 on: August 18, 2018, 02:39:34 AM »
Thanks for explaining further. You’re so rich in experience. Ang galing nyo Sir.

Hoping that you can share or teach us further up to those features you have mentioned like usb applications, ethernet, and adding memory.  ;D

It is really difficult (for me) to make a choice what mcu or its variants fit in applications I was planning. Hence, I’d always wanted to refer to ideas and thoughts by experts like you. And it may not already be a good practice for me to keep on shifting and learning other mcus and IDEs just to compare them and decide what is better. For now and hopefully magtagal, sa STM32 muna ako.


Offline motion55

  • *****
  • 3169
  • 520
  • Gender: Male
  • Been at this longer than you've been alive.
Re: STM32 Tutorial
« Reply #205 on: August 22, 2018, 10:04:13 AM »
I will explain more on the STM32 MCU family's versatility as we proceed with the tutorial. I will begin with the first board that I will use. It is the STM32F103C8 development board commonly known as the "Blue Pill" because of its board color.



Pinili ko mainly because of its price. I don't know kung may local seller nito pero available sa Lazada. At about Php150 each, it is unbeatable even by Arduino.

https://www.lazada.com.ph/products/stm32f103c8t6-arm-stm32-minimum-system-development-board-module-for-arduino-intl-i144535422-s167173475.html

Kung bibilihin ang STM32F103C8T6 IC lang from the distributors like Mouser, etc, mas mahal pa kaysa Blue Pill. Hmmm... Base sa datasheet,  ang STM32F103C8T6 may 64KB lang ng program flash memory. Pero it known that most Blue Pill have 128KB flash. Hmmm... Anyway, its a good board for learning STM32.

More info from here:

https://wiki.stm32duino.com/index.php?title=Blue_Pill


"Set your mind free!"

Offline _basura_man()

  • *
  • 1169
  • 63
  • Senior Software Engr. in http://goo.gl/iM8khM
Re: STM32 Tutorial
« Reply #206 on: August 22, 2018, 11:40:54 PM »
Buhayin ko itong thread. I am using the AC6 SW4STM32 IDE and the board will be the cheap STM32F103C8 "BluePill" board.



Anyone interested in a tutorial?





count me in sir motion55
Senior software developer at day, HW and FW hobbyist at night.
Working at http://goo.gl/iM8khM.

Offline S73172DP

  • **
  • 20
  • 1
Re: STM32 Tutorial
« Reply #207 on: August 23, 2018, 12:24:23 AM »
‘Just checking for updates. ;D ;D ;D

Sir motion, have you already tried or seen an STM32F103C8T6 with 128 kb flash?

Offline motion55

  • *****
  • 3169
  • 520
  • Gender: Male
  • Been at this longer than you've been alive.
Re: STM32 Tutorial
« Reply #208 on: August 23, 2018, 10:13:00 AM »
‘Just checking for updates. ;D ;D ;D

Sir motion, have you already tried or seen an STM32F103C8T6 with 128 kb flash?

Honestly, hindi pa. May ilang Blue Pill ako pero STM32F105RCT6 ang ginagamit ko ngayon. Hindi supported ng built-in bootloader ng STM32F103 ang USB port. Sa UART lang. Whereas supported sa STM32F105.

"Set your mind free!"

Offline motion55

  • *****
  • 3169
  • 520
  • Gender: Male
  • Been at this longer than you've been alive.
Re: STM32 Tutorial
« Reply #209 on: August 23, 2018, 10:34:15 AM »
STM32 IDE Setup

Earlier nabanggit ko ng ginagamit ko ang SW3STM32 IDE ng AC6. Ang SW3STM32 IDE supplied ng AC6 gumagamit ng mas lumang version ng Eclipse (Oxygen 2). I am now using a newer version of Eclipse (Photon) and yan ang recommended ko sa ngayon.

Step 1. Download and install Eclipse Photon for C/C++ developers

https://www.eclipse.org/downloads/packages/

Step 2. Install System Workbench for STM32 plugin

You should Start Eclipse then open menu “Help >> Install New Software”; this will open the “Available Software” dialog:

You must then create a new update site, to be able to install System Workbench for STM32 - Bare Metal Edition:

You should click on “Add:” Then give a name to the update site (System Workbench for STM32 - Bare Machine edition) and set the location to :

http://ac6-tools.com/Eclipse-updates/org.openstm32.system-workbench.update-site-v2

Then click “OK” to create the update site

Then you should select all of the OpenSTM32 tools and click “Next>”

You will then just have to accept the license and System Workbench for STM32 - Bare Metal edition will install itself in your Eclipse setup.

Note that you will probably have to restart Eclipse for the tools to be available; Eclipse will automatically suggest the restart.

http://www.openstm32.org/Installing%2BSystem%2BWorkbench%2Bfor%2BSTM32%2Bfrom%2BEclipse

Step 3. Install STM32CubeMX plugin

Register and download the STM32CubeMX plugin (ZIP file) from this link:

https://www.st.com/en/development-tools/stsw-stm32095.html

Kagaya ng pag install ng SW4STM32 plugin, from the “Help >> Install New Software” menu, open the  “Available Software” dialog. Pero this time, press the "archive" button and select the ZIP file you downloaded.


"Set your mind free!"

Offline S73172DP

  • **
  • 20
  • 1
Re: STM32 Tutorial
« Reply #210 on: August 23, 2018, 11:35:47 PM »
All set, and ready for the first project. ;D


Offline motion55

  • *****
  • 3169
  • 520
  • Gender: Male
  • Been at this longer than you've been alive.
Re: STM32 Tutorial
« Reply #211 on: August 27, 2018, 11:24:29 AM »
All set, and ready for the first project. ;D

Let's start with the Blinky project.

1. Assuming you have installed the two plug ins, Launch the Eclipse IDE.

2. From the menu, Select Window->Perspective->Open Perspective->Other..
Lalabas ang Open Perpsective dialog. Select  STM32CubeMx from the dialog. Ganito ang result.



3. Since this may be the first time STM32CubeMx is launched, you should check if the software package for the STM32F103 is installed. From the menu, select Help->Manage embedded software package. A dialog will appear. Select and install the latest package for the STM32F1 family.



4. After the package have been installed, close the dialog and return to the page in step 2. Press the "New Project" link. The "New Project" dialog will appear. Select the device STM32F103C8 from the list of devices. To help, you can filter the choices by checking the ff.

Core - ARM Cortex M3
Series - STM32F1
Line - STM32F103



Press the start project button on the right side. When this appears, we are ready to setup the codes to initialize the chip.



The microcontroller makers like Microchip, STM32 and others supply wizard apps to help wade through the zoo of peripherals and the codes for initializing them. Nevertheless, it will also help by reading the datasheets while using these tools.

"Set your mind free!"

Offline S73172DP

  • **
  • 20
  • 1
Re: STM32 Tutorial
« Reply #212 on: August 27, 2018, 07:59:58 PM »
Great start Sir motion!

I like the new version of Eclipse and how the SW4STM32 and STM32CubeMX plugins were integrated in eclipse.  ;)

Thanks for this procedure.

Offline _basura_man()

  • *
  • 1169
  • 63
  • Senior Software Engr. in http://goo.gl/iM8khM
Re: STM32 Tutorial
« Reply #213 on: August 28, 2018, 11:39:29 AM »
thanks sir motion55!
Senior software developer at day, HW and FW hobbyist at night.
Working at http://goo.gl/iM8khM.

Offline motion55

  • *****
  • 3169
  • 520
  • Gender: Male
  • Been at this longer than you've been alive.
Re: STM32 Tutorial
« Reply #214 on: August 28, 2018, 06:24:37 PM »
Continuing from where we stopped, let's add the LED. According to the Blue Pill schematic, the LED is wired to PC13 pin.

1. Bago mag create ng code, change the settings first. From the menu, select Project->Settings. Lalabas ang settings dialog.

a. Change the project name to "Blinky".
b. Select the target Toolchain/IDE to SW4STM32.

Ganito ang settings. Click your mouse sa pictures to magnify.



2. Setup GPIO: Sa picture ng STM32F104C8 IC, left-click on pin PC13. Sa selection menu na lalabas, select GPIO Output.

3. Right click on the same pin. Then select "Enter User Label". Rename the pin to "LED_Ouput". Ganito dapat lalabas.



4. At this point, the clock for the MCU is set to default. Kahit may 8Mhz crystal si Blue Pill, naka set sa ngayon to using the internal 8MHz RC oscillator. Later, we will change that to use the crystal and the PLL to push the clock speed all the way up to 72MHz. Pero since blink LED lang pwede na tumakbo at 8MHz. You can view the clock configuration.



5. Time to generate some code. From the menu again, select Project->Generate Code. STM32CubeMX will proceed to generate the project files. After matapos, select Open Project. Nothing happens, because we are still in the STM32CubeMX perspective, Time to switch to the C++ perspective. There are two ways to switch perspective. One way is from the main menu. Select Window->Perspective->Open Perspective->Other and select the C/C++ perspective. Another way is to press the C++ button sa toolbar.



I modified the file main.c  to include the bliink LED code. It looks similar to the Blinky ng Arduino.

Take note that I also installed a dark theme from the Marketplace. Matanda na ako and I can't see too well kung white ang background.

Next time, we will discuss how to upload and run the program to the Blue Pill.





"Set your mind free!"

Offline S73172DP

  • **
  • 20
  • 1
Re: STM32 Tutorial
« Reply #215 on: August 29, 2018, 12:23:02 PM »
Got it Sir. Well explained.  :)


Offline motion55

  • *****
  • 3169
  • 520
  • Gender: Male
  • Been at this longer than you've been alive.
Re: STM32 Tutorial
« Reply #216 on: September 13, 2018, 10:27:55 AM »
Sorry for the long pause. Nagpapagamot ako with some eye sight issues. Tapos dumating ito kahapon from my employer. Since they are paying my bills, priority ito. It's a custom FPGA board (prototype pa lang) with an STM32F105RCT6 MCU, Ito'y part ng isang laser marking controller. Unlike the Blue Pill's STM32F103C8T6, the STM32F105RCT6  supports the bootloader on the USB port.



Don't worry. Itutuloy ko pa rin ang tutorial as soon as I sort out what to do next.

"Set your mind free!"

Offline S73172DP

  • **
  • 20
  • 1
Re: STM32 Tutorial
« Reply #217 on: September 17, 2018, 11:38:04 PM »
Get well soon Sir. Aabangan ko future posts mo for this tutorial.

Very interesting board. Are you also programming the FPGA chip? What is the main function of the STM32F105RCT6 in this board?

Thanks.

Offline motion55

  • *****
  • 3169
  • 520
  • Gender: Male
  • Been at this longer than you've been alive.
Re: STM32 Tutorial
« Reply #218 on: September 18, 2018, 05:34:58 PM »
Get well soon Sir. Aabangan ko future posts mo for this tutorial.

May 1 week na mula na injection ako sa mata (left eye) ng gamot. As expected, lumilinaw na ang vision. Ang tanung ay kung stable ba. Over 3 years, 4 na beses na ako na injection. Dalawang beses bawat mata. Buti na lang ang kanang mata hindi kailangan ng injection pero may gamot na pinapatak ngayon.

Quote
Very interesting board. Are you also programming the FPGA chip? What is the main function of the STM32F105RCT6 in this board?

Thanks.

Yes ako rin gagawa ng program para sa Altera Cyclone IV FPGA. Verilog ang gamit ko this time. It's for a PID controller ng 3 axes of "Laser Galvo drivers". Sige Google niyo. Galvo is short for galvanometer. FPGA para high speed ang digital control loop (~500KHz).

So ano ang function ng STM32? PID requires tuning of PID constants as well as other settings. Ang analog version ng mga Galvo drivers has over 10 trimmer potentiometers. May sample ako gawa ng Cambridge (USA). So pang tuning and calibration ang STM32. Secondly, ang STM32 pang update ng FPGA program. It's also a Altera USB Balster in disguise. The STM32 is connected to the FPGA by 2 SPI lines and through JTAG. Bakit dalawang SPI kamo? Isa para sa internal register pang laser control. Ang pangalawa ay para sa pass-through para ma access ang flash memory ng FPGA. Pwede niya sulatan ang flash memory para ma change ang program ng Altera FPGA as well as to store the settings.


"Set your mind free!"

Offline S73172DP

  • **
  • 20
  • 1
Re: STM32 Tutorial
« Reply #219 on: September 19, 2018, 03:36:32 AM »
Sana Sir maging stable na ang condition ng mata mo. Masyado lang siguro na na-stress sa work nyo.

Ang galing naman fpga board nyo Sir, pati programming complicated na rin. Now I know, very advanced pala level nyo sa mga controllers at programming. :)

I’ve once checked and read about fpga and cpld since there are cheap development boards from on-line shops including its programmer, pero parang mahirap pag-aralan especially now that I’m still learning the basics of some 8bit/32bit MCUs. Siguro, try ko rin ito in the future.

Regarding PID, I may also need this as another feature for my controller (hindi lang relay output na on-off ang function), since it is one main feature of analog controllers and PLCs that I like. I haven’t tried it for MCUs yet but I’m interested to explore the arm math for my STM32 boards.

Thanks for the post. It’s a great information to see and learn the fpga board’s general function and its existence.