aboutsummaryrefslogtreecommitdiff
path: root/examples/lpc43xx/hackrf-jellybean
diff options
context:
space:
mode:
Diffstat (limited to 'examples/lpc43xx/hackrf-jellybean')
-rw-r--r--examples/lpc43xx/hackrf-jellybean/README4
-rw-r--r--examples/lpc43xx/hackrf-jellybean/i2c/Makefile24
-rw-r--r--examples/lpc43xx/hackrf-jellybean/i2c/README5
-rw-r--r--examples/lpc43xx/hackrf-jellybean/i2c/i2cdemo.c102
-rw-r--r--examples/lpc43xx/hackrf-jellybean/jellybean-lpc4330.ld32
-rw-r--r--examples/lpc43xx/hackrf-jellybean/jellybean_conf.h80
-rw-r--r--examples/lpc43xx/hackrf-jellybean/miniblink/Makefile24
-rw-r--r--examples/lpc43xx/hackrf-jellybean/miniblink/README11
-rw-r--r--examples/lpc43xx/hackrf-jellybean/miniblink/miniblink.c82
9 files changed, 364 insertions, 0 deletions
diff --git a/examples/lpc43xx/hackrf-jellybean/README b/examples/lpc43xx/hackrf-jellybean/README
new file mode 100644
index 0000000..07aaeee
--- /dev/null
+++ b/examples/lpc43xx/hackrf-jellybean/README
@@ -0,0 +1,4 @@
+These example programs are written for the Jellybean development board from the
+HackRF project:
+
+https://github.com/mossmann/hackrf
diff --git a/examples/lpc43xx/hackrf-jellybean/i2c/Makefile b/examples/lpc43xx/hackrf-jellybean/i2c/Makefile
new file mode 100644
index 0000000..b18f122
--- /dev/null
+++ b/examples/lpc43xx/hackrf-jellybean/i2c/Makefile
@@ -0,0 +1,24 @@
+##
+## This file is part of the libopencm3 project.
+##
+## Copyright (C) 2010 Uwe Hermann <uwe@hermann-uwe.de>
+##
+## This library is free software: you can redistribute it and/or modify
+## it under the terms of the GNU Lesser General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## (at your option) any later version.
+##
+## This library is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU Lesser General Public License for more details.
+##
+## You should have received a copy of the GNU Lesser General Public License
+## along with this library. If not, see <http://www.gnu.org/licenses/>.
+##
+
+BINARY = i2cdemo
+
+LDSCRIPT = ../jellybean-lpc4330.ld
+
+include ../../Makefile.include
diff --git a/examples/lpc43xx/hackrf-jellybean/i2c/README b/examples/lpc43xx/hackrf-jellybean/i2c/README
new file mode 100644
index 0000000..0785a11
--- /dev/null
+++ b/examples/lpc43xx/hackrf-jellybean/i2c/README
@@ -0,0 +1,5 @@
+------------------------------------------------------------------------------
+README
+------------------------------------------------------------------------------
+
+This program exercises the I2C peripheral on Jellybean's LPC43xx.
diff --git a/examples/lpc43xx/hackrf-jellybean/i2c/i2cdemo.c b/examples/lpc43xx/hackrf-jellybean/i2c/i2cdemo.c
new file mode 100644
index 0000000..d6441ab
--- /dev/null
+++ b/examples/lpc43xx/hackrf-jellybean/i2c/i2cdemo.c
@@ -0,0 +1,102 @@
+/*
+ * This file is part of the libopencm3 project.
+ *
+ * Copyright (C) 2010 Uwe Hermann <uwe@hermann-uwe.de>
+ * Copyright (C) 2012 Michael Ossmann <mike@ossmann.com>
+ *
+ * This library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <libopencm3/lpc43xx/gpio.h>
+#include <libopencm3/lpc43xx/scu.h>
+#include <libopencm3/lpc43xx/cgu.h>
+#include <libopencm3/lpc43xx/i2c.h>
+
+//FIXME generalize and move to drivers
+
+#define SCU_SFSI2C0_SCL_EFP (1 << 1) /* 3 ns glitch filter */
+#define SCU_SFSI2C0_SCL_EHD (1 << 2) /* Fast-mode Plus transmit */
+#define SCU_SFSI2C0_SCL_EZI (1 << 3) /* Enable the input receiver */
+#define SCU_SFSI2C0_SCL_ZIF (1 << 7) /* Disable input glitch filter */
+#define SCU_SFSI2C0_SDA_EFP (1 << 8) /* 3 ns glitch filter */
+#define SCU_SFSI2C0_SDA_EHD (1 << 10) /* Fast-mode Plus transmit */
+#define SCU_SFSI2C0_SDA_EZI (1 << 11) /* Enable the input receiver */
+#define SCU_SFSI2C0_SDA_ZIF (1 << 15) /* Disable input glitch filter */
+
+#define I2C_CONCLR_AAC (1 << 2) /* Assert acknowledge Clear */
+#define I2C_CONCLR_SIC (1 << 3) /* I2C interrupt Clear */
+#define I2C_CONCLR_STAC (1 << 5) /* START flag Clear */
+#define I2C_CONCLR_I2ENC (1 << 6) /* I2C interface Disable bit */
+
+#define I2C_CONSET_AA (1 << 2) /* Assert acknowledge flag */
+#define I2C_CONSET_SI (1 << 3) /* I2C interrupt flag */
+#define I2C_CONSET_STO (1 << 4) /* STOP flag */
+#define I2C_CONSET_STA (1 << 5) /* START flag */
+#define I2C_CONSET_I2EN (1 << 6) /* I2C interface enable */
+
+#define CGU_SRC_32K 0x00
+#define CGU_SRC_IRC 0x01
+#define CGU_SRC_ENET_RX 0x02
+#define CGU_SRC_ENET_TX 0x03
+#define CGU_SRC_GP_CLKIN 0x04
+#define CGU_SRC_XTAL 0x06
+#define CGU_SRC_PLL0USB 0x07
+#define CGU_SRC_PLL0AUDIO 0x08
+#define CGU_SRC_PLL1 0x09
+#define CGU_SRC_IDIVA 0x0C
+#define CGU_SRC_IDIVB 0x0D
+#define CGU_SRC_IDIVC 0x0E
+#define CGU_SRC_IDIVD 0x0F
+#define CGU_SRC_IDIVE 0x10
+
+#define CGU_BASE_CLK_PD (1 << 0) /* output stage power-down */
+#define CGU_BASE_CLK_AUTOBLOCK (1 << 11) /* block clock automatically */
+#define CGU_BASE_CLK_SEL_SHIFT 24 /* clock source selection (5 bits) */
+
+void i2c0_init()
+{
+ /* enable input on SCL and SDA pins */
+ SCU_SFSI2C0 = (SCU_SFSI2C0_SCL_EZI | SCU_SFSI2C0_SDA_EZI);
+
+ /* use PLL1 as clock source for APB1 (including I2C0) */
+ CGU_BASE_APB1_CLK = (CGU_SRC_PLL1 << CGU_BASE_CLK_SEL_SHIFT);
+
+ //FIXME assuming we're on IRC at 96 MHz
+
+ /* 400 kHz I2C */
+ I2C0_SCLH = 120;
+ I2C0_SCLL = 120;
+
+ /* 100 kHz I2C */
+ //I2C0_SCLH = 480;
+ //I2C0_SCLL = 480;
+
+ /* clear the control bits */
+ I2C0_CONCLR = (I2C_CONCLR_AAC | I2C_CONCLR_SIC
+ | I2C_CONCLR_STAC | I2C_CONCLR_I2ENC);
+
+ /* enable I2C0 */
+ I2C0_CONSET = I2C_CONSET_I2EN;
+}
+
+int main(void)
+{
+ int i;
+
+ i2c0_init();
+
+ //TODO I2C tx/rx
+
+ return 0;
+}
diff --git a/examples/lpc43xx/hackrf-jellybean/jellybean-lpc4330.ld b/examples/lpc43xx/hackrf-jellybean/jellybean-lpc4330.ld
new file mode 100644
index 0000000..92c25af
--- /dev/null
+++ b/examples/lpc43xx/hackrf-jellybean/jellybean-lpc4330.ld
@@ -0,0 +1,32 @@
+/*
+ * This file is part of the libopencm3 project.
+ *
+ * Copyright (C) 2010 Uwe Hermann <uwe@hermann-uwe.de>
+ *
+ * This library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* Linker script for HackRF Jellybean (LPC4330, 1M SPI flash, 64K SRAM). */
+
+/* Define memory regions. */
+MEMORY
+{
+ /* rom is really the shadow region that points to SPI flash or elsewhere */
+ rom (rx) : ORIGIN = 0x00000000, LENGTH = 1M
+ ram (rwx) : ORIGIN = 0x10000000, LENGTH = 128K
+ /* there are some additional RAM regions */
+}
+
+/* Include the common ld script. */
+INCLUDE libopencm3_lpc43xx.ld
diff --git a/examples/lpc43xx/hackrf-jellybean/jellybean_conf.h b/examples/lpc43xx/hackrf-jellybean/jellybean_conf.h
new file mode 100644
index 0000000..a5ad8d0
--- /dev/null
+++ b/examples/lpc43xx/hackrf-jellybean/jellybean_conf.h
@@ -0,0 +1,80 @@
+/*
+ * This file is part of the libopencm3 project.
+ *
+ * Copyright (C) 2012 Benjamin Vernoux <titanmkd@gmail.com>
+ *
+ * This library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __JELLYBEAN_CONF_H
+#define __JELLYBEAN_CONF_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libopencm3/lpc43xx/scu.h>
+
+/************************/
+/* JellyBean SCU PinMux */
+/************************/
+
+/* GPIO Output PinMux */
+#define SCU_PINMUX_LED1 (P4_1) /* GPIO2[1] on P4_1 */
+#define SCU_PINMUX_LED2 (P4_2) /* GPIO2[2] on P4_2 */
+#define SCU_PINMUX_LED3 (P6_12) /* GPIO2[8] on P6_12 */
+
+#define SCU_PINMUX_EN1V8 (P6_10) /* GPIO3[6] on P6_10 */
+
+/* GPIO Input PinMux */
+#define SCU_PINMUX_BOOT0 (P1_1) /* GPIO0[8] on P1_1 */
+#define SCU_PINMUX_BOOT1 (P1_2) /* GPIO0[9] on P1_2 */
+#define SCU_PINMUX_BOOT2 (P2_8) /* GPIO5[7] on P2_8 */
+#define SCU_PINMUX_BOOT3 (P2_9) /* GPIO1[10] on P2_9 */
+
+/* TODO add other Pins */
+
+/**********************/
+/* JellyBean GPIO Pin */
+/**********************/
+
+/* GPIO Output */
+#define PIN_LED1 (BIT1) /* GPIO2[1] on P4_1 */
+#define PIN_LED2 (BIT2) /* GPIO2[2] on P4_2 */
+#define PIN_LED3 (BIT8) /* GPIO2[8] on P6_12 */
+#define PORT_LED1_3 (GPIO2) /* PORT for LED1, 2 & 3 */
+
+#define PIN_EN1V8 (BIT6) /* GPIO3[6] on P6_10 */
+#define PORT_EN1V8 (GPIO3)
+
+/* GPIO Input */
+#define PIN_BOOT0 (BIT8) /* GPIO0[8] on P1_1 */
+#define PIN_BOOT1 (BIT9) /* GPIO0[9] on P1_2 */
+#define PIN_BOOT2 (BIT7) /* GPIO5[7] on P2_8 */
+#define PIN_BOOT3 (BIT10) /* GPIO1[10] on P2_9 */
+
+/* Read GPIO Pin */
+#define BOOT0_STATE ( (GPIO0_PIN & PIN_BOOT0)==PIN_BOOT0 )
+#define BOOT1_STATE ( (GPIO0_PIN & PIN_BOOT1)==PIN_BOOT1 )
+#define BOOT2_STATE ( (GPIO5_PIN & PIN_BOOT2)==PIN_BOOT2 )
+#define BOOT3_STATE ( (GPIO1_PIN & PIN_BOOT3)==PIN_BOOT3 )
+
+/* TODO add other Pins */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif \ No newline at end of file
diff --git a/examples/lpc43xx/hackrf-jellybean/miniblink/Makefile b/examples/lpc43xx/hackrf-jellybean/miniblink/Makefile
new file mode 100644
index 0000000..32da7ff
--- /dev/null
+++ b/examples/lpc43xx/hackrf-jellybean/miniblink/Makefile
@@ -0,0 +1,24 @@
+##
+## This file is part of the libopencm3 project.
+##
+## Copyright (C) 2010 Uwe Hermann <uwe@hermann-uwe.de>
+##
+## This library is free software: you can redistribute it and/or modify
+## it under the terms of the GNU Lesser General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## (at your option) any later version.
+##
+## This library is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU Lesser General Public License for more details.
+##
+## You should have received a copy of the GNU Lesser General Public License
+## along with this library. If not, see <http://www.gnu.org/licenses/>.
+##
+
+BINARY = miniblink
+
+LDSCRIPT = ../jellybean-lpc4330.ld
+
+include ../../Makefile.include
diff --git a/examples/lpc43xx/hackrf-jellybean/miniblink/README b/examples/lpc43xx/hackrf-jellybean/miniblink/README
new file mode 100644
index 0000000..556ed92
--- /dev/null
+++ b/examples/lpc43xx/hackrf-jellybean/miniblink/README
@@ -0,0 +1,11 @@
+------------------------------------------------------------------------------
+README
+------------------------------------------------------------------------------
+
+This is the smallest-possible example program using libopencm3.
+
+It's intended for the Jellybean development board from the HackRF project:
+
+https://github.com/mossmann/hackrf
+
+It should blink LED1 on the board.
diff --git a/examples/lpc43xx/hackrf-jellybean/miniblink/miniblink.c b/examples/lpc43xx/hackrf-jellybean/miniblink/miniblink.c
new file mode 100644
index 0000000..567d9dc
--- /dev/null
+++ b/examples/lpc43xx/hackrf-jellybean/miniblink/miniblink.c
@@ -0,0 +1,82 @@
+/*
+ * This file is part of the libopencm3 project.
+ *
+ * Copyright (C) 2010 Uwe Hermann <uwe@hermann-uwe.de>
+ * Copyright (C) 2012 Michael Ossmann <mike@ossmann.com>
+ *
+ * This library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <libopencm3/lpc43xx/gpio.h>
+#include <libopencm3/lpc43xx/scu.h>
+
+#include "../jellybean_conf.h"
+
+void gpio_setup(void)
+{
+ /* Configure SCU Pin Mux as GPIO */
+ scu_pinmux(SCU_PINMUX_LED1, SCU_GPIO_FAST);
+ scu_pinmux(SCU_PINMUX_LED2, SCU_GPIO_FAST);
+ scu_pinmux(SCU_PINMUX_LED3, SCU_GPIO_FAST);
+
+ scu_pinmux(SCU_PINMUX_EN1V8, SCU_GPIO_FAST);
+
+ scu_pinmux(SCU_PINMUX_BOOT0, SCU_GPIO_FAST);
+ scu_pinmux(SCU_PINMUX_BOOT1, SCU_GPIO_FAST);
+ scu_pinmux(SCU_PINMUX_BOOT2, SCU_GPIO_FAST);
+ scu_pinmux(SCU_PINMUX_BOOT3, SCU_GPIO_FAST);
+
+ /* Configure all GPIO as Input (safe state) */
+ GPIO0_DIR = 0;
+ GPIO1_DIR = 0;
+ GPIO2_DIR = 0;
+ GPIO3_DIR = 0;
+ GPIO4_DIR = 0;
+ GPIO5_DIR = 0;
+ GPIO6_DIR = 0;
+ GPIO7_DIR = 0;
+
+ /* Configure GPIO as Output */
+ GPIO2_DIR |= (PIN_LED1|PIN_LED2|PIN_LED3); /* Configure GPIO2[1/2/8] (P4_1/2 P6_12) as output. */
+ GPIO3_DIR |= PIN_EN1V8; /* GPIO3[6] on P6_10 as output. */
+}
+
+u32 boot0, boot1, boot2, boot3;
+
+int main(void)
+{
+ int i;
+ gpio_setup();
+
+ /* Set 1V8 */
+ gpio_set(PORT_EN1V8, PIN_EN1V8);
+
+ /* Blink LED1/2/3 on the board and Read BOOT0/1/2/3 pins. */
+ while (1)
+ {
+ boot0 = BOOT0_STATE;
+ boot1 = BOOT1_STATE;
+ boot2 = BOOT2_STATE;
+ boot3 = BOOT3_STATE;
+
+ gpio_set(PORT_LED1_3, (PIN_LED1|PIN_LED2|PIN_LED3)); /* LEDs on */
+ for (i = 0; i < 2000000; i++) /* Wait a bit. */
+ __asm__("nop");
+ gpio_clear(PORT_LED1_3, (PIN_LED1|PIN_LED2|PIN_LED3)); /* LED off */
+ for (i = 0; i < 2000000; i++) /* Wait a bit. */
+ __asm__("nop");
+ }
+
+ return 0;
+}