Stm32f103 programming

Embedded Lab

When looking at a few pages on the STM32; I was a bit skeptical on how easy it would be to program this board. I have seen tutorial where you need to fiddle with the onboards jumpers; then strategically press the reset button. That seemed really not user friendly. In fact; it is really easy to program the blue pill board, and none of this gymnastic is actually necessary. Chances are the shop that is selling the blue pill board also sells a ST-Link. These cheap copies do not provide a full pin JTAG connector; but it is not needed for this Cortex M3 based micro-controller; so it is perfectly adequate for the job. The installation might take a while. The Blue Pill is pretty much devoid of any on board peripherals, but it has at least an on board LED. At the end you should have a message similar to the one below:. Note: My STM32 board came pre-loaded with a blinking sketch. To go further and make full use of the board and its hardware peripherals; be sure to refer to this pinout diagram; courtesy of Rasmus Friis Kjeldsen:. Search Search ….

Introducing to STM32 ADC programming. Part2

Microcontroller Tutorials. One thing I can say is that there's not much resource that I can easily find about this board the ST website has lots of info but not very friendly to newbies like me which is the thing that discouraged me from studying it. But then one day I decided to suck it all up and just find whatever tutorial or datasheet that I can find that can teach me a few things about this board. The purpose of this tutorial would be to help you get started with programming the STM32F1 Discovery board, the same way I did with mine. I will provide more in-depth tutorials in the near future. You will be needing Keil to program this device. Keil is an older platform developed by ARM for programming their microcontrollers and microprocessors. You can download it here. Find the "get software" button at the bottom of the page. You may need to register to continue. You also need the ST-Link Utility software to download your firmware to the board. Locate the firmware package you've downloaded. Here you will find the file shown in the picture:. If your Keil is version 5 like me, a dialog box will appear like the one below. Just press the "Migrate to Device Pack" button. This will download the necessary files for the example project. After that, you can now see the main. But I'll tell you, you will get the hang of it if you spend more time with it. The next we'll do is we will replace the entire contents of the main. The next step is to download the program to the board. By this time, your board should be already connected to your computer via USB. Next, press the Settings button and click on the Debug tab. Find the port option and change it to SW. Press OK to close the dialog box and now you're ready to burn the program to your board. If everything's OK, this should be the last message shown:. So what was that program we just loaded to the board? Oh, you also need to press the reset button on the board after loading the program. After that, the LED should be blinking. We needed three header files in order for this to work: the main header file stm32f10x. We also initiate our delay function here as we used it after the main function which would result in a compiler error if we didn't. As it turns out, you need to enable the clock of the STM32F1 discovery's peripheral because they are not enabled at power on. This is what. Next, you need to specify and configure the GPIO you will be using. Finally, the last part of the code is the delay function. For example, if the value of a is then it would take this function would count tokeeping the CPU busy, thus a delay. So that's it! I'll be doing a full-pledge STM32F1 discovery tutorial in the future. In the mean time, if you have any questions or reactions, just leave a comment below.

Subscribe to RSS

To understand simple things lets go with the simplest case — single conversion mode. In this mode, ADC does one conversion and then stops. The same situation is if the injected channel is converted. In our example, we are going to measure the internal temperature sensor value and send it using USART. The algorithm will start single conversion and wait for conversion complete flag EOC. So we should see value in the terminal screen. The code for single conversion is pretty short:. When standard peripheral functions are used, everything becomes simple. First, we set enable ADC peripheral clock:. It is connected to APB2 bus. Then we disable scan mode and continuous scan as we want only single conversion and stop. We also disable any external triggering and select data to be right aligned. This is done by using the command:. After ADC is set up and the sensor is woken, we can configure channel Here we need to set several parameters including channel number, the index in the group and channel sampling time:. After microcontroller is powered on it is recommended to run ADC self-calibration. This calculates error correction codes for capacitors and reduces overall error in the result. After reading the temperature sensor, we get some bit digital value. To calculate temperature we need to use a formula:. Here we get that V25 is typically 1. When using 3. Having these temperature value can be easily calculated:. It can serve only to detect temperature variations inside the chip. It is always better to use an external sensor for accurate readings. This is how data looks in the terminal screen. The first read ls room temperature and the second is with some heat applied to the microcontroller:. This code is only to demonstrate the most straightforward ADC usage. Practically it is Very inefficient because there are loop used for waiting for ADC to be complete. There are better ways of doing this like using interrupts or DMA. Next time we will try different ADC mode used more efficiently. How to find out on which channel was made last conversion. Could you make some example of basic multi channel conversion, where every channel has another function meaning of different source and where will be seems how to get these different values without DMA? You can find this in datasheet. In DS CD But there is no ADC12, right? I am confused now. Could you please explain it?

