📜 ⬆️ ⬇️

We are switching from STM32 to the Russian K1986BE92QI microcontroller. Setting up the project in keil and flashing LED

Introduction


In the last article, I shared my personal impressions of the recruitment I received and programmed the controller with a demo project using MT-LINK (it was also provided). Now that we have reviewed the entire kit in detail, it is time to start mastering it.
For the impatient - the result.



Create an empty project in Keil 5 for K1986BE92QI.


First you need to create a clean project. Of course, you can use the demo project as a basis, but the project with the number “2” did not start, and in the project “3” for some reason in the controller selection menu a blank sheet. It somehow alerted me. Project with the number "1" is not in principle.


Compile the simplest program.


Insert into the main function an infinite loop with the counter increment by 1. Now our file should look like this.



Do not forget that at the end of each file should be an empty line. Keil regards this as a warning that often gets on your nerves. Of course, it will compile, but the fact of the warning itself is alarming.
At this setting is over. We can recompile our project by pressing F7. If everything went well, we will see it.


Now it remains only to configure J-LINK in the settings and you can upload. How to configure it - was described in detail in the previous article.

By the way. J-LINK sees the chip without connecting additional power, as well as allows you to debug the chip. So external power is not particularly necessary. When navigating through the lines of the code, you can see how the screen tint flashes.

We adjust a controller leg for work with a LED


Having run through the table of contents of the documentation, I did not see anything about the timing of the periphery, so I immediately set about adjusting it. Remembering all the horrors of SPL in terms of setting up I / O ports in the STM32, the thought of using the bundled libraries disappeared immediately. And it’s not good, just like that, without having time to play with registers, hide behind libraries, in which, by the way, mistakes are not excluded.

First, let's understand which port we need to configure. In the "Debug Board 1986EV92U, K1986BE92QI (MDR32F9Q2I) \ Printed circuit board 1986EvBrd_LQFP64" there is a file 1986EvBrd_64_Rev2.pdf, which shows the circuit board. On it, we can see that 2 LEDs are connected to PC0 and PC1 pins. Fine. Do not have to suffer with displacement.



I liked very much that Milandra had all the information about the chip line in one document. The STM32 is very confused with the documents ... Let's look at the I / O port diagram. Something vaguely resembles the port scheme of the STM32. Not seeing anything that would have caught the eye, we are going to tune the registers.



Since I did not know exactly how Milander called his ports, I reached into the ports configuration library. I saw the following there.



Well, a little higher.



After making sure that the address of port C coincides with the address in the data sheet, I created a new function in the main.c file (The main function is surely higher! Otherwise, the function prototypes in the .h file will have to be described. And these are unnecessary troubles for now.).

I start writing PORTC-> (by habit), hold down ctrl + space and see the following.



This is a familiar picture. Very happy. Then I began to look at which registers needed to be changed.



We need an LED on the port "0", so we can write: PORTC-> RXTX | = 1;

With this we translate the 0th bit of the port to 1. Thus, lighting the diode on port 0. But before turning it on, it is worth setting it up ...
So this action is performed last and before.



We have a way out, so: PORTC-> OE | = 1;



We leave unchanged, since the default is zero everywhere.



And here we need digital: PORTC-> ANALOG | = 1;



We do not need a brace, so skip it.



Well, we don’t need that either ...



And here we need to choose the speed. The default is everything. Choosing a slow front. For the LED it is quite enough: PORTC-> PWR | = 1;



Well, the last register. Generally unknown to me earlier thing. This has yet to be resolved.

Well, with the setting we finished. BUT, if we now sew up this code, then nothing will work. For a long time I tried to understand what the problem was, yet once again I did not carefully read about the clocking system. There is not a word about clocking in the ports section. But there is a separate chapter in which it is written how and what needs to be clocked. I went there and saw the following.



We need ports. This fits well with the description "peripheral blocks". We are looking for this register and here.



It remained only to understand how keil is called this register. Since I did not find anything in the libraries, I went with a selection. As a result, it turned out that it is called RST_CLK. Well, then we only need to write "1" in the desired block.

RST_CLK-> PER_CLOCK | = (1 << 23);
On the "PER_CLOCK" came out by chance. When I wrote “RST_CLK” I pressed ctrl + space and after the list appeared, “p”. After choosing the appropriate option.

The result is such a code.



The code compiles and we get.



Russian comments in keil 5


Now it is worthwhile to place comments on the code, but this is not possible in Russian. There are incomprehensible characters, in order to be able to write Russian comments, you need to go to Edit -> Configuration.



And there change the encoding, as shown in the figure. Then click "OK".



Blink LED

Now we will write a code that will flash using the LED.



We sew and rejoice! The speed is taken from the LED flashing experience on the STM32. The LED flashes at a rate of approximately once per second.

Everything. It seems to have missed nothing. I advise you to archive this project immediately. Then to use as a blank.

The project is attached to the article .

Once again I remind you. In the project settings there is one link to the project directory relative to “C: \”. So the project will work only in the same way as in the article. You can easily change the way and use it freely.
Thank you sguwenka for fixes.

Source: https://habr.com/ru/post/255323/


All Articles