pin configuration -> application " />

iMX257 pin configuration function/memory read and write function

Publisher:EnchantedDreamLatest update time:2024-08-13 Source: cnblogs Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Three header files to include:

#include "mx257_gpio.h"

#include "mx25_pins.h"

#include "iomux.h"

1. GPIO pin usage

Select Pin Mode->Pin Configuration->Apply for GPIO->Set Pin Input/Output->Read GPIO->Release Pin Mode->

Release GPIO

1. Select the pin mode (ALT0-ALT7)

int mxc_request_iomux(iomux_pin_name_t pin, iomux_pin_cfg_t cfg)

void mxc_free_iomux(iomux_pin_name_t pin, iomux_pin_cfg_t cfg)

Example: mxc_request_iomux(GPIO2_21, MUX_CONFIG_ALT5);

mxc_free_iomux(GPIO2_21, MUX_CONFIG_ALT5);

#define GPIO2_21 MX25_PIN_CLKO (defined in mx25_pin.h)

2. Set the pin configuration

void mxc_iomux_set_pad(iomux_pin_name_t pin, u32 config)

Example: mxc_iomux_set_pad(GPIO2_21, 0);

#define GPIO2_21 MX25_PIN_CLKO (defined in mx25_pin.h)

void mxc_iomux_set_gpr(iomux_gp_func_t gp, bool en);

This function enables/disables the general purpose function for a particular signal.

3. Apply for GPIO

int gpio_request(unsigned gpio, const char *label)

void gpio_free(unsigned gpio)

Example: gpio_request(IOMUX_TO_GPIO(GPIO2_21), "GPIO2_21");

gpio_free(IOMUX_TO_GPIO(GPIO2_21));

4. Set the input and output mode of the pin:

Related documents:

/drivers/gpio/gpiolib.c

/arch/arm/plat-mxc/gpio.c

/arch/arm/plat-mxc/include/mach/gpio.h

输入:int gpio_direction_input(unsigned gpio)

Example: gpio_direction_input(IOMUX_TO_GPIO(GPIO2_21)); //Set GPIO2_21 to input mode

#define GPIO2_21 MX25_PIN_CLKO (defined in mx25_pin.h)

输出:int gpio_direction_output(unsigned gpio, int value)

Example: gpio_direction_output(IOMUX_TO_GPIO(GPIO2_21), 0); // GPIO2_21 outputs 0

gpio_direction_output(IOMUX_TO_GPIO(GPIO2_21), 1);    // GPIO2_21输出1

5. Get the value of the pin

int gpio_get_value(unsigned int gpio)

Note: Each time you read the value of a pin, you must first set the gpio pin to input mode

Example: gpio_direction_input(IOMUX_TO_GPIO(GPIO3_15));

data = gpio_get_value(IOMUX_TO_GPIO(GPIO3_15));

Related documents:

arch/arm/plat-mxc/include/mach/gpio.h

drivers/gpio/gpiolib.c

arch/arm/plat-mxc/gpio.c

In the gpio.h file

① #define gpio_get_value __gpio_get_value is defined (defined in gpiolib.c)

②Call chip->get in __gpio_get_value, and the actual call is to the mxc_gpio_get function in the arch/arm/plat-mxc/gpio.c file

2. Register Operation

1. Memory mapping, IO ports

#define iounmap(addr)                ((void)0)

#define ioremap(physaddr, size)            (physaddr)

#define ioremap_nocache(physaddr, size) (physaddr)

#define ioremap_writethrough(physaddr, size)    (physaddr)

#define ioremap_fullcache(physaddr, size)    (physaddr)

2. Read mapped memory, IO port, read byte port (8bit)/word port (16bit)/long word port (32bit)

#define readb(addr) ({ unsigned char __v = (*(volatile unsigned char *) (addr)); __v; })

#define readw(addr) ({ unsigned short __v = (*(volatile unsigned short *) (addr)); __v; })

