nanoPc T2 bare metal development (1)

-----------------------------Write in front

It's been a long time since I played the MCU. The stm32 I played before is not learning at all. I just use the 51 knowledge I learned before and the library functions that call the atom. If there is anything wrong, please correct me, thank you.

refer to:

http://wiki.friendlyarm.com/wiki/index.php/NanoPC-T2/zh#.E7.BC.96.E8.AF.91U-Boot

The development board is nanoPc T2 using Friendly Arm, the Soc is S5P4418, and other peripherals can be found on the wiki. I think it's pretty good, although I've only used this one, but it's still good to use.

http://weibo.com/p/1001603914482173772682

This is the routine I refer to, although I didn't go in to see it (because I don't have a Weibo...) But I have all his relevant source code, which is on the Weibo. Called the big guy Dicka, he is very strong.


----------------------------text

We need to know what kind of thing we are going to do now and have a concept. If you read the article of the big guy Deca, his topic is, play s5p4418 like playing 51, which means that we can use s5p4418 to light the lights, set the buttons, add 1602, add 12864 , use an interrupt to run the timer, this is the same function as when learning 51. (What? Can you still play like this?) That's for sure, the principles are the same, just a more complex one, with more functions, and a wider application scene.

ok, for example, we're going to use him to light a lamp. Looking back at 51, how did we do it?

1. Include the header file, reg51.h is indispensable, (the IDE has already done it for us in this step, I just need to include)

2. Function function

3. Compile and generate hex or bin files

4. Download to the target machine (ie 51 MCU)

Very simple, right, so what should we do with the nanoPc T2 we have?

1 "========" We also need a header file, which has the same function as reg51.h, but we have to write it ourselves.

2 "========" function function

3 "========" to compile and generate hex or bin files (I only tried to generate bin)

4 Download "========" to the target machine (ie s5p4418)

In fact, the steps are the same, but we lack the help of the IDE, which is a little troublesome. I have not tried whether keil can be used or not. The purpose of my trip is to understand his entire process, not just to run out a It's just the result, so refer to the program of the big dick, and understand.

So how to do it specifically?

1. The header file is formed. After reading the article of Mr. Dika, he has a very deep understanding of 51. When I was learning, I just stayed with it. He has seen the essence. A whole system is a "world" of 0 1, built up layer by layer. The bottom world is the transmission of many level signals. So, come back, the header file of 51, there are many things defined by sfr sbit, followed by a string of hexadecimal numbers, what is that? That is the absolute address of the register. The preceding string is the code name of these addresses. For example, sfr P0 0x80; you can find this register from the address of 0x80, and P0 is the code word we communicated in the upper layer. It will be restored to an absolute address.

That is to say, we have to assign a codename to s5p4418 for better communication. Ok, after knowing what we are going to do, how do we know where the addresses of their registers are? Check the datasheet of the chip, it is quite detailed, (although I didn't compare it, but it looks like a lot of pages...) What? you will not? It doesn't matter, first look at the source code written by others, see how others wrote it, and then think about why it is written, and where can I find the above information. Since I'm using the code of the big dick, I won't post it. If you want, you can go to Weibo to contact him, (I don't have Weibo yet...)

2. Assuming we have understood the header file, let's take lighting as an example, what we need to operate is the GPIO interface, then what we need to operate is the GPIO, there are so many gpio, which one do we choose?

This is a screenshot of the datasheet, and there are many more below. This is the reason why he is stronger than 51. What makes him powerful is that he has many functions, but the space is limited and the pins are not enough. The mechanism of pin multiplexing is introduced. Below we can see his package diagram,

The pins drawn from his bga package are not many for his functions. It is precisely because of the multiplexing of pins that he is expanded. The following figure is his multiplexing map,

A1 A2 A3.... corresponds to his pin, but what is the function of his pin, it needs a register to set.

This is the register we need to control the gpio to achieve the function we want.

ok, we now know what our purpose of operating the register is, and now we can configure the register to achieve our purpose.

Our purpose is to light up the led, then we have to check the schematic diagram, what pin controls the led, this will not be mapped. This board of mine is led0 controlled by GPIOB12. So, we need GPIOB12, ok, check in the pin multiplexing register, how should we operate to get GPIOB12.

These two are configuration multiplexed registers, ALTFN0 is for pins 0-15, and ALTFN1 is for pins 31-16. I need 12, so, look at 12

It seems that there is no word GPIOB12, let's look at the pin assignment diagram just now,

See, ALT Function0, 1, 2, 3 configure their function pins. GPIOB12 is 2, so assign 10.

That is, GPIOBALTFN0 |= (0X2<<24); or you can write it in hexadecimal. ok, then this pin is GPIOB12. But we control the LED to make the pin output voltage, so it needs to be configured as output mode, this is the same, it is ok to configure the corresponding register, it is very simple. The output also has corresponding control, so it is very simple to meet our requirements. At this point, our function function is finished.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325766311&siteId=291194637