made blinking a led on efm32 possible

this includes all register definitions for the gpu and mcu modules, but
not all their bit definitions
This commit is contained in:
chrysn 2012-02-25 22:42:15 +01:00
parent 2180a02e2f
commit 08918902ab
3 changed files with 239 additions and 48 deletions

View File

@ -18,55 +18,28 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//#include <libopencm3/efm32/tinygecko/gpio.h>
//
//void gpio_setup(void)
//{
// /* Enable GPIOC clock. */
// /* Manually: */
// // RCC_APB2ENR |= RCC_APB2ENR_IOPCEN;
// /* Using API functions: */
// rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
//
// /* Set GPIO8 (in GPIO port C) to 'output push-pull'. */
// /* Manually: */
// // GPIOC_CRH = (GPIO_CNF_OUTPUT_PUSHPULL << (((8 - 8) * 4) + 2));
// // GPIOC_CRH |= (GPIO_MODE_OUTPUT_2_MHZ << ((8 - 8) * 4));
// /* Using API functions: */
// gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ,
// GPIO_CNF_OUTPUT_PUSHPULL, GPIO8);
//}
#include <libopencm3/efm32/tinygecko/gpio.h>
#include <libopencm3/efm32/tinygecko/cmu.h>
int main(void)
{
// int i;
//
// gpio_setup();
//
// /* Blink the LED (PC8) on the board. */
// while (1) {
// /* Manually: */
// // GPIOC_BSRR = GPIO8; /* LED off */
// // for (i = 0; i < 800000; i++) /* Wait a bit. */
// // __asm__("nop");
// // GPIOC_BRR = GPIO8; /* LED on */
// // for (i = 0; i < 800000; i++) /* Wait a bit. */
// // __asm__("nop");
//
// /* Using API functions gpio_set()/gpio_clear(): */
// // gpio_set(GPIOC, GPIO8); /* LED off */
// // for (i = 0; i < 800000; i++) /* Wait a bit. */
// // __asm__("nop");
// // gpio_clear(GPIOC, GPIO8); /* LED on */
// // for (i = 0; i < 800000; i++) /* Wait a bit. */
// // __asm__("nop");
//
// /* Using API function gpio_toggle(): */
// gpio_toggle(GPIOC, GPIO8); /* LED on/off */
// for (i = 0; i < 800000; i++) /* Wait a bit. */
// __asm__("nop");
// }
//
// return 0;
for(;;);
// FIXME: As of now, this doesn't work without x being volatile; an issue with linking?
volatile int x;
// Before GPIO works, according to d0034_efm32tg_reference_manual.pdf
// note in section 28.3.7, we'll have to enable GPIO in CMU_HFPERCLKEN0
CMU_HFPERCLKEN0 |= CMU_HFPERCLKEN0_GPIO;
// The User LED is connected to PD7 to the plus side of the LED
// according to t0011_efm32_tiny_gecko_stk_user_manual.pdf figures 16.2
// and 16.3 (called UIF_LED0)
GPIO_PD_MODEL = GPIO_MODE_PUSHPULL<<(7*4);
GPIO_PD_DOUTSET = 1<<7;
while(1) {
for(x = 0; x < 200000; ++x);
GPIO_PD_DOUTTGL = 1<<7;
};
}

View File

