How to use official SDK files to assist development

Keywords: Linux

How to use official SDK files to assist development

1. First of all, what is SDK?

SDK or SDK package refers to a software development kit synchronously launched by semiconductor manufacturers for their own chips.

It can simply provide some files of application program interface API for a programming language, but it may also include complex hardware that can communicate with an embedded system.

SDK s also often include sample code, supporting technical notes, or other supporting documentation to clarify doubts about basic resources.

I understand it this way. The SDK is like the instruction manual of the chip: it tells you which buttons there are and what functions these buttons control.

2. How to use?

First download it from the official website and then install it. You will see that there are many files in this package.

This time focus on the register related files.

1)cc.h data type header file

#ifndef __CC_H
#define __CC_H


/*
 * Customize some data types for library files
 */
#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;


#endif

You must be familiar with it. Yes, when you used to play single chip microcomputer, u32 and u64 are defined data types at the beginning and put them in the header file. Careful friends must be impressed.

Here is another basic knowledge:

Why should the header file be expressed like the following?

#ifndef __CC_H
#define __CC_H

#endif

This involves the reference of header files.

ifndef __CC_H means "if not define _cc_h"

define __CC_H is introduced__ CC_H

endif, otherwise you do not need to import

The main function is to prevent the header file from being referenced repeatedly.

The repeated reference here does not mean that two different files refer to the same header file, but that the same file references a header file multiple times.

What happens?

Because of the nesting between header functions, for example, b.h is referenced in a.c and c.h is referenced in b.h. at this time, A.C can no longer reference c.h.

What are the consequences of repeated references?

  1. Increase the amount of compilation, and the compilation efficiency is low;
  2. Duplicate definition of variable

But not all header files should use this format, but this is a good habit and should be maintained.

2)main.c

#include "fsl_common.h"

#include "fsl_iomuxc.h"

#include "MCIMX6Y2.h"

/*

 * @description	: Enable all peripheral clocks of I.MX6U
 * @param 		: nothing
 * @return 		: nothing

 */

void clk_enable(void)

{
	CCM->CCGR0 = 0XFFFFFFFF;
	CCM->CCGR1 = 0XFFFFFFFF;
	CCM->CCGR2 = 0XFFFFFFFF;
	CCM->CCGR3 = 0XFFFFFFFF;
	CCM->CCGR4 = 0XFFFFFFFF;
	CCM->CCGR5 = 0XFFFFFFFF;
	CCM->CCGR6 = 0XFFFFFFFF;
}

/*

 * @description	: Initialize GPIO corresponding to LED
 * @param 		: nothing
 * @return 		: nothing

 */

void led_init(void)

{

	/* 1,Initialize IO multiplexing */

	IOMUXC_SetPinMux(IOMUXC_GPIO1_IO03_GPIO1_IO03,0);		/* Multiplexed to GPIO1_IO0 */

	/* 2,,Configure gpio1_ IO properties of io03	
	 *bit 16:0 HYS close
	 *bit [15:14]: 00 Default drop-down
     *bit [13]: 0 kepper function
     *bit [12]: 1 pull/keeper Enable
     *bit [11]: 0 Turn off the open circuit output
     *bit [7:6]: 10 Speed 100Mhz
     *bit [5:3]: 110 R0/6 Driving capability
     *bit [0]: 0 Low conversion rate
     */

	IOMUXC_SetPinConfig(IOMUXC_GPIO1_IO03_GPIO1_IO03,0X10B0);

	/* 3,Initialize GPIO and set GPIO1_IO03 set to output  */
	GPIO1->GDIR |= (1 << 3);	

	/* 4,Set GPIO1_IO03 outputs low level and turns on LED0 */
	GPIO1->DR &= ~(1 << 3);			
}



/*
 * @description	: Turn on the LED
 * @param 		: nothing
 * @return 		: nothing
 */

void led_on(void)

{
	/* Gpio1_ bit3 clearing of Dr 	*/
	GPIO1->DR &= ~(1<<3); 
}



/*

 * @description	: Turn off the LED
 * @param 		: nothing
 * @return 		: nothing
 */

void led_off(void)

{
	/* Gpio1_ bit3 of DR is set to 1 */
	GPIO1->DR |= (1<<3); 
}

/*
 * @description	: Short time delay function
 * @param - n	: Number of cycles to delay (number of empty operation cycles, mode delay)
 * @return 		: nothing
 */

void delay_short(volatile unsigned int n)
{
	while(n--){}
}

/*

 * @description	: Delay function, at the main frequency of 396Mhz
 * 			  	  The delay time is about 1ms
 * @param - n	: Number of ms to delay
 * @return 		: nothing
 */

void delay(volatile unsigned int n)
{
	while(n--)
	{
		delay_short(0x7ff);
	}
}

/*
 * @description	: mian function
 * @param 		: nothing
 * @return 		: nothing
 */

int main(void)
{
	clk_enable();		/* Enable all clocks 			*/
	led_init();			/* Initialize led 			*/
	while(1)			/* Dead cycle 				*/
	{	
		led_off();		/* Turn off the LED 			*/
		delay(500);		/* Delay 500ms 			*/

		led_on();		/* Turn on the LED 			*/
		delay(500);		/* Delay 500ms 			*/
	}
	return 0;
}

This process is similar to the previous tweet, but with some changes. For example, the following method is used:

CCM->CCGR0 = 0XFFFFFFFF;

GPIO1->GDIR |= (1 << 3);

This - > symbol is a common structure pointer operator in a structure. It is used to access internal members of a structure.

3) makefile file

CROSS_COMPILE ?= arm-linux-gnueabihf-

NAME    ?= ledc

CC 		:= $(CROSS_COMPILE)gcc

LD		:= $(CROSS_COMPILE)ld

OBJCOPY := $(CROSS_COMPILE)objcopy

OBJDUMP := $(CROSS_COMPILE)objdump

OBJS 	:= start.o main.o

$(NAME).bin:$(OBJS)
	$(LD) -Timx6ul.lds -o $(NAME).elf $^
	$(OBJCOPY) -O binary -S $(NAME).elf $@
	$(OBJDUMP) -D -m arm $(NAME).elf > $(NAME).dis
%.o:%.s
	$(CC) -Wall -nostdlib -c -O2 -o $@ $<
%.o:%.S
	$(CC) -Wall -nostdlib -c -O2 -o $@ $<

%.o:%.c
	$(CC) -Wall -nostdlib -c -O2 -o $@ $<
clean:
	rm -rf *.o $(NAME).bin $(NAME).elf $(NAME).dis

Just pay attention to the use of variables.

The following three header files are transplanted from the SDK.

  1. fsl_common.h
  2. fsl_iomuxc.h
  3. MCIMX6Y2.h

Of course, simple tailoring is required before transplantation, because the code is too long and mostly repetitive, so it is not attached here.

Posted by st89 on Fri, 03 Dec 2021 12:00:31 -0800