Skip to content

Commit 120b18e

Browse files
authored
Merge pull request #5 from kuldeepdhaka/efm32lg
Basic example for EFM32LG
2 parents d313494 + cea844d commit 120b18e

File tree

32 files changed

+1342
-2
lines changed

32 files changed

+1342
-2
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ PREFIX ?= arm-none-eabi
2323
TARGETS := stm32/f0 stm32/f1 stm32/f2 stm32/f3 stm32/f4 stm32/l0 stm32/l1
2424
TARGETS += lpc/lpc13xx lpc/lpc17xx #lpc/lpc43xx
2525
TARGETS += tiva/lm3s tiva/lm4f
26-
TARGETS += efm32/efm32tg efm32/efm32g efm32/efm32lg efm32/efm32gg
26+
TARGETS += efm32/tg efm32/g efm32/lg efm32/gg
2727
TARGETS += vf6xx
2828
TARGETS += qemu
2929

examples/efm32/Makefile.include

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
##
2+
## This file is part of the unicore-mx project.
3+
##
4+
## Copyright (C) 2015 Kuldeep Singh Dhaka <[email protected]>
5+
##
6+
## This library is free software: you can redistribute it and/or modify
7+
## it under the terms of the GNU Lesser General Public License as published by
8+
## the Free Software Foundation, either version 3 of the License, or
9+
## (at your option) any later version.
10+
##
11+
## This library is distributed in the hope that it will be useful,
12+
## but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
## GNU Lesser General Public License for more details.
15+
##
16+
## You should have received a copy of the GNU Lesser General Public License
17+
## along with this library. If not, see <http://www.gnu.org/licenses/>.
18+
##
19+
20+
COMMON_DIR = ../../../../common
21+
include ../../../../Makefile.rules

