aboutsummaryrefslogtreecommitdiff
path: root/02-usart/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to '02-usart/src/main.c')
-rw-r--r--02-usart/src/main.c40
1 files changed, 17 insertions, 23 deletions
diff --git a/02-usart/src/main.c b/02-usart/src/main.c
index 8b98cbf..d26dce4 100644
--- a/02-usart/src/main.c
+++ b/02-usart/src/main.c
@@ -8,6 +8,7 @@
#include "core/nvic.h"
#include "core/irq.h"
+#include "peri/dma.h"
#include "delay.h"
#include "mem.h"
#include "spin.h"
@@ -64,37 +65,30 @@ int main()
setup_usart2(115200);
regset(USART2.c_r1, usart_txeie, 1);
regset(USART2.c_r1, usart_rxneie, 1);
+ usart_enable_dma(&USART2, USART_ENABLE_TX);
usart_set_enabled(&USART2, USART_ENABLE_TX | USART_ENABLE_RX);
- enable_interrupt(IRQ_USART2);
- USART2.td_r = (uint8_t) 0x61;
+ dma_opts_t opts = DEFAULT_DMA_OPTS;
+ opts.transfer_complete_interrupt_enable = 1;
+ int ec = 0;
+ dma_mem2p_channel_t dma_chan =
+ select_dma_channel_mem2p(DMA1_PERIPH_USART2_TX, &opts, &ec);
+ enable_interrupt(dma_channel_get_interrupt(dma_chan.c_));
+
+ if (ec) {
+ usart_printf(&USART2, "Select DMA channel failed :( %d\n", ec);
+ for (;;);
+ }
+
+ const char* thing = "HELLO DMA!\r\n";
+ regset(USART2.ic_r, usart_tccf, 1);
+ dma_mem2p_initiate_transfer(dma_chan, thing, strlen(thing));
__IO gpio_port_t* port_b = enable_gpio(GPIO_PORT_B);
gpio_output_pin_t pin3 = set_gpio_pin_output(port_b, PIN_3);
pin_on(pin3);
- usart_printf(&USART2, "\nUSART2.c_r1: %p\n", USART2.c_r1);
- usart_printf(&USART2, "NVIC intlinesnum: %d\n",
- regget(NVIC.ict_r, nvic_intlinesnum));
-
- int off = 1;
- int last;
- for(;;) {
- int next = USART2.is_r & usart_rxne;
- volatile int y = USART2.rd_r;
- if (next)
- USART2.td_r = y;
- if (last != next) {
- if (off) {
- pin_on(pin3);
- } else {
- pin_off(pin3);
- }
- off = !off;
- }
- }
-
// usart_printf(&USART2, "Start Configuring Countdown!\n");
/* Set the countdown to start from 1,000,0000. */