Why did you start thinking about embedded development? In the past five years, from cloud computing, big data to machine learning, AI, a variety of new technological concepts wave after wave.

As an inquisitive software programmer, EVERY technological concept became popular.

However, in my technology stack, all the software developed requires PC, mobile phone interaction.

How to break? Do embedded development!

Several years ago, a friend who is engaged in embedded development gave me the knowledge of embedded development. Because he has been busy with his work, he did not really have serious contact with me. Until this year, he started his own business, he seriously considered whether embedded can bring new opportunities to himself.

Choose STM32 at first, my friend recommended raspberry PI as the development board for me to get started.

Raspberry PI can install the operating system, the price is moderate, the function is perfect, almost is a low performance small computer, used to be familiar with all kinds of pin functions, play with common sensor equipment is very convenient, but also can be very cheap to build Linux operating system, very suitable for beginners to build Linux development environment.

But it doesn’t learn anything about real embedded development. It’s very cheap compared to a PC, but it’s too power, too big and too expensive for an embedded product.

After consulting friends, decided to choose a real single-chip development board to learn embedded development.

On the Internet to find information, learned that the current popular microcontroller

51 series: classic, there are many books and courses written about 51 series: AVR: Atmel’s new MCU, said to be used to replace 51 STM32/STM8: ST company’s ARM core MCU STC51: It is said to be a combination of AVR and 51. I chose STM32. Here’s why:

See in the technical forum, 51 although classic, but it is really a bit outdated, technical indicators and functions are not as good as STM32 cost-effective STM32, many functions, but the price is still very cheap, the smallest system board compared to other MCU boards are very cheap. There is enough information. However, some people criticize the information is too complicated, because STM32 provides many functions, so the content of learning is naturally much more, for example, the clock has 5, which is more complicated than 51. Complete IDE and library. So far, this is what I find most convenient about STM32, and what really makes it possible to get started with zero basics. Official eclipse-based IDE, HAL hardware abstraction library (C language), in the premise of completely did not learn the principle of single-chip computer, a little look at HAL library, you can do some simple small experiments. (To know, most 51 MCU tutorial, is to learn a little register knowledge and assembly language knowledge to really start). Most of the microcontroller development environment in Windows is very convenient, but in OSX there are few good IDE and debugging software, but the ST official provided cross-platform all-in-one development tools. Hands-on visit the official website of ST Company. www.st.com

By the way, the update speed of SCM is not as fast as that of software, so the technical information on the Internet is not as much as that of software, and the update speed is not timely. But it happens that ST Company has updated a lot of content in the past two years. For example, STM32CubeMX, STM32CubeProgrammer, STM32CubeIDE are less introduced, ST company also packages HAL library (hardware abstraction library), the operation of the register are packaged into easy to use functions, so I suggest you try to access the information through the official website. As you can see, the ST company has many products, and 32-bit microprocessors are just one of them. STM32 is ST’s 32-bit Microprocessor.

The first step is to download the IDE. Search stm32cubeIDE directly in the search box above the official website of ST

image.png

STM32CubeIDE is an all-in-one multi-OS development tool, STM32CubeIDE is a multi-functional cross-platform development tool based on ECLIPSE™/CDT, which is part of the STM32Cube software ecosystem.

image

In the learning phase, STM32CubeIDE, which includes configuration tools and debugging tools, is sufficient.

The second step is to choose a development board and software development is different, in addition to a computer, we also need to buy a single chip microcomputer. But a single chip microcomputer is not directly used to learn, we need to buy a single chip microcomputer development board with some simple functions and leads to pins.

If you search STM32 development board directly, you can see many different models and prices of development board. How to choose next?

The price of SCM itself is very cheap, a few to a dozen, but the price gap of the development board is very big, a few to dozens or even hundreds of pieces. The price difference is mainly due to the different peripheral functions of the development board. There are a lot of boards with a lot of interfaces, so the price is also high, but we are not sure to use it in the beginner’s study. As a beginner, I choose the minimum system board.

The minimal system board, which contains only some basic interfaces, leads, is small and inexpensive. But there are several versions of the minimum system board, and the difference is mainly in the STM32 microprocessor model.

Take a look at image.png on our website

image.png

As can be seen from the figure, ST company divides the processor into many models according to the performance and use, among which F0 and F1 series are more suitable for beginners to learn, which is also the reason why there are more searches for STM32 development board F0 and F1 on some bao, among which F103C8T6 model is the most, because its performance and function are rich enough. Fully adapted for learning, one of the development boards code-named “BluePill” is very useful and inexpensive. The BluePill development board looks like this, compared to buy it, the price is around 12-22 (beginners are advised to buy welded stitches) : image.png