examples/efm32/lg/Makefile.include

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
##
2+
## This file is part of the unicore-mx project.
3+
##
4+
## Copyright (C) 2009 Uwe Hermann <[email protected]>
5+
## Copyright (C) 2010 Piotr Esden-Tempski <[email protected]>
6+
##
7+
## This library is free software: you can redistribute it and/or modify
8+
## it under the terms of the GNU Lesser General Public License as published by
9+
## the Free Software Foundation, either version 3 of the License, or
10+
## (at your option) any later version.
11+
##
12+
## This library is distributed in the hope that it will be useful,
13+
## but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
## GNU Lesser General Public License for more details.
16+
##
17+
## You should have received a copy of the GNU Lesser General Public License
18+
## along with this library. If not, see <http://www.gnu.org/licenses/>.
19+
##
20+
21+
LIBNAME = ucmx_efm32lg
22+
DEFS = -DEFM32LG
23+
24+
FP_FLAGS ?= -msoft-float
25+
ARCH_FLAGS = -mthumb -mcpu=cortex-m3 $(FP_FLAGS)
26+
27+
################################################################################
28+
# OpenOCD specific variables
29+
30+
OOCD ?= openocd
31+
OOCD_INTERFACE ?= flossjtag
32+
OOCD_BOARD ?= efm32
33+
34+
################################################################################
35+
# Black Magic Probe specific variables
36+
# Set the BMP_PORT to a serial port and then BMP is used for flashing
37+
BMP_PORT ?=
38+
39+
################################################################################
40+
# texane/stlink specific variables
41+
#STLINK_PORT ?= :4242
42+
43+
44+
include ../../../Makefile.include
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
##
2+
## This file is part of the unicore-mx project.
3+
##
4+
## Copyright (C) 2009 Uwe Hermann <[email protected]>
5+
##
6+
## This library is free software: you can redistribute it and/or modify
7+
## it under the terms of the GNU Lesser General Public License as published by
8+
## the Free Software Foundation, either version 3 of the License, or
9+
## (at your option) any later version.
10+
##
11+
## This library is distributed in the hope that it will be useful,
12+
## but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
## GNU Lesser General Public License for more details.
15+
##
16+
## You should have received a copy of the GNU Lesser General Public License
17+
## along with this library. If not, see <http://www.gnu.org/licenses/>.
18+
##
19+
20+
BINARY = adc-timer-dma
21+
22+
LDSCRIPT = ../efm32lg-stk3600.ld
23+
24+
include ../../Makefile.include
25+
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
/*
2+
* This file is part of the unicore-mx project.
3+
*
4+
* Copyright (C) 2015 Kuldeep Singh Dhaka <[email protected]>
5+
*
6+
* This library is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Lesser General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This library is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this library. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
#include <unicore-mx/efm32/cmu.h>
21+
#include <unicore-mx/efm32/gpio.h>
22+
#include <unicore-mx/efm32/dma.h>
23+
#include <unicore-mx/efm32/adc.h>
24+
#include <unicore-mx/efm32/prs.h>
25+
#include <unicore-mx/efm32/timer.h>
26+
27+
#define SAMPLES_COUNT 1000
28+
static uint16_t samples[SAMPLES_COUNT] __attribute__((aligned(16)));
29+
30+
/* we need only 1 channel (0th channel) */
31+
static uint8_t dma_desc_mem[DMA_DESC_CH_SIZE * 1] __attribute__((aligned(256)));
32+
33+
static void clock_setup(void)
34+
{
35+
cmu_clock_setup_in_hfxo_out_48mhz();
36+
37+
cmu_periph_clock_enable(CMU_GPIO);
38+
cmu_periph_clock_enable(CMU_ADC0);
39+
cmu_periph_clock_enable(CMU_DMA);
40+
cmu_periph_clock_enable(CMU_TIMER0);
41+
cmu_periph_clock_enable(CMU_PRS);
42+
}
43+
44+
static void led_setup(void)
45+
{
46+
gpio_clear(GPIOE, GPIO2);
47+
gpio_mode_setup(GPIOE, GPIO_MODE_PUSH_PULL, GPIO2);
48+
}
49+
50+
static void adc_setup(void)
51+
{
52+
/*
53+
* Tconv = (Ta + N) * OVS
54+
* (Tconv / 12Mhz) < (1 / 500Khz) [500Khz is timer (PRS CH0) trigger rate]
55+
* Tconv < (120 / 5)
56+
* Tconv < 24
57+
*
58+
* we need atleast 12bit resolution, N = 13
59+
* (Ta + 13) * OVS < 24
60+
* for OVS = 1
61+
*
62+
* Ta < 11
63+
* so, Ta = 8
64+
* Acquisition time = 8 cycles
65+
*/
66+
67+
/*
68+
* ADC Warm up = 48Mhz / Timebase = 48Mhz / (95 + 1) = 2us (and is <= 1us)
69+
* prescalar = 48Mhz / (3 + 1) = 12Mhz (and is <= 13Mhz)
70+
* keep adc warm between samples
71+
*/
72+
/* TODO: workaround(ADC_E117) */
73+
ADC0_CTRL = ADC_CTRL_TIMEBASE(95) | ADC_CTRL_PRESC(3) |
74+
ADC_CTRL_WARMUPMODE_KEEPADCWARM;
75+
76+
/*
77+
* get trigger from PRS Ch0 (connected to timer0, at 500Khz)
78+
* Reference: VDD
79+
* Acquisition Time: 8 ADC Clocks
80+
* Resolution: 12bit
81+
* Channels: {0, 1, 2, 3, 4, 5, 6, 7}
82+
*/
83+
ADC0_SCANCTRL = ADC_SCANCTRL_PRSSEL_PRSCH0 | ADC_SCANCTRL_PRSEN |
84+
ADC_SCANCTRL_AT_8CYCLES | ADC_SCANCTRL_REF_VDD |
85+
ADC_SCANCTRL_INPUTSEL_CH0 | ADC_SCANCTRL_INPUTSEL_CH1 |
86+
ADC_SCANCTRL_INPUTSEL_CH2 | ADC_SCANCTRL_INPUTSEL_CH3 |
87+
ADC_SCANCTRL_INPUTSEL_CH4 | ADC_SCANCTRL_INPUTSEL_CH5 |
88+
ADC_SCANCTRL_INPUTSEL_CH6 | ADC_SCANCTRL_INPUTSEL_CH7 |
89+
ADC_SCANCTRL_RES_12BIT;
90+
}
91+
92+
static void dma_setup(void)
93+
{
94+
uint32_t dma_desc = (uint32_t) dma_desc_mem;
95+
96+
/* DMA global */
97+
DMA_CONFIG = DMA_CONFIG_EN;
98+
DMA_CTRLBASE = dma_desc;
99+
100+
/* channel descriptor */
101+
uint16_t n_minus_1 = SAMPLES_COUNT - 1;
102+
DMA_DESC_CHx_CFG(dma_desc, 0) =
103+
DMA_DESC_CH_CFG_DEST_INC_HALFWORD | DMA_DESC_CH_CFG_DEST_SIZE_HALFWORD |
104+
DMA_DESC_CH_CFG_SRC_INC_NOINC | DMA_DESC_CH_CFG_SRC_SIZE_HALFWORD |
105+
DMA_DESC_CH_CFG_R_POWER(DMA_R_POWER_1) | DMA_DESC_CH_CFG_CYCLE_CTRL_BASIC |
106+
DMA_DESC_CH_CFG_N_MINUS_1(n_minus_1);
107+
DMA_DESC_CHx_DEST_DATA_END_PTR(dma_desc, 0) = ((uint32_t) samples) + (n_minus_1 << 1);
108+
DMA_DESC_CHx_SRC_DATA_END_PTR(dma_desc, 0) = (uint32_t) &ADC0_SCANDATA;
109+
110+
/* Channel 0 */
111+
DMA_CH0_CTRL = DMA_CH_CTRL_SOURCESEL_ADC0 | DMA_CH_CTRL_SIGSEL_ADC0SCAN;
112+
DMA_CHREQMASKC = DMA_CHREQMASKC_CH0SREQMASKC;
113+
DMA_RDS = DMA_RDS_RDSCH0;
114+
DMA_CHENS = DMA_CHENS_CH0SENS;
115+
}
116+
117+
static void timer_setup(void)
118+
{
119+
TIMER0_TOP = (48 * 2 * 8) - 1;
120+
}
121+
122+
static void prs_setup(void)
123+
{
124+
PRS_CH0_CTRL = PRS_CH_CTRL_SOURCESEL_TIMER0 | PRS_CH_CTRL_SIGSEL_TIMER0OF;
125+
}
126+
127+
int main(void)
128+
{
129+
clock_setup();
130+
led_setup();
131+
adc_setup();
132+
dma_setup();
133+
timer_setup();
134+
prs_setup();
135+
136+
/* start timer */
137+
TIMER0_CMD = TIMER_CMD_START;
138+
139+
/* wait till dma not received data */
140+
while(!(DMA_IF & DMA_IF_CH0DONE));
141+
142+
/* stop timer */
143+
TIMER0_CMD = TIMER_CMD_STOP;
144+
145+
/* turn "LED0" on */
146+
gpio_set(GPIOE, GPIO2);
147+
148+
while(1);
149+
return 0;
150+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
##
2+
## This file is part of the unicore-mx project.
3+
##
4+
## Copyright (C) 2009 Uwe Hermann <[email protected]>
5+
##
6+
## This library is free software: you can redistribute it and/or modify
7+
## it under the terms of the GNU Lesser General Public License as published by
8+
## the Free Software Foundation, either version 3 of the License, or
9+
## (at your option) any later version.
10+
##
11+
## This library is distributed in the hope that it will be useful,
12+
## but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
## GNU Lesser General Public License for more details.
15+
##
16+
## You should have received a copy of the GNU Lesser General Public License
17+
## along with this library. If not, see <http://www.gnu.org/licenses/>.
18+
##
19+
20+
BINARY = button
21+
22+
LDSCRIPT = ../efm32lg-stk3600.ld
23+
24+
include ../../Makefile.include
25+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# README
2+
3+
This example blinks the yellow LED "LED0" on the SiLabs EFM32LG-STK3600 eval board.
4+
5+
When you press the 'PB0' button, the blinking is faster.
6+
7+
## Board connections:
8+
9+
*none required*
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* This file is part of the unicore-mx project.
3+
*
4+
* Copyright (C) 2009 Uwe Hermann <[email protected]>,
5+
* Copyright (C) 2010 Piotr Esden-Tempski <[email protected]>
6+
* Copyright (C) 2011 Stephen Caudle <[email protected]>
7+
* Copyright (C) 2015 Kuldeep Singh Dhaka <[email protected]>
8+
*
9+
* This library is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Lesser General Public License as published by
11+
* the Free Software Foundation, either version 3 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* This library is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with this library. If not, see <http://www.gnu.org/licenses/>.
21+
*/
22+
23+
#include <unicore-mx/efm32/cmu.h>
24+
#include <unicore-mx/efm32/gpio.h>
25+
26+
#define BUTTON_PORT GPIOB
27+
#define BUTTON_PIN GPIO9
28+
29+
#define LED_PORT GPIOE
30+
#define LED_PIN GPIO2
31+
32+
static void clock_setup(void)
33+
{
34+
/* Enable GPIO clock. */
35+
cmu_periph_clock_enable(CMU_GPIO);
36+
}
37+
38+
static void led_setup(void)
39+
{
40+
/* Set "LED0" to 'output push-pull'. */
41+
gpio_mode_setup(LED_PORT, GPIO_MODE_PUSH_PULL, LED_PIN);
42+
}
43+
44+
static void button_setup(void)
45+
{
46+
/* Set button "PB0" to 'input'. */
47+
gpio_clear(BUTTON_PORT, BUTTON_PIN);
48+
gpio_mode_setup(BUTTON_PORT, GPIO_MODE_INPUT, BUTTON_PIN);
49+
}
50+
51+
int main(void)
52+
{
53+
unsigned i;
54+
55+
clock_setup();
56+
led_setup();
57+
button_setup();
58+
59+
/* Blink the LED0 on the board. */
60+
while (1) {
61+
gpio_toggle(LED_PORT, LED_PIN);
62+
63+
/* Upon button press, blink more slowly. */
64+
if (gpio_get(BUTTON_PORT, BUTTON_PIN)) {
65+
for (i = 0; i < 300000; i++) { /* Wait a bit. */
66+
__asm__("nop");
67+
}
68+
}
69+
70+
for (i = 0; i < 300000; i++) { /* Wait a bit. */
71+
__asm__("nop");
72+
}
73+
}
74+
75+
return 0;
76+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
##
2+
## This file is part of the unicore-mx project.
3+
##
4+
## Copyright (C) 2009 Uwe Hermann <[email protected]>
5+
##
6+
## This library is free software: you can redistribute it and/or modify
7+
## it under the terms of the GNU Lesser General Public License as published by
8+
## the Free Software Foundation, either version 3 of the License, or
9+
## (at your option) any later version.
10+
##
11+
## This library is distributed in the hope that it will be useful,
12+
## but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
## GNU Lesser General Public License for more details.
15+
##
16+
## You should have received a copy of the GNU Lesser General Public License
17+
## along with this library. If not, see <http://www.gnu.org/licenses/>.
18+
##
19+
20+
BINARY = dac-static-value
21+
22+
LDSCRIPT = ../efm32lg-stk3600.ld
23+
24+
include ../../Makefile.include
25+

0 commit comments

Comments
 (0)