{"id":8764,"date":"2014-12-04T06:38:53","date_gmt":"2014-12-04T11:38:53","guid":{"rendered":"http:\/\/embedded-lab.com\/blog\/?p=8764"},"modified":"2023-04-20T22:58:59","modified_gmt":"2023-04-21T02:58:59","slug":"stm32-prior-to-start","status":"publish","type":"post","link":"https:\/\/embedded-lab.com\/blog\/stm32-prior-to-start\/","title":{"rendered":"STM32 &#8211; Prior to Start"},"content":{"rendered":"<p style=\"text-align: left\" align=\"center\"><span style=\"font-size: 0.95em;line-height: 1.6em\">STM32 ARM-based micros from STMicroelectronics pack high density resources than any other conventional microcontroller. They are also high speed devices, operating typically at 72MHz and beyond. Despite several advanced features and heavy resources, they turn out to be misfortunes for beginners who wish to play with them. Available in market are several cool STM32 boards but most of them are not well documented. The aim of this document is to address some common FAQs.<\/span><\/p>\n<p style=\"text-align: left\">Typically most people ask the following question:<\/p>\n<ul style=\"text-align: left\">\n<li><i>How to program the STM32 micro embedded in my development board?<\/i><\/li>\n<li><i>What tools do I need to get started?<\/i><\/li>\n<li><i>What compiler support do I have for STM32?<\/i><\/li>\n<li><i>What resources are available for STM32 on the internet?<\/i><\/li>\n<\/ul>\n<p style=\"text-align: left\">In this doc, I\u2019ll be addressing these FAQs along with some basics as I had similar questions in my early expeditions with STM32 micros. When I started with STM32 these questions were there as they are now. Literally there was nothing to address them till now. Most experts take it for granted that those who are beginning with ARMs must have heavy knowledge on the topic and thus skip answering these simple or silly questions.<\/p>\n<p style=\"text-align: left\">Well I decided to break this stalemate for any starter no matter what\u2019s his\/her experience. Firstly most people nowadays believe ARM is only for mobile phones, PDAs, tablets, etc. and can\u2019t be used like other micros like AVRs and PICs. This is completely wrong. Firstly because no one has set such a rule and secondly because there\u2019s no limit to requirements in an embedded design. However it would be wasteful to make simple LED blinking stuffs with such chips. When it comes to size and resources ARM varies in all aspects. You can have an ARM chip with similar resources available in a typical 8 bit or 16 bit micro and yet you can also have an ARM chip with high resources. For instance if you think of flash memory, an ARM chip can have a few kilobytes to several megabytes of flash memory. Thus not just for real-time operating systems, phones, DSP, graphical processing and so on but also for other kinds of embedded systems the door for ARM is always open. It\u2019ll completely depend on its user. STM32 portfolio has wide ranges of 32 bit ARM micros just as I described. A quick look on ST\u2019s page will give you a brief idea: <a href=\"http:\/\/www.st.com\/web\/en\/catalog\/mmc\/FM141\/SC1169\">http:\/\/www.st.com\/web\/en\/catalog\/mmc\/FM141\/SC1169<\/a> .<\/p>\n<p style=\"text-align: left\">Answering from the last, let\u2019s see what resources are available for STM32s on the internet. Going back to ST\u2019s site one can clearly see that there are several app notes for STM32s. At the time of writing this doc there 83 app notes on ST\u2019s page. Obviously then there are reference manuals, datasheet and other docs too. Of these the important ones are the datasheet of a particular micro and its family reference manual. The rest of the stuffs are various software and tools but here confusion arises. We\u2019ll see what other things are needed later but for now let\u2019s see the purpose of reference manuals and datasheet. The reference manual is needed for understanding the internal hardware of a particular STM32 family, the registers associated with these hardware, programming techniques and what \u201cnot\u201ds and what \u201care\u201ds. These make it the core document of all. Datasheet basically give overviews of the devices. Books available for STM32-based ARMs are hard to find but still found a book called Discovering STM32 on Google search\u2019s first page.<\/p>\n<p style=\"text-align: left\">Regarding compiler selection, there are several available for STM32 micros. The most common ones are Keil, CooCox and MikroC PRO for ARM. My personal favourite is MikroC (<a href=\"http:\/\/www.mikroe.com\/mikroc\/arm\/\">http:\/\/www.mikroe.com\/mikroc\/arm\/<\/a>) as I\u2019m already familiar with MikroC for AVR and 8051. MikroC comes with lot of easy-to-use built-in and examples and so it\u2019s a good compiler to work with. Anyone familiar with MikroC will not have any trouble using it for ARM. With MikroC one can go to raw levels and he\/she can also go for easy library-based coding.<\/p>\n<p style=\"text-align: left\">Now let\u2019s see what tools we\u2019ll need for STM32 micros. The first tool we\u2019ll need is called <b>Flash Loader Demonstrator<\/b> (<a href=\"http:\/\/www.st.com\/web\/en\/catalog\/tools\/PF257525\">http:\/\/www.st.com\/web\/en\/catalog\/tools\/PF257525<\/a>).\u00a0 Basically it\u2019s a programmer GUI based on factory loaded bootloader that allows a user to load, erase, verify, read or set configuration bits for his\/her STM32 micro. The second tool is called <b>Microxplorer<\/b> (<a href=\"http:\/\/www.st.com\/web\/en\/catalog\/tools\/PF251717\">http:\/\/www.st.com\/web\/en\/catalog\/tools\/PF251717<\/a>). This tool allows a user to graphically set configurations for IO ports, internal hardware and many more. Basically it\u2019ll help you reduce your time debugging registers. Both of these software are free and easy to use.\u00a0 The last but not the least tool is called <b>Timer Calculator<\/b> (<a href=\"http:\/\/www.libstock.com\/projects\/view\/398\/timer-calculator\">http:\/\/www.libstock.com\/projects\/view\/398\/timer-calculator<\/a>). It\u2019s a handy tool for those who\u2019ll use MikroC for ARM. It can be used to generate codes for timer interrupts and timer-based stuffs. There are other tools too.<\/p>\n<p style=\"text-align: left\">The final topic is about loading code to a STM32 micro. There are two ways either by a JTAG programmer like ST-Link or by bootloader and UART. The former is the best choice as it is a programmer and a debugger but in terms of expense this is unnecessary as the chips come with preprogramed bootloader. Thus the latter method of using bootloader and UART is simplest and also the most popular solution. This is also my personal preference as I didn\u2019t want to spend for another programmer just for the purpose studying. This is the method I\u2019ll describe here. Let\u2019s see the board:<\/p>\n<p style=\"text-align: left\" align=\"center\"><i style=\"font-size: 0.95em;line-height: 1.6em\"><a href=\"http:\/\/embedded-lab.com\/blog\/stm32-prior-to-start\/untitled\/\" rel=\"attachment wp-att-8765\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8765\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/06\/Untitled.png\" alt=\"Untitled\" width=\"308\" height=\"203\" \/><\/a><\/i><\/p>\n<p style=\"text-align: left\"><!--more--><\/p>\n<p style=\"text-align: left\">This baby is about the size of a standard match box and contains the basic components needed for its STM32F108C8 micro. This one comes from LC-Technology China (<a href=\"http:\/\/www.lctech-inc.com\/Hardware\/Detail.aspx?id=0172e854-77b0-43d5-b300-68e570c914fd\">http:\/\/www.lctech-inc.com\/Hardware\/Detail.aspx?id=0172e854-77b0-43d5-b300-68e570c914fd<\/a>) and is reasonably cheap. I have also other ARM boards but this one is my favourite because of its compact size and portability. Most STM32F10x board have similar features and no matter what board is chosen there\u2019ll literally no difference at all.<\/p>\n<p>Now let\u2019s see the important parts of the board:<\/p>\n<p><a href=\"http:\/\/embedded-lab.com\/blog\/stm32-prior-to-start\/board-features\/\" rel=\"attachment wp-att-8766\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8766\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/06\/board-features.png\" alt=\"board features\" width=\"287\" height=\"372\" \/><\/a><\/p>\n<p>These are the least common features of any STM32 development board must have. Here\u2019s the schematic of the board:<\/p>\n<p><a href=\"http:\/\/embedded-lab.com\/blog\/stm32-prior-to-start\/schema\/\" rel=\"attachment wp-att-8767\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8767\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/06\/schema.png\" alt=\"schema\" width=\"601\" height=\"395\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/06\/schema.png 601w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/06\/schema-550x361.png 550w\" sizes=\"auto, (max-width: 601px) 100vw, 601px\" \/><\/a><\/p>\n<p>To demonstrate Flash Loader Demonstrator I made a setup for a wasteful LED blinking project with STM32 just for the sake of giving a demo. Here\u2019s the setup:<\/p>\n<p><a href=\"http:\/\/embedded-lab.com\/blog\/stm32-prior-to-start\/setup-10\/\" rel=\"attachment wp-att-8768\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8768\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/06\/setup.png\" alt=\"setup\" width=\"601\" height=\"358\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/06\/setup.png 601w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/06\/setup-550x327.png 550w\" sizes=\"auto, (max-width: 601px) 100vw, 601px\" \/><\/a><\/p>\n<p>The needed tools here are a PC, a FT232 USB-UART converter, a LED breakout board and of course a STM32 board. Since the micro is empty the LEDs are all off. Now let\u2019s upload a code in it. Before we do that please have a look in \u201cBoot Configuration\u201d section of STM32F103\u2019s reference manual and also locate the boot jumpers of your board.\u00a0Usually <b><i>Boot 0<\/i><\/b> is kept low and <b><i>Boot 1<\/i><\/b> high to enter bootloader mode after reset.<\/p>\n<p><a href=\"http:\/\/embedded-lab.com\/blog\/stm32-prior-to-start\/boot\/\" rel=\"attachment wp-att-8769\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8769\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/06\/boot.png\" alt=\"boot\" width=\"471\" height=\"353\" \/><\/a><\/p>\n<p>The first photo below shows the jumper settings during normal running and the second shows the settings needed during uploading code. Every time the jumpers are altered a reset is a must. To do so just hit the reset switch briefly.<\/p>\n<p><a href=\"http:\/\/embedded-lab.com\/blog\/stm32-prior-to-start\/setup2-4\/\" rel=\"attachment wp-att-8770\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8770\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/06\/setup2.png\" alt=\"setup2\" width=\"716\" height=\"464\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/06\/setup2.png 716w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/06\/setup2-550x356.png 550w\" sizes=\"auto, (max-width: 716px) 100vw, 716px\" \/><\/a><\/p>\n<p>Be sure to change jumpers when changing modes. Shown below are step-step ways of loading a code using boot loader and UART. Prior to entering boot loader mode change the jumper and hold reset before clicking \u201cNext\u201d in the Flash Loader Demonstrator GUI. This is similar to entering the boot loader mode of an Arduino but manually.<\/p>\n<p><a href=\"http:\/\/embedded-lab.com\/blog\/stm32-prior-to-start\/setup2-6\/\" rel=\"attachment wp-att-8772\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8772\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/06\/setup22.png\" alt=\"setup2\" width=\"862\" height=\"324\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/06\/setup22.png 862w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/06\/setup22-550x206.png 550w\" sizes=\"auto, (max-width: 862px) 100vw, 862px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/embedded-lab.com\/blog\/stm32-prior-to-start\/screen2\/\" rel=\"attachment wp-att-8773\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8773\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/06\/screen2.png\" alt=\"screen2\" width=\"849\" height=\"451\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/06\/screen2.png 849w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/06\/screen2-550x292.png 550w\" sizes=\"auto, (max-width: 849px) 100vw, 849px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/embedded-lab.com\/blog\/stm32-prior-to-start\/screen3\/\" rel=\"attachment wp-att-8774\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8774\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/06\/screen3.png\" alt=\"screen3\" width=\"874\" height=\"334\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/06\/screen3.png 874w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/06\/screen3-550x210.png 550w\" sizes=\"auto, (max-width: 874px) 100vw, 874px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/embedded-lab.com\/blog\/stm32-prior-to-start\/screen4\/\" rel=\"attachment wp-att-8775\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8775\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/06\/screen4.png\" alt=\"screen4\" width=\"851\" height=\"673\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/06\/screen4.png 851w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/06\/screen4-550x434.png 550w\" sizes=\"auto, (max-width: 851px) 100vw, 851px\" \/><\/a><\/p>\n<p>After flashing the STM32, the code runs as shown below:<\/p>\n<p><a href=\"http:\/\/embedded-lab.com\/blog\/stm32-prior-to-start\/out\/\" rel=\"attachment wp-att-8776\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8776\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/06\/out.png\" alt=\"out\" width=\"328\" height=\"193\" \/><\/a><\/p>\n<p>I hope it was helpful. Happy coding.<\/p>\n<p>Repository: <a href=\"https:\/\/github.com\/sshahryiar\/STM32-Tutorials\">https:\/\/github.com\/sshahryiar\/STM32-Tutorials<\/a><\/p>\n<p><i>Author: Shawon M. Shahryiar<br \/>\n<\/i><\/p>\n<p><a href=\"https:\/\/www.youtube.com\/c\/sshahryiar\">https:\/\/www.youtube.com\/c\/sshahryiar<\/a><\/p>\n<p><a href=\"https:\/\/github.com\/sshahryiar\">https:\/\/github.com\/sshahryiar<\/a><\/p>\n<p><a href=\"mailto:sshahryiar@gmail.com\"><i>sshahryiar@gmail.com<\/i><\/a><i><\/i><i>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0<\/i><\/p>\n","protected":false},"excerpt":{"rendered":"<p>STM32 ARM-based micros from STMicroelectronics pack high density resources than any other conventional microcontroller. They are also high speed devices, operating typically at 72MHz and beyond. Despite several advanced features and heavy resources, they turn out to be misfortunes for beginners who wish to play with them. Available in market are several cool STM32 boards but most of them are not well documented. The aim of this document is to address some common FAQs. Typically most people ask the following question: How to program the STM32 micro embedded in my development board? What tools do I need to get started?<\/p>\n","protected":false},"author":5,"featured_media":8765,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[733,1474,1466],"tags":[798,799,734,1319],"class_list":["post-8764","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-stm32","category-stm32-tutorials","category-tutorials","tag-32-bit-microcontroller","tag-advanced-embedded-systems","tag-arm","tag-stm32"],"_links":{"self":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/8764","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/comments?post=8764"}],"version-history":[{"count":9,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/8764\/revisions"}],"predecessor-version":[{"id":15153,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/8764\/revisions\/15153"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/media\/8765"}],"wp:attachment":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/media?parent=8764"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/categories?post=8764"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/tags?post=8764"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}