# Introduction to STM32
###### tags: `tutorial` `electrical_system` `NTURT` `CAN bus`
##### Author: @solarLiterature
## STM32
<!--
You can see a microcontroller pretty much everywhere electronic sensing and controlling is required for their versatility and the affordable price. It appears in phone chargers, 3D printers, almost any appliance with the word "smart" in its name, and in our case, cars. STM32 is a family of microcontrollers which is utilized in our vehicle to do various tasks, so knowing how it works is important for people working with the hardware in the team.
-->
Microcontrollers are ubiquitous in electronic devices, providing versatile and cost-effective solutions for sensing and control. You can find them in phone chargers, 3D printers, and nearly any "smart" appliance. In our specific case with cars, the STM32 microcontroller family plays a crucial role, handling various tasks within the vehicle. As a result, it is essential for team members working with the hardware to have a comprehensive understanding of how these microcontrollers function. This knowledge empowers them to effectively utilize and optimize the STM32 microcontrollers to enhance the performance and capabilities of our vehicle.
<!--
STM32 is a huge ecosystem, and the community, tools, and resources are very diverse, so it can be like looking into a pile of uncatalogued books when first googling about it. Therefore, this intro hopes to provide some general information about STM32 before you go out there and start looking for other resources.
-->
The STM32 ecosystem is vast and encompasses a diverse range of resources, tools, and a thriving community. However, when you first begin exploring it, the sheer volume of information can be overwhelming, akin to searching through an unorganized collection of books. This introduction aims to offer you some essential background knowledge about STM32 before you embark on your quest for further resources. By understanding the basics presented here, you'll be better equipped to navigate the wealth of information available and make the most out of the STM32 ecosystem.
There's a video, a slide, and a HackMD page for this part. Most of the content is on the video, and you can see this page as the skeleton of this part.:new_moon_with_face:
Have fun! (please)
## Youtube Video
[STM32](https://www.youtube.com/watch?v=1L_I03t4S6I)
[STM32 slides pdf](https://cool.ntu.edu.tw/courses/7119/files/2521793?module_item_id=639345)
<!--
Note: When looking for a blue pill board and an STLink, be sure to get one from a trust-worthy source and make sure that you are getting a genuine ST chip on board for both the dev board and the downloader! There are a lot of counterfeit chips out in the wild and we never know which would not work and how to make it work.
Counterfeit chips may or may not have the name "STM32F103C8T6" written on it, so at least we can be sure that anything that is not called "STM32F103C8T6" is not a genuine chip as a first step for checking.
-->
Important Note: When purchasing a blue pill board and an STLink for your projects, it is crucial to ensure that you acquire them from a reputable and trustworthy source. Verify that both the development board and the downloader contain genuine ST chips. Unfortunately, counterfeit chips are prevalent, making it challenging to determine which ones will work reliably.
Counterfeit chips may lack the official label "STM32F103C8T6," but not all of them will bear this name. As an initial step for verification, avoid any chips that do not carry the "STM32F103C8T6" label, as they are likely not genuine.
Being cautious and vigilant about the authenticity of the components you purchase will help prevent potential issues and ensure the smooth functioning of your projects. Always purchase from reliable sources to guarantee the quality and performance of your STM32-based devices.
## Hardware of STM32
### MCU family
[STM32 32-bit Arm Cortex MCUs](https://www.st.com/en/microcontrollers-microprocessors/stm32-32-bit-arm-cortex-mcus.html)
You can find more details for each MCU line on the left of the page.
What's MCU?:[第一次使用MCU: 微控制器基本架構](https://medium.com/%E7%A8%8B%E5%BC%8F%E6%84%9B%E5%A5%BD%E8%80%85/%E7%AC%AC%E4%B8%80%E6%AC%A1%E4%BD%BF%E7%94%A8mcu-%E5%BE%AE%E6%8E%A7%E5%88%B6%E5%99%A8%E5%9F%BA%E6%9C%AC%E6%9E%B6%E6%A7%8B-4bb0673ce040)
### development boards
[Official Nucleo boards](https://www.st.com/en/evaluation-tools/stm32-nucleo-boards.html)
[Official Discovery boards](https://www.st.com/en/evaluation-tools/stm32-discovery-kits.html)
[the "Blue Pill"](https://stm32-base.org/boards/STM32F103C8T6-Blue-Pill.html)
## General Workflows
## Libraries for STM32
hardware registers
HAL+LL (Check out the official doc below)
SPL
[LibOpenCM3](https://github.com/libopencm3/libopencm3)
## Software Tools of STM32
[STM32CubeMX](https://www.st.com/en/development-tools/stm32cubemx.html)
[STM32CubeIDE](https://www.st.com/en/development-tools/stm32cubeide.html)
[STM32CubeProgrammer](https://www.st.com/en/development-tools/stm32cubeprog.html)
[MDK-ARM](https://www2.keil.com/mdk5)
linux toolchain (make, gcc, gdb, st-link...)
PlatformIO
ArduinoIDE?
and more...
If you are having trouble downloading CubeIDE...
[How to Download STM32CubeIDE - Simple Tutorial for Embedded Systems](https://www.youtube.com/watch?v=qy03y_L-fgA)
If you don't have an account, you can just give ST an email address to receive the download link.
## Other Resources
### Official Documents
Everything we know about a microcontroller all boils down to the official documents. The most important documents are
1. [datasheet](https://www.st.com/resource/en/datasheet/stm32f103c8.pdf)
The datasheets tell you all about the chip's electrical characteristics and basic functionalities.
3. [reference manual](https://www.st.com/resource/en/reference_manual/rm0008-stm32f101xx-stm32f102xx-stm32f103xx-stm32f105xx-and-stm32f107xx-advanced-armbased-32bit-mcus-stmicroelectronics.pdf)
The reference manual tells you in detail how every part of an STM32 chip works and how you may use them through hardware registers.
5. [Description of STM32F1 HAL and low-layer drivers](https://www.st.com/content/ccc/resource/technical/document/user_manual/72/52/cc/53/05/e3/4c/98/DM00154093.pdf/files/DM00154093.pdf/jcr:content/translations/en.DM00154093.pdf)
This is the official document for the libraries made by ST. Most of it is generated by doxygen, so you can read it in the source code as well.
7. [STM32CubeIDE user guide](https://www.st.com/resource/en/user_manual/um2609-stm32cubeide-user-guide-stmicroelectronics.pdf)
all the relavant documents for STM32C8:[STM32F103C8](https://www.st.com/en/microcontrollers-microprocessors/stm32f103c8.html#documentation)
There is no other tutorial out there that is going to be more completed then the official docs. Never forget your datasheet and reference manual or you will be lost in the forest of transistors.
### LibOpenCM3
Beginning STM32: Developing with FreeRTOS, libopencm3 and GCC (Link not included because it's a book)