当前位置:网站首页>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 = .;
}
边栏推荐
- Huawei set up login with account and password
- Introduction to fastdfs high availability
- 01 | opening words: teach you to build a blog website hand in hand
- 02 | 环境准备:如何在windows下安装和配置一个基本的php开发环境?
- Sword finger offer 45. arrange the array into the smallest number
- Valdo2021 - vascular space segmentation in vascular disease detection challenge (I)
- Framework API online viewing source code
- [training Day8] [luogu_p6335] staza [tarjan]
- Actual measurement of Qunhui 71000 Gigabit Network
- Sword finger offer 52. The first common node of the two linked lists
猜你喜欢

clip:learning transferable visual models from natural language supervision

Covid-19-20 - basic method of network segmentation based on vnet3d
![[training Day8] series [matrix multiplication]](/img/00/06f7eb935bfd3c195e2e135197b4bd.png)
[training Day8] series [matrix multiplication]

Duilib actual combat 1- imitate Baidu online disk login interface

Understand the domestic open source Magnolia license series agreement in simple terms

strlen函数剖析和模拟实现

Stop using UUID indiscriminately. Have you tested the performance gap between self incrementing ID and UUID?
![[Extension Program - cat scratch 1.0.15 _ online video and audio acquisition artifact _ installation tutorial plus acquisition]](/img/75/5eca7f63758802ecf86a90a1bbdeaf.png)
[Extension Program - cat scratch 1.0.15 _ online video and audio acquisition artifact _ installation tutorial plus acquisition]

C form application treeview control use

Alibaba cloud technology expert Yang Zeqiang: building observable capabilities on elastic computing cloud
随机推荐
Rotation matrix derivation process
Know typescript
Substr and substring function usage in SQL
Luogu - p1616 crazy herb picking
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
Use of paging assistant PageHelper
Valdo2021 - vascular space segmentation in vascular disease detection challenge (2)
[training Day6] dream [priority queue] [greed]
Inconsistent time
strlen函数剖析和模拟实现
Duilib actual combat 1- imitate Baidu online disk login interface
Wechat applet -that.setdata ({}) set complex field data
02 | 环境准备:如何在windows下安装和配置一个基本的php开发环境?
2019 Hangdian multi school first 6581 vacation [thinking]
Pure C implementation -------- Nicolas theorem
02 | environment preparation: how to install and configure a basic PHP development environment under windows?
MySQL stored procedure
Sword finger offer 52. The first common node of the two linked lists
Apache atlas version 2.2 installation
纯C实现----------尼科彻斯定理