Transcript for:
STM32 Cube IDE Course for Beginners

this video is brought to you by LTM designer welcome to my stm32 Cube IDE course specifically designed for beginners in this course we will take a step-by-step approach to ensure that you can a solid understanding of how to use Cube IDE for programming the stm32 microcontroller throughout this course I'll be using the most popular stm32f103c8t6 microcontroller board which is also known as Bluebell and for uploading the program I will use the sd-link V2 since this course is for the absolute beginners so I will try my level plus to explain each and every detail including number one stm32 blue pill board technical specifications and pin out number two what is Cube IDE and number three how to download and install stm32 Cube IDE after covering the most basic things then I will practically show you how to use the most commonly used electronics components with the stm32 since this go course is for the beginners so first I will start with the easiest example which is controlling the stm32 onboard LED then in the second example I will show you how to connect and control external LEDs these led blinking examples will help you in understanding how to turn on and turn off any gpio pins on the stm32 in third example I will show you how to read a digital input on any gpio open of the stm32 for this I will use a push button we'll be reading and controlling both at the same time the hdm32 board will sense the button click and then accordingly will turn on or turn off the LED in fourth example I will show you how to interface an i2c supported 16 into LCD this is one of the most commonly used LCDs you will simply print the hello world text message on the LCD Mario in the fifth example I will show you how to use an analog sensor with the stm32 and display its value on the i2c supported 16 into LCD for demonstration purposes I'll be using a potentiometer as the analog sensor after understanding this example then you would be able to use all types of analog sensors like for example ldrs flick sensors four sensors Etc there is a long list of the analog sensors in the sixth example I will show you how to connect an i2c supported or LED display module with the stm32 I will write a very basic program to print some text on the OLED display Mario this is really an important example because in most of the projects you will need an or LED display module to print text messages and sensor values in seventh example I will explain how to make a simple distance measurement system using the most popular hc-desh sr04 ultrasonic sensor we will simply measure the distance and then print it on the i2c supported SSD 1306 or LED display module these examples will help you in getting started with stm32 and Cube IDE so without any further delay let's get started foreign [Music] throughout this course I will use the stm32 blue build board which is based on the stm32f103c8 T6 microcontroller unit from SD microelectronics stm32f1 series the stm32 blue pill controller board is based on the arm cortex M3 and is commonly known as the Blue Bell development board let me share with you some of its key information it is based on the arm cortex m332-bit risk processor which offers a good balance between performance and power efficiency the stm32f103c8 T6 microcontroller typically operates at a maximum clock speed of 72 megahertz it comes with different variants offering various amounts of flash memory the most common one is 64 kilobyte of flash memory which is used to store the program code it has 20 kilobyte of SRAM static Random Access Memory that is used for data storage during program execution the MCU includes a wide range of peripherals including gpio general purpose input output ports timers usart SPI i2c ADC and log to digital converter and more the operating voltage typically ranges from 2.0 volts to 3.6 volts making it suitable for low power applications to program and develop applications for the stm32f103c8 T6 MCU you can use the stm32 cube IDE which is an integrated development environment provided by SD microelectronics Additionally you can use various other development tools and programming the languages like COC plus plus and assembly the sdm32f1 series has been widely used in various applications including Industrial Automation consumer electronics iot devices Robotics and more its versatility performance and affordability make it a popular choice among developers and hobbyists for various embedded projects it has a total of 40 pins 20 pins on each side it has two 3.3 volt pins connected to the onboard 3.3 volt regulator power supply which is used to power up the onboard components including the microcontroller and other external components like sensors and breakout boards so if you need 3.3 volts to power up your sensors you can simply connect 3.3 volt from any of these two pins it has three ground pins one on this side and the other two on this side all these ground pins are interconnected so you can take a ground connection from any of these three pins this 5-fold pin is the input Power Pin means you can connect an external regulator Firefall power supply to this pin to power up the stm32 board you don't need to worry about the microcontroller the onboard 3.3 volt regulator will convert the 5 volts in the 3.3 volts while performing your initial experiments you don't need to connect an external 5 volt regulator power supply you can just use your laptop as the power source but sooner or later you will need an external power supply because it's impractical to use your laptop or PCS the power source so I recommend you should build yourself this FireFold and 3 amps power supply I have a detailed video on its designing and making and later in this video I'll use this Firefall power supply to power up the stm32 controller board it has a total of 32 gpio pins numbered asp0 to B15 C13 to C15 and a0 to a15 while in the pin out diagram these are numbered as BB PC and Pa it has a total of 10 analog pins starting from a0 to B1 the spins are connected to the built-in analog or digital converter ADC of the microcontroller and can be used to measure analog signals it has two eye to C supported ports the i2c1 is available on pins B6 and B7 B6 is the scl and B7 is the SDA the i2c second Port is available on pins P10 and b11 P10 is the scl and b11 is the SDA it has three serial ports the usar D1 is available on pins N9 and A10 N9 is the TX and 810 is the RX usar D2 is available on pins A2 and A3 A2 is the TX and A3 is the RX usar D3 is available on pins B10 and b11 B10 is the TX and b11 is the r X and it also has pins for the SPI pwm and Kane all these pens are clearly labeled let me also tell you when you hold the stm32 controller board like this all the pins on this side from B9 to B12 are 5 volt tolerant except the B5 pin bb-5 or B5 is 3.3 volt standard pin all the pins on this side from V battery to the reset pen or 3.3 volt standard pins except the B10 and b11 which are five volt tolerant pins these four pins on the stm32 board or the swd serial wire debug pins that allow you to connect a debugger or a programmer like the sd-link V2 the sd-link V2 allows you to program the firmware onto stm32 microcontrollers and also provides debugging capabilities it connects to the stm32 microcontrollers swd pins for programming and debugging operations it is designed to work seamlessly with the stm32 cube IDE which is an integrated development environment provided by SD microelectronics I think I have shared enough variable information with you guys and now it's time to download and install the stm32 cube IDE search for the stm32 cube IDE click on this link while you are on the stm32 cube IDE official page go to the stm32 developer Zone and from the drop down list select stm32 Cube IDE click on the download htm32 Cube IDE button select Windows except the license agreement click on the register button click on the create account [Music] enter the required details finally check the box and click on the register button next open your email account and click on the validate now complete your registration by entering your password click the submit button and you will be notified the registration has been completed please log in here enter your registered email ID and password and click on the login button [Music] now you can click on the download stm32 Cube IDE click on the Windows except the license agreement and start downloading the stm32 cube IDE extract the download zip folder [Music] open the folder and run the XZ file to start the installation process [Music] thank you [Music] the stm32 cube IDE has been installed you will see the stm32 cube ID is shortcut on the desktop in this first example we are going to control the stm32 onboard LED which is connected to pc13 pin before we start the programming first we will need to connect the stm32 port to the laptop or PC for this we are going to use the SD link V2 simply connect the sd-link V2 3.3 volt and ground pins to the 3.3 volt and ground pins on the stm32 board connect the swclk and swdio pins of the SD link to the stm32 swclk and swdio pins finally connect the sd-link V2 to your laptop or PC open the stm32 cube IDE software select a directory as workplace where you want to store all your projects or you can go with the default address finally click on the launch button foreign will display the welcome screen indicating that the IDE has been successfully launched to start a new project go to the file menu then to new and click on the stm32 project stm32 Cube IDE may take a moment to load and download the necessary libraries please be patient during this process as it may take some time depending on the speed of your internet connection Target selection window and while the MCU selector tape is active select the commercial part number that is hdm32f103c8d6 selected from the mcu's list and then click on the next button write the project name select the targeted language Target binary type and targeted project type [Music] on the pinout and configuration tape click on the system core and select says click on the debug and select serial wire [Music] click on pc13 and select gpio underscore output is the onboard LED is connected to this pen finally click on the save button if it asks you do you want to generate code click Yes again press the yes button stm32 Cube IDE will generate the necessary code based on your PIN configuration and open the associated perspective this perspective provides you with the appropriate tools and views for further development and customization of your project scroll down now in while function we will write code for blinking the LED [Music] once the code is completed click on the hammer icon or build there are no errors and warnings now we can click on the play button click on the debugger tape select SD link click on show generate options set the reset mode to Software System reset and click the apply button and then click the OK button foreign [Music] foreign [Music] you can see the onboard LED is blinking we just built our first LD blinking project in this next example I'm going to explain how to control external LEDs ultimate designer is the world's most crosstalk PCB design system ultim designer enables Engineers to effortlessly connect with every facet of the electronics design process over 35 years of innovation and development focused on a truly unified design environment makes it the most widely used PCB design solution with ultimate designer you can create PCB designs with an intuitive and Powerful interface that connects you to every aspect of the electronics design process routed your way through any angle tuned for the delay push slide and walk around faster than ever easily work together with your mechanical team and forget about the days of swapping design files every design change stays in sync between ultim designer and SolidWorks BTC crew Autodesk Inventor Autodesk Fusion 360 or Sim means NX interact and collaborate with mechanical designers like never before and of photorealistic 3D design environment one of the best things about ultimate design is that you can share your designs with your team members using ultim365. they can check your design leave comments and if there are any issues they can fix them from anywhere in the world ultimate designer also uses the world's fastest component search engine OCTA part so you won't have any difficulty in searching for components links to the ultim designer Altium 365 and octopod are given in the description in the second example we are going to control external LEDs but to keep things simple and easy to follow first let's start with a single LED and afterwards we'll control multiple LEDs anyway let me explain the connections the cathode licks off all the LEDs are connected together and then connected to the ground pin on the stm32 board the inert legs of all the LEDs are connected to the gpio pins pb6 p B7 bb8 and pb9 through this current limiting resistors you can follow this circuit diagram before we start the programming first we will need to connect the stm32 port to the laptop or PC while the stm32 cube IDE is open go to the file menu then to new and click on the stm32 project on the target selection window and while the MCU selector tab is active select the commercial part number that is stm32f103c8d6 select it from the mcu's list and then click on the next button write the project name select the targeted language Target binary type and targeted project type on the pin out and configuration tape click on the system core and select says click on the debug and select serial via click on pb9 and select gpio output is the external LED is connected to this pin repeat the same steps for the other three gpio pins to which the external LEDs are connected finally click on the save button if it asks you do you want to generate code click yes again press the yes button scroll down now in while function we will write code for blinking one area that is connected to B9 or pb9 once the code is completed click on the hammer icon or build there are no errors and warnings now we can click on the play button click on the debugger tape select SD link click on show generate options set the reset mode to Software System reset and click the apply button and then click the OK button you can see out of these four LEDs only one LED is blinking if you replace this Italy with a relay then you would be able to control high voltage AC and DC load anyway now let's control all these four LEDs I have already written some codes so I'm going to copy and paste it in the existing code you can see I'm using the same pins B9 B8 B7 and B6 the code is exactly the same only this time I'm controlling multiple LEDs you can turn on and turn off LEDs and certain patrons to make some cool animations let's click on the play button you can see this time I'm able to control multiple LEDs now you can modify this program to control less or more LEDs in next example I'm going to explain how to read digital input in this third example we are going to learn how to read a digital input on any gpio pin of the stm32 microcontroller board we'll be monitoring and controlling both at the same time each time the pattern is pressed the early is going to change its state anyway let's take a look at the wiring the inert leg of the LED is connected to the stm32 GPI open pa1 through a 330 ohm current limiting resistor and the cathode Lake of the LED is connected to the ground one side of the push button is connected to the ground and the other side of the push button is connected to 3.3 volt through a 10 kilo ohm pull up resistor a wire from the middle is connected to the stm32 gpio pin pb1 when the button is open the pb1 pin reads 3.3 volt and when the button is pressed it reads zero volt you can follow this circuit diagram before we start the programming first we will need to connect the stm32 port to the laptop or base receive while the stm32 cube IDE is open go to the file menu then to new and click on the stm32 project on the target selection window and while the MCU selector tab is active select the commercial part number that is stm32f103c8d6 select it from the mcu's list and then click on the next button write the project name select the targeted language Target binary type in targeted project type on the pin out and configuration tape click on the system core and select says click on the debug and select serial via click on pa1 and select gpio output click on pb1 and select gpio input finally click on the save button if it asks you do you want to generate code click yes again press the yes button I have already written some code so I am going to copy and paste it in the main.c file you can download this code from a website electronic clinic.com once the code is completed click on the hammer icon or build there are no errors and warnings now we can click on the play button click on the debugger tape select SD link click on show generate options set the reset mode to Software System reset and click the apply button and then click the OK button you can see each time I press the button the LED changes its state you can replace this push button with a digital IR sensor and the LED with a relay to make a contactless AC or DC load control system you can use any type of digital sensor even you can convert this simple project into a security system using a digital PIR sensor anyway in next example we are going to use i2c supported 16 into 2 LCD with the stm32 if you have been using LTM designer for creating schematics and designing your pcbs and you don't know about LTM 365 then let me tell you about it Altium 365 lets you store projects in the cloud with all the documents and components you might need to complete all your tasks to unlock all of the functionality of ultim365 you must first connect to your workspace a separate environment where all your data exists after logging into your account you can access all of the features of the LTM 365 platform let me show you how to create a workspace click on the not signed in drop down button and click on the sign in click on the register and account it's just a two steps process into your email ID or you can also register with Gmail and Facebook once you complete the registration then come back to Altium designer enter your email ID and password check the sign in automatically box and click on the sign in button and you Altium 365 workspace will activate click on manage if you want to change your password your information and you can also write about your experience and projects and finally you can click on save button I will share more tips and tricks with you in my upcoming videos I have edited links to the ultim designer ultim365 and octopod the world's fastest component search engine in this fourth example I'm going to show you how to print text on this i2c supported 16 into 2 LCD this is one of the most commonly used LCDs used for displaying text messages and since the values let me explain the connections connect the VCC and ground pins of the i2c supported 16 into 2 LCD to the stm32 port 5 volt and ground pins connect the scl and SDA pins of the 16 into 2 LCD to the stm32 gpio opens pb10 and pb11 you can follow this circuit diagram before we start the programming first we will need to connect the HTM meter to pour to the laptop or PC for this we are going to use the SD link V2 simply connect the SD link V2 3.3 volt and ground pins to the 3.3 volt and ground pins on the stm32 port connect the swclk and swdio pins of the SD link to the stm32 swclk and swdio pins finally connect the sd-link V2 to your laptop or PC while the stm32 cube IDE is open go to the file menu then to new and click on the stm32 project stm32 Cube IDE may take a moment to load and download the necessary libraries please be patient during this process as it may take some time depending on the speed of your internet connection on the target selection window and while the MCU selector tab is active select the commercial part number that is stm32f103c8d6 select it from the mcu's list and then click on the next button write the project name select the targeted language Target binary type in targeted project type on the pin out end configuration tape click on the system core and select says click on the debug and select serial via click on the connectivity and select i2c2 you can see the pb10 and pb11 pins are selected on the left side click on core then Inc right click and select new file write the file name liquidcrystal.h you can see the liquid crystal.h header file has been added now copy and paste this code save this file then go to the SRC folder and create a new file write the file name Liquid Crystal underscore i2c.c copy this code and paste it in the Liquid Crystal underscore i2c.c file and also save this file you can download these codes from a website electronic clinic.com now go to the main.c file and add the header file then scroll down and under the user code begin to copy and paste this code the purpose of this code is to initialize and clear the LCD on the first Ruby print hello and next to it we print fold once the code is completed click on the hammer icon or build there are no errors and warnings now we can click on the play button click on the debugger tab select SD link click on show generate options set the reset mode to Software System reset and click the apply button and then click the OK button you can see the message hello world printed on the i2c support 16 into LCD and next example we are going to interface an analog sensor with the stm32 board and we will print its value on the 16 into LCD in this fifth example I'm going to use an analog sensor with the stm32 board I will read its value and then print its value on the i2c supported 16 into 2 LCD you can see I'm using a potentiometer as the analog sensor for this experiment you can use any airlock sensor like for example an ldr Etc anyway I'm going to continue with this potentiometer let me explain the interfacing the 16 into two LCD of wiring remains exactly the same as explained in the previous example the potentiometer left most and rightmost legs are connected to the stm32 3.3 volt and ground pins and the middle leg of the potentiometer is connected to the pb1 all the analog pins are 3.3 volt standard pencil make sure the voltage on the analog pins does not exceed 3.3 volts anyways you can follow this circuit diagram before we start the programming first we will need to connect the stm32 port to the laptop or PC I'm going to modify the previous project go to the i2c lcd.ioc click on the analog and select adc1 and under the adc1 mode and configuration select in9 which is the gpio pb1 pin on the stm32 click on continuous conversion and enable it finally click on the save button if it asks you do you want to generate code click yes again press the yes button I have already written this code simply copy and paste this code in the main.c file you can download this code from a website electronic clinic.com once the code is completed click on the hammer icon or build there are no errors and warnings now we can click on the play button you can see the value changes as I rotate the knob of the potential meter you can use the same program with all types of analog sensors for reading and displaying the raw data next I am going to explain how to use an i2c supported or LED display module with the stm32 controller board in this sixth example I'm going to show you how to print text on this i2c supported SSD 1306 or LED display module in most of your upcoming projects you will need this OLED display model for printing text messages and sensors values in this example I'll print the hello world message on this OLED display module anyway let's take a look at the connections the sad 1306 or LED display module VCC and ground pins are connected to the stm32 3.3 volt and ground pins the scl and SDA pins are connected to the stm32 gpio pins pb10 and pb11 pb10 is the scl and pb11 as the SDA you can follow this circuit diagram before we start the programming first you will need to connect the stm32 port to the laptop or PC while the stm32 cube IDE is open go to the file menu think to new and click on the stm32 project stm32 Cube IDE may take a moment to load and download the necessary libraries please be patient during this process as it may take some time depending on the speed of your internet connection on the target selection window and while the MCU selector tab is active select the commercial part number that is stm32f103c8d6 selected from the mcu's list and then click on the next button write the project name select the targeted language Target binary type in targeted project type on the pin out in configuration tape click on the system core and select says click on the debug and select serial via click on the connectivity and select i2c2 you can see the pb10 and pb11 pins are selected click on the i2c speed mode and select fast mode finally click on the save button if it asks you do you want to generate code click yes again press the yes button next we will add these dot C and dot h files exactly the same way as we did in the example number four we will add C files in the SRC folder and dot h files in the Inc folder you can download these codes from the article available on electroniclinic.com foreign [Music] foreign [Music] foreign .c files have been added now we can close all these files because these are already added in the SRC and Inc folders I have already written the program so I'm going to copy and paste it in the main.c file for the step-by-step explanation to read my article I start off by adding the required header files the purpose of this section of code is to print the hello world message on the OLED display module you can see the hello world message on the SSD 1306 or LED display module now you can add this OLED display module and all those projects where you need to print text or sensor values in the next example we are going to measure the distance using the ultrasonic sensor and then we'll print the major distance on this OLED display module get your LTM 365 workspace activated because ultim 365 provides a useful solution in cases when you are facing difficulties with your PCB design and unsure of your next step you can share your project and ultim designer or on the web with any user in just a few clicks you will have full control over who you want to give freed only access for let's say comments and design inspections and who you want to give read write access to allow full Global collaboration by a geographically dispersed team with editing performed through ultim designer let me show you how to share your project simply right click on the project name and select share write the user's email select read or write permissions from the drop down menu on the right and click on the share button it's just that simple I've added links to the ultim designer ultium 365 and octopod the world's fastest component search engine in this seventh example we are going to make a distance measurement system using the hc-desh sr04 ultrasonic sensor with the stm32 microcontroller board will measure the distance in centimeters and then we'll print it on the SD 13060 LED display module anyway let's go ahead and take a look at the connections the OLED display module wiring with the stm32 remains exactly the same the ultrasonic sensor VCC and ground pins are connected to the stm32 board 5-fold and ground pins the Echo and Trigger pins are connected to the stm32 gpio pins pb8 and pb9 pb8 and pb9 are 5 volt tolerant pins so it doesn't matter if I use Firefall to power up the ultrasonic sensor you can follow this circuit diagram before we start the programming first you will need need to connect the stm32 port to the laptop or PC for this we are going to use the SD link V2 simply connect the SD link V2 3.3 volt and ground pins to the 3.3 volt and ground pins on the stm32 port connect the swclk and swd I O pins of the SD link to the stm32 swclk and swdio pins finally connect the sd-link V2 to your laptop or PC I'm going to continue with the same or LED display module programming go to the OLED Dot ioc I'm going to use the same scl and SDI pens for the OLED display module go to the system core and click on the RCC select Crystal or ceramic resonator next go to timers select timer 1. select the clock source as internal clock next click on the pa8 pin and select timer 1 channel 1. next go to the connectivity and as you can see I'm using the same i2c2 for the OLED display Mario next click on the pb9 and set it as output then click on the pb8 and set it as input then go to clock configuration and change the hclk to 72 megahertz finally click on the save button if it asks you do you want to generate code click yes again press the yes button stm32 Cube IDE will generate the necessary code based on your PIN configuration and open the associated perspective this perspective provides you with the appropriate tools and views for further development and customization of your project I've already written this code for you so simply copy and paste it in the main.c file more than 70 percent of the code is automatically generated I only added this portion of the code in the while function and I also added these pins definitions and defined some variables anyway once your program is completed then you can save the program and click on the hammer icon to check for any errors and finally click on the play button to run the project we just built ourselves a distance measurement system using the hc-sr04 ultrasonic sensor and OLED display module and the stm32 microcontroller board so that's all for now support me on patreon for more videos I hope you liked today's episode like and share this video with your friends see you in next episode and thanks for watching