Commit 0a4f3793 authored by Angus Ainslie's avatar Angus Ainslie

m4_main : lots of cleanup

* fix the xputhex function
* add xputint function
* use the updated IOMUX variable
* move some things out a header file
* add gpio functionality
parent ff5a7c20
......@@ -7,15 +7,17 @@ CFLAGS += -g
CFLAGS += -march=armv7e-m -mthumb
AFLAGS += -march=armv7e-m -mthumb
OBJS = m4_start.o m4_main.o iomux-v3.o ddr_loader.o gpio.c
all: m4.bin
m4.bin: m4_ocram.elf
${OBJCOPY} -O binary $^ m4.bin
m4_tcm.elf: m4_start.o m4_main.o iomux-v3.o ddr_loader.o
m4_tcm.elf: $(OBJS)
${CC} $(CXXFLAGS) -o $@ $^ -fno-zero-initialized-in-bss -mcpu=cortex-m4 -mfloat-abi=softfp -mthumb -mlittle-endian -T ldscript -nostartfiles -Wl,-Map,m4.map,--cref,-n
m4_ocram.elf: m4_start.o m4_main.o iomux-v3.o ddr_loader.o
m4_ocram.elf: $(OBJS)
${CC} $(CXXFLAGS) -g -o $@ $^ -fno-zero-initialized-in-bss -mcpu=cortex-m4 -mfloat-abi=softfp -mthumb -mlittle-endian -T ldscript -nostartfiles -Wl,-Ttext,0x00900000,-Map,m4.map,--cref,-n
clean:
......
/*
* Copyright (C) 2018 Purism
*
* SPDX-License-Identifier: GPL-3.0+
*/
#include "io.h"
#include "gpio.h"
uint32_t bank_base[] = {
GPIO1_BASE,
GPIO2_BASE,
GPIO3_BASE,
GPIO4_BASE,
GPIO5_BASE
};
void gpio_set_input_mask( int bank, uint32_t mask )
{
uint32_t reg;
reg = __raw_readl((void *)bank_base[bank] + GPIO_DIR_OFFSET);
reg &= ~mask;
__raw_writel(reg, (void *)bank_base[bank] + GPIO_DIR_OFFSET);
}
void gpio_set_input(int bank, int gpio)
{
gpio_set_input_mask(bank, 1<<gpio);
}
void gpio_set_output_mask( int bank, uint32_t mask )
{
uint32_t reg;
reg = __raw_readl((void *)bank_base[bank] + GPIO_DIR_OFFSET);
reg |= mask;
__raw_writel(reg, (void *)bank_base[bank] + GPIO_DIR_OFFSET);
}
void gpio_set_output(int bank, int gpio)
{
gpio_set_output_mask(bank, 1<<gpio);
}
void gpio_set_reg(int bank, uint32_t mask)
{
uint32_t reg;
/* we could set the loopback on the mux so we could read
the value back from the PSR */
reg = __raw_readl((void *)bank_base[bank] + GPIO_DR_OFFSET);
reg |= mask;
__raw_writel(reg, (void *)bank_base[bank] + GPIO_DR_OFFSET);
}
void gpio_set_bit(int bank, int gpio)
{
gpio_set_reg(bank, 1<<gpio);
}
void gpio_clr_reg(int bank, uint32_t mask)
{
uint32_t reg;
/* we could set the loopback on the mux so we could read
the value back from the PSR */
reg = __raw_readl((void *)bank_base[bank] + GPIO_DR_OFFSET);
reg &= ~mask;
__raw_writel(reg, (void *)bank_base[bank] + GPIO_DR_OFFSET);
}
void gpio_clr_bit(int bank, int gpio)
{
gpio_clr_reg(bank, 1<<gpio);
}
uint32_t gpio_read_reg(int bank)
{
return __raw_readl((void *)bank_base[bank] + GPIO_DR_OFFSET);
}
int gpio_read_bit(int bank, int bit)
{
uint32_t reg;
reg = __raw_readl((void *)bank_base[bank] + GPIO_DR_OFFSET);
return (reg >> bit) & 1;
}
/*
* Copyright (C) 2018 Purism
*
* SPDX-License-Identifier: GPL-3.0+
*/
#ifndef __GPIO_H__
#define __GPIO_H_
#define GPIO1_BASE 0x30200000
#define GPIO2_BASE 0x30210000
#define GPIO3_BASE 0x30220000
#define GPIO4_BASE 0x30230000
#define GPIO5_BASE 0x30240000
#define GPIO_DR_OFFSET 0x00 /* Data register */
#define GPIO_DIR_OFFSET 0x04 /* direction register */
#define GPIO_PSR_OFFSET 0x08 /* pad status register */
#define GPIO_ICR1_OFFSET 0x0c /* interrupt configuration register */
#define GPIO_ICR2_OFFSET 0x10 /* interrupt configuration register */
#define GPIO_IMR_OFFSET 0x14 /* interrupt mask register */
#define GPIO_ISR_OFFSET 0x18 /* interrupt status register */
#define GPIO_ES_OFFSET 0x1c /* edge select register */
void gpio_set_input_mask( int bank, uint32_t mask );
void gpio_set_input(int bank, int gpio);
void gpio_set_output_mask( int bank, uint32_t mask );
void gpio_set_output(int bank, int gpio);
void gpio_set_reg(int bank, uint32_t mask);
void gpio_set_bit(int bank, int gpio);
void gpio_clr_reg(int bank, uint32_t mask);
void gpio_clr_bit(int bank, int gpio);
uint32_t gpio_read_reg(int bank);
int gpio_read_bit(int bank, int bit);
#endif /* __GPIO_H__ */
#ifndef __M4_H__
#define __M4_H_
#include "spi.h"
#define NIRQ 256
#if !defined( __ASSEMBLER__ )
static void (*cortexM4_irq_table[])(void);
struct irq_vector {
int irq_num;
void *func;
};
#endif /* __ASSEMBLER__ */
#endif /* __M4_H__ */
......@@ -29,11 +29,14 @@
*/
#include <inttypes.h>
#include <stddef.h>
#include "io.h"
#include "iomux-v3.h"
#include "iomux-mx8mq.h"
#include "ddr_loader.h"
#include "m4.h"
#include "gpio.h"
#define CONADDR1 0x30860000 // UART1
#define CONADDR2 0x30890000 // UART2
......@@ -87,7 +90,7 @@
#define DEBUG
static void
void
xputc(char c, int console)
{
#ifdef DEBUG
......@@ -114,16 +117,56 @@ xputs(char *s)
}
}
void xputhex( int h )
void xputhex_digit( uint8_t d )
{
char c, i = 28;
xputs("0x");
while( i > 0 )
{
c=((h>>i)&0xf) + '0';
xputc(c, CONSOLE_PORT);
i -= 4;
}
char c;
if(d > 9)
c = (d - 10) + 'a';
else
c = d + '0';
xputc(c, CONSOLE_PORT);
}
void xputhex( uint32_t h )
{
char i = 28, val;
xputs("0x");
while( i > 0 ) {
val = (h>>i)&0xf;
xputhex_digit(val);
i -= 4;
}
xputhex_digit(h&0xf);
}
void xputint( int d )
{
int negative = 0, i = 0;
char str[16];
if (d == 0) {
xputc('0', CONSOLE_PORT);
return;
}
if (d < 0) {
d = d * -1;
negative = 1;
}
while (d > 0) {
str[i++] = (d % 10) + '0';
d = d / 10;
}
if (negative)
xputc('-', CONSOLE_PORT);
while (i >= 0)
xputc(str[i--], CONSOLE_PORT);
}
static void
......@@ -176,14 +219,20 @@ cortexM4_main(void)
__raw_writel(0, (void *)TCMU_ARG_M4);
__raw_writel(ST_READY, (void *)TCMU_ST_M4);
//iomux_v3_setup_pad(IMX8MQ_PAD_UART1_RXD__UART1_RX);
//iomux_v3_setup_pad(IMX8MQ_PAD_UART1_TXD__UART1_TX);
iomux_v3_setup_pad(IMX8MQ_PAD_UART2_RXD__UART2_RX);
iomux_v3_setup_pad(IMX8MQ_PAD_UART2_TXD__UART2_TX);
iomux_v3_setup_pad(IMX8MQ_PAD_GPIO1_IO13__GPIO1_IO13);
//iomux_v3_setup_pad(IMX8MQ_PAD_GPIO1_IO13__PWM2_OUT);
//iomux_v3_setup_pad(MX8MQ_IOMUXC_UART2_RXD_UART2_DCE_RX);
//iomux_v3_setup_pad(MX8MQ_IOMUXC_UART2_TXD_UART2_DCE_TX);
setup_uart(2,115200);
//setup_uart(CONSOLE_PORT,115200);
xputs("Cortex M4 starting\r\n");
gpio_set_output(1, 13);
gpio_set_bit(1, 13);
for (;;)
{
xputs("Cortex M4 waiting for commands\r\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment