LED driver of embedded Linux

Posted by Birdmansplace on Sun, 15 Mar 2020 08:47:12 +0100

The difference and connection of different versions of LED driver

Resources related to this article:
1,Assembly C language imitates STM32 official SDK BSP project management) LED driver
Note: the assembly file in the LED driver is not rewritten and cannot be used for the uboot startup. bin file. If you want to use the uboot startup, please Interrupt vector table of embedded Linux 3, Code in interrupt experiment writing is transplanted to it (assembly LED is not applicable)

Compile LED

After the previous introduction, I will not introduce it here. See the article for details Assembly LED of embedded Linux
It's posted here because it's also a kind of LED driver. Except for this, others are written by C, so other comparisons don't include assembly led

C language LED

This is the simplest of the four. It can be said that this is the core code of the other three, because the other is a further encapsulation based on this.
Partial code introduction

#define CCM_CCGR0 			*((volatile unsigned int *)0X020C4068)
#define CCM_CCGR1 			*((volatile unsigned int *)0X020C406C)
#define CCM_CCGR2 			*((volatile unsigned int *)0X020C4070)


	CCM_CCGR0 = 0xffffffff;
	CCM_CCGR1 = 0xffffffff;
	CCM_CCGR2 = 0xffffffff;

This is part of the code of the project, which is to directly operate the address of each register of CCGR

Imitation STM32 LED

As the name implies, STM32 imitates STM32's operation mode of register - structure, which simplifies the trouble of inputting each register, and uses the characteristics of structure to input only the first address of a continuous set of registers
The GPIO part of imx6ul.h is listed below

 * Base address of peripheral register group 
#define GPIO1_BASE                  (0x0209C000)
#define GPIO2_BASE                  (0x020A0000)
#define GPIO3_BASE                  (0x020A4000)
#define GPIO4_BASE                  (0x020A8000)
#define GPIO5_BASE                  (0x020AC000)
 * GPIO Register structure
typedef struct 
	volatile unsigned int DR;							
	volatile unsigned int GDIR; 							
	volatile unsigned int PSR;								
	volatile unsigned int ICR1; 							
	volatile unsigned int ICR2; 							 
	volatile unsigned int IMR;								 
	volatile unsigned int ISR;			
	volatile unsigned int EDGE_SEL;  

 * Peripheral pointer 
#define GPIO1				((GPIO_Type *)GPIO1_BASE)
#define GPIO2				((GPIO_Type *)GPIO2_BASE)
#define GPIO3				((GPIO_Type *)GPIO3_BASE)
#define GPIO4				((GPIO_Type *)GPIO4_BASE)
#define GPIO5				((GPIO_Type *)GPIO5_BASE)

This is the part of LED initialization

/* 3,Initialize GPIO */
GPIO1->GDIR = 0X0000008;	/* GPIO1_IO03 Set as output */

/* 4,Set gpio1 ﹣ io03 output low level, turn on LED0 */	
GPIO1->DR &= ~(1 << 3);	

It can be seen that the operation mode is basically the same as STM32.

Official SDK LED

For the reason of using the official SDK, the peripheral architectures imitating STM32 are manually input by themselves. There are many 6ull peripherals, so it's not realistic to manually input them by themselves. The SDK package provides the file and the definition of the architectures of all peripherals

#define     __I     volatile 
#define     __O     volatile 
#define     __IO    volatile

typedef   signed          char int8_t;
typedef   signed short     int int16_t;
typedef   signed           int int32_t;
typedef unsigned          char uint8_t;
typedef unsigned short     int uint16_t;
typedef unsigned           int uint32_t;
typedef unsigned long     long uint64_t;
typedef	  signed char  	 	   s8;		
typedef	  signed short 	  int  s16;
typedef	  signed int 		   s32;
typedef	  signed long long int s64;
typedef	unsigned char 		   u8;
typedef	unsigned short int     u16;
typedef	unsigned int 		   u32;
typedef	unsigned long long int u64;

There are many data types used in the SDK package, so we need to define some common data types in cc.h.
We use MCIMX6Y2 in the derices directory of the SDK package (this depends on the specific chip)
FSL? Iomuxc. H contains the configuration of many io ports

BSP engineering management LED

The purpose of BSP project management is to organize the code in a modular way, and the files with the same attribute are stored in the same directory. To lay the foundation for later writing larger projects
1. Create a new folder and put the files of the same property in the corresponding folder.
2. Modify the clk, led and delay drivers, create the corresponding driver files, and then place them in the corresponding directory.
3. Modify the main.c file according to the new driver file.

Published 12 original articles, praised 0, visited 324
Private letter follow

Topics: SDK C Linux Attribute