@ -0,0 +1,66 @@
/*
* This file is part of the libopencm3 project.
*
* Copyright (C) 2012 chrysn <chrysn@fsfe.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* this interface correspons to the description in
* d0034_efm32tg_reference_manual.pdf section 11. */
#ifndef LIBOPENCM3_EFM32_TINYGECKO_CMU_H
#define LIBOPENCM3_EFM32_TINYGECKO_CMU_H
#include <libopencm3/cm3/common.h>
#define CMU_BASE 0x400C8000 /* according to d0034_efm32tg_reference_manual.pdf figure 5.2 */
/* this is d0034_efm32tg_reference_manual.pdf section 11.4 */
#define CMU_CTRL MMIO32(CMU_BASE + 0x000)
#define CMU_HFCORECLKDIV MMIO32(CMU_BASE + 0x004)
#define CMU_HFPERCLKDIV MMIO32(CMU_BASE + 0x008)
#define CMU_HFRCOCTRL MMIO32(CMU_BASE + 0x00C)
#define CMU_LFRCOCTRL MMIO32(CMU_BASE + 0x010)
#define CMU_AUXHFRCOCTRL MMIO32(CMU_BASE + 0x014)
#define CMU_CALCTRL MMIO32(CMU_BASE + 0x018)
#define CMU_CALCNT MMIO32(CMU_BASE + 0x01C)
#define CMU_OSCENCMD MMIO32(CMU_BASE + 0x020)
#define CMU_CMD MMIO32(CMU_BASE + 0x024)
#define CMU_LFCLKSEL MMIO32(CMU_BASE + 0x028)
#define CMU_STATUS MMIO32(CMU_BASE + 0x02C)
#define CMU_IF MMIO32(CMU_BASE + 0x030)
#define CMU_IFS MMIO32(CMU_BASE + 0x034)
#define CMU_IFC MMIO32(CMU_BASE + 0x038)
#define CMU_IEN MMIO32(CMU_BASE + 0x03C)
#define CMU_HFCORECLKEN0 MMIO32(CMU_BASE + 0x040)
#define CMU_HFPERCLKEN0 MMIO32(CMU_BASE + 0x044)
#define CMU_SYNCBUSY MMIO32(CMU_BASE + 0x050)
#define CMU_FREEZE MMIO32(CMU_BASE + 0x054)
#define CMU_LFACLKEN0 MMIO32(CMU_BASE + 0x058)
#define CMU_LFBCLKEN0 MMIO32(CMU_BASE + 0x060)
#define CMU_LFAPRESC0 MMIO32(CMU_BASE + 0x068)
#define CMU_LFBPRESC0 MMIO32(CMU_BASE + 0x070)
#define CMU_PCNTCTRL MMIO32(CMU_BASE + 0x078)
#define CMU_LCDCTRL MMIO32(CMU_BASE + 0x07C)
#define CMU_ROUTE MMIO32(CMU_BASE + 0x080)
#define CMU_LOCK MMIO32(CMU_BASE + 0x084)
/* this is incomplete because i'm impatient and want a working result
* quickly */
#define CMU_HFPERCLKEN0_GPIO (1<<6)
#endif

View File