#define readl(addr) ({ unsigned long __v = (*(volatile unsigned long *) (addr)); __v; })

#define inb(addr)     readb (addr)

#define inw(addr)     readw (addr)

#define inl(addr)     readl (addr)

#define in_8(addr)     readb (addr)

#define in_be16(addr)     readw (addr)

#define in_be32(addr)     readl (addr)

#define inb_p(port)        inb((port))

#define inw_p(port) inw((port))

#define inl_p(port)        inl((port))

Or: val = *((unsigned char*) (0xc00b0fe4));

io_mem = ioremap(0xfb000000,0x200000);

val = *((unsigned char*)(io_mem+0x100000));

3. Write mapped memory and IO ports

#define writeb(b, addr) (void)((*(volatile unsigned char *) (addr)) = (b))

#define writew(b, addr) (void)((*(volatile unsigned short *) (addr)) = (b))

#define writel(b, addr) (void)((*(volatile unsigned int *) (addr)) = (b))

#define outb(x, addr)    ((void) writeb (x, addr))

#define outw(x, addr)    ((void) writew (x, addr))

#define outl(x, addr)    ((void) writel (x, addr))

#define out_8(addr,x )     outb (x,addr)

#define out_be16(addr,x )    outw (x,addr)

#define out_be32(addr,x )    outl (x,addr)

#define outb_p(val, port)    outb((val), (port))

#define outw_p(val, port) outw((val), (port))

#define outl_p(val, port) outl((val), (port))

4. Memory and IO port copy

#define memset_io(a,b,c) memset((void *)(a),(b),(c))

#define memcpy_fromio(a,b,c) memcpy((a),(void *)(b),(c))

#define memcpy_toio(a,b,c) memcpy((void *)(a),(b),(c))

When copying, the source address and destination address will automatically increase.

Example: Clear memory: memset_io(start,0,*size);

5. Batch read, read a string of bytes/words/long words

(source, destination, size)

static inline void io_insb (unsigned long port, void *dst, unsigned long count)

{

unsigned char *p = dst;

while (count--)

*p++ = inb (port);

}

static inline void io_insw (unsigned long port, void *dst, unsigned long count)

{

unsigned short *p = dst;

while (count--)

*p++ = inv(port);

}

static inline void io_insl (unsigned long port, void *dst, unsigned long count)

{

unsigned long *p = dst;

while (count--)

*p++ = inl(port);

}

#define insb(a,b,l) io_insb(a,b,l)

#define insw(a,b,l) io_insw(a,b,l)

#define insl(a,b,l) io_insl(a,b,l)

Example: insb(adr, data, size);

6. Batch write

(destination, source, size)

static inline void io_outsb (unsigned long port, const void *src, unsigned long count)

{

const unsigned char *p = src;

while (count--)

outb (*p++, port);

}

static inline void io_outsw (unsigned long port, const void *src, unsigned long count)

{

const unsigned short *p = src;

while (count--)

outw (*p++, port);

}

static inline void io_outsl (unsigned long port, const void *src, unsigned long count)

{

const unsigned long *p = src;

while (count--)

outl (*p++, port);

}

#define outsb(a,b,l) io_outsb(a,b,l)

#define outsw(a,b,l) io_outsw(a,b,l)

#define outsl(a,b,l) io_outsl(a,b,l)

Example: outsb(adr, data, size);


Reference address:iMX257 pin configuration function/memory read and write function

Previous article:Debugging and analysis of the implementation of mymsg and myprintk under proc in imx257
Next article:IMX257 virtual network card vnet driver

Recommended ReadingLatest update time:2024-11-15 01:49

IMX257 BEEP driver implementation
1. Determine the base address of the relevant register Determine the IOMUX address 0x43fa_c000 0x43fa_ffff Address of GPIO1 0x53fc_c000 0x53fc_ffff MUX_CTL register offset address 0x011c PAD-CTL register offset 0x0314 GPIO register offset address
[Microcontroller]
IMX257 BEEP driver implementation
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号