Buy buy buy, suggest to buy 2-3 pieces, based on my experience, has a very small chance to buy has a problem of the board, have 2-3 board, if there are any questions found, can change to try to check the problem is their own or of the board, and as a novice, have biscuit of 3 two standby board, can rest assured bold to play, not afraid of playing bad, learning more efficient.

Step 3 Purchase accessories In addition to the development board, we also need to purchase some equipment for debugging and development. When I was learning, I did not understand at all, and there was no one around me to guide me. I bought a board and was confused. How to use it, and then I could complete the accessories bit by bit to do experiments.

Necessary accessories:

Write procedures st-Link V2: written procedures installed into the microcontroller tool bread board: convenient circuit to do experiments dupont line: Connect circuit necessary, public, public and female, all buy mini USB power supply and line (general Android phone charger and line can be) optional accessories (beginners do not need to use, but want to in-depth, sooner or later need to use) :

Sensors: It would be interesting to experiment with sensors in addition to the small lights that control the development board. Light-emitting diodes (leds) : Similar to sensors, they’re all for experimentation. Resistance: a lot of leds rated voltage current is very low, need to combine resistance USB TTL switch: another way to write a program, in addition, do serial port debugging on the computer will use tin welding equipment fourth step writing program equipment are fully configured, you can start the first small experiment.

Take BluePill development board as an example, first connect ST-Link V2, the connection method is very simple, TX on the development board is connected to ST-Link RX, RX on the development board is connected to ST-Link TX, Gnd on the development board is connected to ST-Link Gnd, Vcc is connected to Vcc, Then plug it into the USB port of your computer.

image.png

Open STM32CubeIDE, create a new project, and some configuration options will appear in the navigation.

Eclipse will not be covered, but will focus on the STM32 library choice.

Different models of processors, libraries and configurations are different, therefore, before the new project, STM32CubeIDE will be required to select the single-chip model, input the corresponding single-chip model in the search box, and then select confirm in the list.

image.png

image.png

After that, the IDE initializes the project with the corresponding library.

After the project is created, open the.ioc file image.png in the left file window

This file is very important, before ST company launched CubeMX, doing initialization is very troublesome things, with any pins, configure the clock, interrupt enable, serial port configuration and so on all need to write initialization code. Now, CubeMX visualizes all of this work, and CubeIDE integrates this functionality with CubeMX.

image.png

image.png

Through visual configuration, STM32CubeIDE generates standard initialization code, similar to image.png below

image.png

In the generated main.c file, you can see many comments. Note that these comments are not superfluous; they are useful. Why is that? If you modify the.ioc file, it will prompt you whether to regenerate the main.c file. In general, it must be regenerated, otherwise the modified configuration will not take effect. Will it be covered? Yes, unless your code is written in

/* USER CODE BEGIN xxxxx */

/* USER CODE END XXXXXX */ all codes that are not between USER CODE BEGIN and END will be overwritten.

The main.c generated by STM32CubeIDE leaves plenty of room for writing user code, and comments guide you to the right place. image.png

Next, write a simple experimental code that makes PinC13’s light flash on the BluePill

First, open ioc file and configure PC13 as output pin image.png

Save the configuration and regenerate the main.c file

Then add code to the main loop in the while,

while (1) { /* USER CODE END WHILE */

/* USER CODE BEGIN 3 */ / Set pin C to low level HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET); // delay 200ms HAL_Delay(200); // Set pin 13 of group C to high level HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET); // delay 200ms HAL_Delay(200);Copy the code

} /* USER CODE END 3 */ OK, a simple flashing program is done.

Step 5 Burn the program debugging remember before let st-link access, and plug in the computer? I’m going to need it.

Enable Debug to configure image.png

The wiring mode of SWD is introduced just now, so SWD interface image.png is selected here

Under the condition of normal wiring, click the Debug button, the program can be automatically written to the microcontroller of the development board and run.

At this point, you should be able to see a quick flash of green on the BluePill.

Here, just introduced almost finished, but the knowledge of single chip microcomputer is so vast, by contrast, this article is very shallow, the tip of the iceberg, I just to introduce it from the perspective of a software programmer, think through this article want to study STM32 MCU development new classmate see a relatively complete from 0 to the first flash experiment process, According to this overview of SCM learning and development Outlines.

SCM development needs patience to learn a lot of basic knowledge, interested students can leave a message to learn together!