当前位置:网站首页>1. Mx6u-alpha development board (key input experiment)
1. Mx6u-alpha development board (key input experiment)
2022-07-24 20:10:00 【*Ruthless*】
List of articles
One 、 Hardware schematic analysis
Key KEY0 Linked to UART1_CTS On the pin . By default UART1_CTS For the high , When pressed KEY0 in the future UART1_CTS For low .
Two 、 The experimental program was written
1、 Set up UART1_CTS Reuse as GPIO1_IO18
2、 Set up UART1_CTS Electrical properties of .
3、 To configure GPIO1_IO08 Is the input mode .
4、 Read the key value , That is to say GPIO1_IO08 High and low levels of
// bsp_gpio.h
#ifndef _BSP_GPIO_H
#define _BSP_GPIO_H
#define _BSP_KEY_H
#include "imx6ul.h"
/* Enumeration type and structure definition */
typedef enum _gpio_pin_direction
{
kGPIO_DigitalInput = 0U, /* Input */
kGPIO_DigitalOutput = 1U, /* Output */
} gpio_pin_direction_t;
typedef struct _gpio_pin_config
{
gpio_pin_direction_t direction; /* GPIO Direction : Input or output */
uint8_t outputLogic; /* If it's output , Default output level */
} gpio_pin_config_t;
/* Function declaration */
void gpio_init(GPIO_Type *base, int pin, gpio_pin_config_t *config);
int gpio_pinread(GPIO_Type *base, int pin);
void gpio_pinwrite(GPIO_Type *base, int pin, int value);
#endif
//bsp_gpio.h
#include "bsp_gpio.h"
void gpio_init(GPIO_Type *base, int pin, gpio_pin_config_t *config)
{
if(config->direction == kGPIO_DigitalInput) /* Input */
{
base->GDIR &= ~( 1 << pin);
}
else /* Output */
{
base->GDIR |= 1 << pin;
gpio_pinwrite(base,pin, config->outputLogic);/* Set the default output level */
}
}
int gpio_pinread(GPIO_Type *base, int pin)
{
return (((base->DR) >> pin) & 0x1);
}
void gpio_pinwrite(GPIO_Type *base, int pin, int value)
{
if (value == 0U)
{
base->DR &= ~(1U << pin); /* Output low level */
}
else
{
base->DR |= (1U << pin); /* Output high level */
}
}
//bsp_key.h
#ifndef _BSP_KEY_H
#define _BSP_KEY_H
#include "imx6ul.h"
/* Define key values */
enum keyvalue{
KEY_NONE = 0,
KEY0_VALUE,
KEY1_VALUE,
KEY2_VALUE,
};
/* Function declaration */
void key_init(void);
int key_getvalue(void);
#endif
//bsp_key.c
#include "bsp_key.h"
#include "bsp_gpio.h"
#include "bsp_delay.h"
void key_init(void)
{
gpio_pin_config_t key_config;
// initialization IO Reuse , Reuse as GPIO1_IO18
IOMUXC_SetPinMux(IOMUXC_UART1_CTS_B_GPIO1_IO18,0);
// To configure UART1_CTS_B Of IO attribute
IOMUXC_SetPinConfig(IOMUXC_UART1_CTS_B_GPIO1_IO18,0xF080);
// initialization GPIO
//GPIO1->GDIR &= ~(1 << 18); /* GPIO1_IO18 Set to input */
key_config.direction = kGPIO_DigitalInput;
gpio_init(GPIO1,18, &key_config);
}
int key_getvalue(void)
{
int ret = 0;
static unsigned char release = 1; /* Release the button */
if((release==1)&&(gpio_pinread(GPIO1, 18) == 0)) /* KEY0 */
{
delay(10); /* Delay chattering */
release = 0; /* Mark key press */
if(gpio_pinread(GPIO1, 18) == 0)
ret = KEY0_VALUE;
}
else if(gpio_pinread(GPIO1, 18) == 1)
{
ret = 0;
release = 1; /* Mark key release */
}
return ret;
}
//main.c
#include "bsp_clk.h"
#include "bsp_delay.h"
#include "bsp_led.h"
#include "bsp_beep.h"
#include "bsp_key.h"
int main(void)
{
int i = 0;
int keyvalue = 0;
unsigned char led_state = OFF;
unsigned char beep_state = OFF;
clk_enable(); /* Enable all clocks */
led_init(); /* initialization led */
beep_init(); /* initialization beep */
key_init(); /* initialization key */
while(1)
{
keyvalue = key_getvalue();
if(keyvalue)
{
switch ((keyvalue))
{
case KEY0_VALUE:
beep_state = !beep_state;
beep_switch(beep_state);
break;
}
}
i++;
if(i==50)
{
i = 0;
led_state = !led_state;
led_switch(LED0, led_state);
}
delay(10);
}
return 0;
}
CROSS_COMPILE ?= arm-linux-gnueabihf-
TARGET ?= key
CC := $(CROSS_COMPILE)gcc
LD := $(CROSS_COMPILE)ld
OBJCOPY := $(CROSS_COMPILE)objcopy
OBJDUMP := $(CROSS_COMPILE)objdump
INCDIRS := imx6ul \
bsp/clk \
bsp/led \
bsp/delay \
bsp/beep \
bsp/gpio \
bsp/key
SRCDIRS := project \
bsp/clk \
bsp/led \
bsp/delay \
bsp/beep \
bsp/gpio \
bsp/key
INCLUDE := $(patsubst %, -I %, $(INCDIRS))
SFILES := $(foreach dir, $(SRCDIRS), $(wildcard $(dir)/*.S))
CFILES := $(foreach dir, $(SRCDIRS), $(wildcard $(dir)/*.c))
SFILENDIR := $(notdir $(SFILES))
CFILENDIR := $(notdir $(CFILES))
SOBJS := $(patsubst %, obj/%, $(SFILENDIR:.S=.o))
COBJS := $(patsubst %, obj/%, $(CFILENDIR:.c=.o))
OBJS := $(SOBJS) $(COBJS)
VPATH := $(SRCDIRS)
.PHONY: clean
$(TARGET).bin : $(OBJS)
$(LD) -Timx6ul.lds -o $(TARGET).elf $^
$(OBJCOPY) -O binary -S $(TARGET).elf [email protected]
$(OBJDUMP) -D -m arm $(TARGET).elf > $(TARGET).dis
$(SOBJS) : obj/%.o : %.S
$(CC) -Wall -nostdlib -c -O2 $(INCLUDE) -o [email protected] $<
$(COBJS) : obj/%.o : %.c
$(CC) -Wall -nostdlib -c -O2 $(INCLUDE) -o [email protected] $<
clean:
rm -rf $(TARGET).elf $(TARGET).dis $(TARGET).bin $(COBJS) $(SOBJS)
3、 ... and 、 eliminate BSS
Plus clear BSS paragraph , The code doesn't run __bss_start = 0X87800289. about 32 Bit SOC Come on , The general visit is 4 Byte access .0X0,0X4,0X8,0XC. The chip is processed with 4 Byte access , So it will come from 0X878000288 Start clearing BSS paragraph . However 0X878000288 Do not belong to BSS paragraph . So we need to deal with __bss_start Carry out four byte alignment . According to the principle of four bytes ,__bss_start=0X8780028C. So you need to set __bss_start Align four bytes .
Make changes in the link script
SECTIONS{
. = 0X87800000;
.text :
{
obj/start.o
*(.text)
}
.rodata ALIGN(4) : {*(.rodata*)}
.data ALIGN(4) : { *(.data) }
__bss_start = .;
.bss ALIGN(4) : { *(.bss) *(COMMON) }
__bss_end = .;
}
边栏推荐
- Sword finger offer 47. the maximum value of gifts
- A circle is displayed and can be moved
- Istio II traffic hijacking process
- Wechat stores build order pages and automatically grab tickets
- Virtual machine win7 system installation vmtool
- Conversion between VC string and timestamp
- Leetcode 206 reverse linked list, 3 longest substring without repeated characters, 912 sorted array (fast row), the kth largest element in 215 array, 53 largest subarray and 152 product largest subarr
- Home Assistant中接入博联WiFi智能遥控
- "Hualiu is the top stream"? Share your idea of yyds
- 纯C实现----------尼科彻斯定理
猜你喜欢

Use of paging assistant PageHelper

Each blogger needs to ask himself seven basic questions

BGP - border gateway protocol

"Hualiu is the top stream"? Share your idea of yyds
![微服务架构 | 服务监控与隔离 - [Sentinel] TBC...](/img/28/8ca90e9dbd492688e50446f55959ff.png)
微服务架构 | 服务监控与隔离 - [Sentinel] TBC...

Install MySQL 5.7.37 on windows10

(posted) differences and connections between beanfactory and factorybean

聊下自己转型测试开发的历程

Getting started with COM programming 1- creating projects and writing interfaces

Valdo2021 - vascular space segmentation in vascular disease detection challenge (I)
随机推荐
纯C实现----------尼科彻斯定理
Storage category
2019 Hangzhou Electric Multi School Game 7 6651 final exam [Law + thinking]
[leetcode] 1184. Distance between bus stops
SSL Error: Unable to verify the first certificate
01 | opening words: teach you to build a blog website hand in hand
Call Baidu AI open platform to realize image and character recognition
2019 Hangdian multi school first 6581 vacation [thinking]
Istio II traffic hijacking process
Istio二之流量劫持过程
Each blogger needs to ask himself seven basic questions
Unit DLU of resource editor
Hcip early summary
Virtual machine win7 system installation vmtool
Leetcode 560 and the subarray of K (with negative numbers, one-time traversal prefix and), leetcode 438 find all alphabetic ectopic words in the string (optimized sliding window), leetcode 141 circula
Lights of thousands of families in the year of xinchou
The U.S. economy continues to be weak, and Microsoft has frozen recruitment: the cloud business and security software departments have become the hardest hit
Rotation matrix derivation process
Framework API online viewing source code
"Hualiu is the top stream"? Share your idea of yyds