@ -0,0 +1,152 @@
/*
* This file is part of the libopencm3 project.
*
* Copyright (C) 2012 chrysn <chrysn@fsfe.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* this interface corresponds to the description in
* d0034_efm32tg_reference_manual.pdf section 28. the interface tries to be
* close to stm32/f1's gpio interface. */
#ifndef LIBOPENCM3_EFM32_TINYGECKO_GPIO_H
#define LIBOPENCM3_EFM32_TINYGECKO_GPIO_H
#include <libopencm3/cm3/common.h>
#define GPIO_BASE 0x40006000 /* according to d0034_efm32tg_reference_manual.pdf figure 5.2 */
/* this is rather straight forward d0034_efm32tg_reference_manual.pdf section 28.4 */
#define GPIO_Px_CTRL_OFFSET 0x000
#define GPIO_Px_MODEL_OFFSET 0x004
#define GPIO_Px_MODEH_OFFSET 0x008
#define GPIO_Px_DOUT_OFFSET 0x00C
#define GPIO_Px_DOUTSET_OFFSET 0x010
#define GPIO_Px_DOUTCLR_OFFSET 0x014
#define GPIO_Px_DOUTTGL_OFFSET 0x018
#define GPIO_Px_DIN_OFFSET 0x01C
#define GPIO_Px_PINLOCKN_OFFSET 0x020
#define GPIO_PA (GPIO_BASE + 0x000)
#define GPIO_PA_CTRL MMIO32(GPIO_PA + GPIO_Px_CTRL_OFFSET)
#define GPIO_PA_MODEL MMIO32(GPIO_PA + GPIO_Px_MODEL_OFFSET)
#define GPIO_PA_MODEH MMIO32(GPIO_PA + GPIO_Px_MODEH_OFFSET)
#define GPIO_PA_DOUT MMIO32(GPIO_PA + GPIO_Px_DOUT_OFFSET)
#define GPIO_PA_DOUTSET MMIO32(GPIO_PA + GPIO_Px_DOUTSET_OFFSET)
#define GPIO_PA_DOUTCLR MMIO32(GPIO_PA + GPIO_Px_DOUTCLR_OFFSET)
#define GPIO_PA_DOUTTGL MMIO32(GPIO_PA + GPIO_Px_DOUTTGL_OFFSET)
#define GPIO_PA_DIN MMIO32(GPIO_PA + GPIO_Px_DIN_OFFSET)
#define GPIO_PA_PINLOCKN MMIO32(GPIO_PA + GPIO_Px_PINLOCKN_OFFSET)
#define GPIO_PB (GPIO_BASE + 0x024)
#define GPIO_PB_CTRL MMIO32(GPIO_PB + GPIO_Px_CTRL_OFFSET)
#define GPIO_PB_MODEL MMIO32(GPIO_PB + GPIO_Px_MODEL_OFFSET)
#define GPIO_PB_MODEH MMIO32(GPIO_PB + GPIO_Px_MODEH_OFFSET)
#define GPIO_PB_DOUT MMIO32(GPIO_PB + GPIO_Px_DOUT_OFFSET)
#define GPIO_PB_DOUTSET MMIO32(GPIO_PB + GPIO_Px_DOUTSET_OFFSET)
#define GPIO_PB_DOUTCLR MMIO32(GPIO_PB + GPIO_Px_DOUTCLR_OFFSET)
#define GPIO_PB_DOUTTGL MMIO32(GPIO_PB + GPIO_Px_DOUTTGL_OFFSET)
#define GPIO_PB_DIN MMIO32(GPIO_PB + GPIO_Px_DIN_OFFSET)
#define GPIO_PB_PINLOCKN MMIO32(GPIO_PB + GPIO_Px_PINLOCKN_OFFSET)
#define GPIO_PC (GPIO_BASE + 0x048)
#define GPIO_PC_CTRL MMIO32(GPIO_PC + GPIO_Px_CTRL_OFFSET)
#define GPIO_PC_MODEL MMIO32(GPIO_PC + GPIO_Px_MODEL_OFFSET)
#define GPIO_PC_MODEH MMIO32(GPIO_PC + GPIO_Px_MODEH_OFFSET)
#define GPIO_PC_DOUT MMIO32(GPIO_PC + GPIO_Px_DOUT_OFFSET)
#define GPIO_PC_DOUTSET MMIO32(GPIO_PC + GPIO_Px_DOUTSET_OFFSET)
#define GPIO_PC_DOUTCLR MMIO32(GPIO_PC + GPIO_Px_DOUTCLR_OFFSET)
#define GPIO_PC_DOUTTGL MMIO32(GPIO_PC + GPIO_Px_DOUTTGL_OFFSET)
#define GPIO_PC_DIN MMIO32(GPIO_PC + GPIO_Px_DIN_OFFSET)
#define GPIO_PC_PINLOCKN MMIO32(GPIO_PC + GPIO_Px_PINLOCKN_OFFSET)
#define GPIO_PD (GPIO_BASE + 0x06C)
#define GPIO_PD_CTRL MMIO32(GPIO_PD + GPIO_Px_CTRL_OFFSET)
#define GPIO_PD_MODEL MMIO32(GPIO_PD + GPIO_Px_MODEL_OFFSET)
#define GPIO_PD_MODEH MMIO32(GPIO_PD + GPIO_Px_MODEH_OFFSET)
#define GPIO_PD_DOUT MMIO32(GPIO_PD + GPIO_Px_DOUT_OFFSET)
#define GPIO_PD_DOUTSET MMIO32(GPIO_PD + GPIO_Px_DOUTSET_OFFSET)
#define GPIO_PD_DOUTCLR MMIO32(GPIO_PD + GPIO_Px_DOUTCLR_OFFSET)
#define GPIO_PD_DOUTTGL MMIO32(GPIO_PD + GPIO_Px_DOUTTGL_OFFSET)
#define GPIO_PD_DIN MMIO32(GPIO_PD + GPIO_Px_DIN_OFFSET)
#define GPIO_PD_PINLOCKN MMIO32(GPIO_PD + GPIO_Px_PINLOCKN_OFFSET)
#define GPIO_PE (GPIO_BASE + 0x090)
#define GPIO_PE_CTRL MMIO32(GPIO_PE + GPIO_Px_CTRL_OFFSET)
#define GPIO_PE_MODEL MMIO32(GPIO_PE + GPIO_Px_MODEL_OFFSET)
#define GPIO_PE_MODEH MMIO32(GPIO_PE + GPIO_Px_MODEH_OFFSET)
#define GPIO_PE_DOUT MMIO32(GPIO_PE + GPIO_Px_DOUT_OFFSET)
#define GPIO_PE_DOUTSET MMIO32(GPIO_PE + GPIO_Px_DOUTSET_OFFSET)
#define GPIO_PE_DOUTCLR MMIO32(GPIO_PE + GPIO_Px_DOUTCLR_OFFSET)
#define GPIO_PE_DOUTTGL MMIO32(GPIO_PE + GPIO_Px_DOUTTGL_OFFSET)
#define GPIO_PE_DIN MMIO32(GPIO_PE + GPIO_Px_DIN_OFFSET)
#define GPIO_PE_PINLOCKN MMIO32(GPIO_PE + GPIO_Px_PINLOCKN_OFFSET)
#define GPIO_PF (GPIO_BASE + 0x0B4)
#define GPIO_PF_CTRL MMIO32(GPIO_PF + GPIO_Px_CTRL_OFFSET)
#define GPIO_PF_MODEL MMIO32(GPIO_PF + GPIO_Px_MODEL_OFFSET)
#define GPIO_PF_MODEH MMIO32(GPIO_PF + GPIO_Px_MODEH_OFFSET)
#define GPIO_PF_DOUT MMIO32(GPIO_PF + GPIO_Px_DOUT_OFFSET)
#define GPIO_PF_DOUTSET MMIO32(GPIO_PF + GPIO_Px_DOUTSET_OFFSET)
#define GPIO_PF_DOUTCLR MMIO32(GPIO_PF + GPIO_Px_DOUTCLR_OFFSET)
#define GPIO_PF_DOUTTGL MMIO32(GPIO_PF + GPIO_Px_DOUTTGL_OFFSET)
#define GPIO_PF_DIN MMIO32(GPIO_PF + GPIO_Px_DIN_OFFSET)
#define GPIO_PF_PINLOCKN MMIO32(GPIO_PF + GPIO_Px_PINLOCKN_OFFSET)
#define GPIO_EXTIPSELL MMIO32(GPIO_BASE + 0x100)
#define GPIO_EXTIPSELH MMIO32(GPIO_BASE + 0x104)
#define GPIO_EXTIRISE MMIO32(GPIO_BASE + 0x108)
#define GPIO_EXTIFALL MMIO32(GPIO_BASE + 0x10C)
#define GPIO_IEN MMIO32(GPIO_BASE + 0x110)
#define GPIO_IF MMIO32(GPIO_BASE + 0x114)
#define GPIO_IFS MMIO32(GPIO_BASE + 0x118)
#define GPIO_IFC MMIO32(GPIO_BASE + 0x11C)
#define GPIO_ROUTE MMIO32(GPIO_BASE + 0x120)
#define GPIO_INSENSE MMIO32(GPIO_BASE + 0x124)
#define GPIO_LOCK MMIO32(GPIO_BASE + 0x128)
#define GPIO_CTRL MMIO32(GPIO_BASE + 0x12C)
#define GPIO_CMD MMIO32(GPIO_BASE + 0x130)
#define GPIO_EM4WUEN MMIO32(GPIO_BASE + 0x134)
#define GPIO_EM4WUPOL MMIO32(GPIO_BASE + 0x138)
#define GPIO_EM4WUCAUSE MMIO32(GPIO_BASE + 0x13C)
/* these are the modes defined for the MODEx fields in the MODEL/MODEH
* registers, named as in d0034_efm32tg_reference_manual.pdf's sections
* 28.5.2/28.5.3. for explanations of what they really do, rather see section
* 28.3.1. */
#define GPIO_MODE_DISABLED 0
#define GPIO_MODE_INPUT 1
#define GPIO_MODE_INPUTPULL 2
#define GPIO_MODE_INPUTPULLFILTER 3
#define GPIO_MODE_PUSHPULL 4
#define GPIO_MODE_PUSHPULLDRIVE 5
#define GPIO_MODE_WIREDOR 6
#define GPIO_MODE_WIREDORPULLDOWN 7
#define GPIO_MODE_WIREDAND 8
#define GPIO_MODE_WIREDANDFILTER 9
#define GPIO_MODE_WIREDANDPULLUP 10
#define GPIO_MODE_WIREDANDPULLUPFILTER 11
#define GPIO_MODE_WIREDANDDRIVE 12
#define GPIO_MODE_WIREDANDDRIVEFILTER 13
#define GPIO_MODE_WIREDANDDRIVEPULLUP 14
#define GPIO_MODE_WIREDANDDRIVEPULLUPFILTER 15
//void gpio_set(u32 gpioport, u16 gpios);
//void gpio_clear(u32 gpioport, u16 gpios);
//void gpio_toggle(u32 gpioport, u16 gpios);
//u16 gpio_get(u32 gpioport, u16 gpios);
#endif