Skip to content

Commit 4dc43dd

Browse files
committed
add dma
1 parent 60f6274 commit 4dc43dd

File tree

5 files changed

+79
-7
lines changed

5 files changed

+79
-7
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*~

tool/dma.h

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil -*- */
2+
3+
/* DMA control block, must be aligned to 256. */
4+
DMA_DESCRIPTOR_TypeDef dma_control_block[DMA_CHAN_COUNT * 2] __attribute__ ((aligned(256)));
5+
6+
namespace dma {
7+
8+
DMA_Init_TypeDef dmaInit = {
9+
.hprot = 0, // No descriptor protection
10+
.controlBlock = dma_control_block, // DMA control block alligned to 256
11+
};
12+
13+
static void setup() {
14+
15+
DMA_Init(&dmaInit);
16+
17+
}
18+
19+
}

tool/leuart0.h

+42-7
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,58 @@
11
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil -*- */
22

3+
#define LEUART0_DMA_CHANNEL 0
4+
#define LEUART0_BUF_MAX 255
5+
36
namespace leuart0 {
47

58
// extra serial interface for debugging
69

710
// PD4: TX
811
// PD5: RX
912

13+
static char rxbuf[LEUART0_BUF_MAX] = {0};
14+
15+
LEUART_Init_TypeDef init = {
16+
.enable = leuartEnableRx, // Activate data reception on LEUn_RX pin.
17+
.refFreq = 0, // Inherit the clock frequenzy from the LEUART clock source
18+
.baudrate = 9600,
19+
.databits = leuartDatabits8,
20+
.parity = leuartNoParity,
21+
.stopbits = leuartStopbits1,
22+
};
23+
24+
DMA_Init_TypeDef dma_init = {
25+
.hprot = 0, // No descriptor protection
26+
.controlBlock = dmaControlBlock, // DMA control block alligned to 256
27+
};
28+
29+
DMA_CfgChannel_TypeDef chnlCfg = {
30+
.highPri = false, // Normal priority
31+
.enableInt = false, // No interupt enabled for callback functions
32+
// Set LEUART0 RX data available as source of DMA signals:
33+
.select = DMAREQ_LEUART0_RXDATAV,
34+
.cb = NULL,
35+
};
36+
37+
DMA_CfgDescr_TypeDef descrCfg = {
38+
.dstInc = dmaDataInc1, // Increment destination address by one byte
39+
.srcInc = dmaDataIncNone, // Do no increment source address
40+
.size = dmaDataSize1, // Data size is one byte
41+
.arbRate = dmaArbitrate1, // Rearbitrate for each byte recieved
42+
.hprot = 0, // No read/write source protection
43+
};
44+
45+
1046
static void setup() {
47+
GPIO_PinModeSet(gpioPortD, 4, gpioModePushPull, 1);
48+
GPIO_PinModeSet(gpioPortD, 5, gpioModeInput, 0);
1149
// To avoid false start, configure output LEU0_TX as high on PD4
12-
GPIO->P[3].DOUT |= (1 << 4);
13-
// Pin PD4 is configured to Push-pull
14-
GPIO->P[3].MODEL = (GPIO->P[3].MODEL & ~_GPIO_P_MODEL_MODE4_MASK) | GPIO_P_MODEL_MODE4_PUSHPULL;
15-
// Pin PD5 is configured to Input enabled
16-
GPIO->P[3].MODEL = (GPIO->P[3].MODEL & ~_GPIO_P_MODEL_MODE5_MASK) | GPIO_P_MODEL_MODE5_INPUT;
50+
GPIO_PinOutSet(gpioPortD, 4);
1751

1852

19-
// Enable signals TX, RX
20-
LEUART0->ROUTE |= LEUART_ROUTE_TXPEN | LEUART_ROUTE_RXPEN;
53+
// Enable signals TX, RX at location 0
54+
LEUART0->ROUTE |= LEUART_ROUTE_TXPEN | LEUART_ROUTE_RXPEN
55+
| LEUART_ROUTE_LOCATION_LOC0;
2156
}
2257

2358
}

tool/main.cc

+5
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@
66
#include "em_adc.h"
77
#include "em_cmu.h"
88
#include "em_usart.h"
9+
#include "em_leuart.h"
10+
#include "em_dma.h"
11+
#include "em_gpio.h"
912

1013
// own code
14+
#include "dma.h"
1115
#include "tick.h"
1216
#include "clock.h"
1317
#include "adc0.h"
@@ -23,6 +27,7 @@ static void setup() {
2327

2428
tick::setup();
2529
clock::setup();
30+
dma::setup();
2631
adc0::setup();
2732
leuart0::setup();
2833
timer0::setup();

tool/swd.h

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil -*- */
2+
3+
namespace swd {
4+
5+
static void setup() {
6+
7+
// enable SWO tracing output
8+
GPIO->ROUTE |= GPIO_ROUTE_SWOPEN;
9+
10+
}
11+
12+
}

0 commit comments

Comments
 (0)