当前位置:网站首页>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 = .;
}
边栏推荐
- Redis common configuration description
- Guys, I have no problem running locally in diea, running on the server. What's wrong with the lack of CDC connection? The database IP can be pinged
- [Extension Program - cat scratch 1.0.15 _ online video and audio acquisition artifact _ installation tutorial plus acquisition]
- Solve the problem that gd32f207 serial port can receive but send 00
- 870. Approximate number
- strlen函数剖析和模拟实现
- Valdo2021 - vascular space segmentation in vascular disease detection challenge (2)
- Leetcode 48 rotating image (horizontal + main diagonal), leetcode 221 maximum square (dynamic programming DP indicates the answer value with ij as the lower right corner), leetcode 240 searching two-d
- Understand the domestic open source Magnolia license series agreement in simple terms
- Getting started with COM programming 1- creating projects and writing interfaces
猜你喜欢

Choose the appropriate container runtime for kubernetes
![[training Day8] series [matrix multiplication]](/img/00/06f7eb935bfd3c195e2e135197b4bd.png)
[training Day8] series [matrix multiplication]
![[training Day6] game [mathematics]](/img/b2/09c752d789eead9a6b60f4b4b1d5d4.png)
[training Day6] game [mathematics]

Analysis and Simulation of strlen function

Istio二之流量劫持过程

Flink window & time principle

TCP sliding window, singleton mode (lazy and hungry) double checked locking / double checked locking (DCL)

Google's display of Chrome browser icons was abandoned, and it was intended to be a small rocket

Home Assistant中接入博联WiFi智能遥控

147-利用路由元信息设置是否缓存——include和exclude使用——activated和deactivated的使用
随机推荐
Microservice architecture | service monitoring and isolation - [sentinel] TBC
Conversion between VC string and timestamp
Using videoview to realize video playback in turns
Hcip early summary
Sword finger offer 46. translate numbers into strings
Sword finger offer 47. the maximum value of gifts
Data transmission of different fragments in the same activity
Interface component devaxpress asp Net v22.1 - new office 365 dark theme
Getting started with COM programming 1- creating projects and writing interfaces
Introduction to WDK development 1- basic environment construction and the first driver (VS2010)
Redis common configuration description
[training Day8] [luogu_p6335] staza [tarjan]
Valdo2021 - vascular space segmentation in vascular disease detection challenge (I)
870. Approximate number
Flink Window&Time 原理
Setting up a dual machine debugging environment for drive development (vs2017)
Sword finger offer 53 - I. find the number I in the sorted array
Functional test of redisgraph multi active design scheme
Unit DLU of resource editor
Install MySQL 5.7.37 on windows10