How to program a STM32 “Blue Pill” with Arduino

STM32 Microcontrollers which uses ARM Cortex M architecture is now becoming popular and are used in many applications because of its feature, cost and performance. Programming STM32 with Arduino IDE is simple, as there are lots of libraries available for various sensors to perform any task, we just need to add those libraries in the program. This is an easy procedure and you may not get into deep learning about the ARM processors. So now we are getting into the next level of programming called ARM programming. By this we can, not only improve our structure of the code but can also save memory space by not using unnecessary libraries. Further this generated code can be used in Keil uVision for editing according to requirement. It is available in a variety of colours. The body is made out of aluminium alloy. The pin names are clearly marked on the shell as we can see in the above image. It can be interfaced with the Keil software where the program can be flashed to the STM32 microcontrollers. Note: When connecting ST-Link with the computer for first time. We need device driver to be installed. Device drivers can be found in this link according to your operating system. This software tool makes the development easy by reducing development effort, time and cost. You can download this tool from the following link. So we need not to power the STM32 separately. The table below shows the connection between ST-Link and Blue pill board. A push button is connected to provide input to the pin PA1 of Blue Pill board. We must also use a pull up resistor of value 10k because the pin might float without any input when the button is released. We can also select our pins in the peripherals section according to our project. Step You can also click on the pin directly and a list appears, now select the required pin configuration. You can note that in below image. Step Next in this pin configuration box we can configure User Label for pins we are using, that is user defined pin names. Step Now the project settings dialog box appears. In this box choose your project name and location and select the development environment. Step Now the code generation dialog box appears. Select Open Project to open project automatically the generated code in Keil uvsion. Step Now the Keil uVision tool opens with our generated code in STM32CubeMx with the same project name with necessary library and codes that are configured for the pins we selected. So select our main. Step Now add the code in the while 1 loop, see the below image where I highlighted that section to run the code continuously.

Arduino Alternative - STM32 Blue Pill Programming Via USB

For reading a button, we need to configure a GPIO pin in digital input mode. The logic voltage of STM32 is 3. We can use 5V logic level to this 5V tolerant input pins. The characteristic of a GPIO pin when it is configured in input mode is shown in figure below. This is the button circuit for this tutorial. I also add an LED in this circuit just for showing the state of the button is pressed or not. This is the example code. The purpose of this code is to turn on the LED when the button is pressed and turn off the LED when it is not pressed. For the project file you can get it from here. You can use other GPIO input modes, which are input with internal pull-down or input floating. For input floating, you must add an external pull-up or pull-down resistor. This is the example circuit for input with internal pull-down and input floating with external pull-up. Go to the part 4 of the tutorial. Your email address will not be published. All source codes included. The output driver is disabled. The schmitt trigger input is activated. The weak pull-up and pull-down resistors are activated or not depending on the input configuration pull-up, pull-down, or floating. A read access to the input data register obtains the GPIO pin state. Button Circuit This is the button circuit for this tutorial. Example Code This is the example code. GPIO read button. Leave a Reply Cancel reply Your email address will not be published. Do you want to deploy machine learning on microcontrollers? Find out more on deeplearningedge.

STM32 Bootloader - Programming STM32 using usb cable - Flashing bootloader in STM32 - Arduino IDE

Comments on “Stm32f103 programming

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>