Skip to content

Commit c02fc96

Browse files
committed
📸 v1 with circular operation
1 parent 4f06bd5 commit c02fc96

File tree

12 files changed

+51
-29
lines changed

12 files changed

+51
-29
lines changed

dma/.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"files.associations": {
3+
"time.h": "c",
4+
"timer.h": "c"
5+
}
6+
}

dma/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ CXXSTD := c++17
1515

1616
# Project specific configuration
1717
BUILD_DIR := build
18-
BUILD_TYPE ?= Release
18+
BUILD_TYPE ?= Debug
1919
SRC_DIR := src
2020
INC_DIRS = include
2121

dma/docs/blue-pill-pinout.png

-808 KB
Binary file not shown.

dma/docs/elf_str.drawio

Lines changed: 0 additions & 1 deletion
This file was deleted.

dma/docs/linker-script.drawio

Lines changed: 0 additions & 1 deletion
This file was deleted.

dma/docs/out_115200_circ.png

449 KB
Loading

dma/include/dma.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <stm32f1xx.h>
2+
3+
#ifndef __DMA_H__
4+
#define __DMA_H__
5+
typedef enum
6+
{
7+
DISABLE,
8+
ENABLE
9+
} dma_channel_cmd_t;
10+
11+
inline void dma_channel_cmd(DMA_Channel_TypeDef *ch, dma_channel_cmd_t cmd)
12+
{
13+
if(cmd == ENABLE){
14+
ch->CCR |= DMA_CCR_EN;
15+
}else{
16+
ch->CCR &= ~DMA_CCR_EN;
17+
}
18+
}
19+
20+
inline void dma_channel_reload(DMA_Channel_TypeDef *ch, uint32_t new_count){
21+
ch->CNDTR = new_count;
22+
}
23+
24+
#endif

dma/include/main.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef __MAIN_H__
22

33
#define __MAIN_H__
4+
int main(void);
5+
46
/**
57
* @brief enable clock for dma1 peripheral registers
68
*/
@@ -12,8 +14,8 @@ void dma1_clock_enable(void);
1214
void dma_usart_tx_init(void);
1315

1416
/**
15-
* @brief Configure DMA1 channel 4 to work with USART1 transmitter
16-
* It reads from memory and writes to USART data register
17+
* @brief Configure DMA1 channel 5 to work with USART1 receiver
18+
* It reads from USART data register and writes to memory
1719
*/
1820
void dma_usart_rx_init(void);
1921

@@ -23,7 +25,7 @@ void dma_usart_rx_init(void);
2325
void dma_usart_tx_enable(void);
2426

2527
/**
26-
* @brief Enable DMA to accept request for channel 4
28+
* @brief Enable DMA to accept request for channel 5
2729
*/
2830
void dma_usart_rx_enable(void);
2931

dma/include/time.h renamed to dma/include/timer.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
#pragma once
1+
22
#include<stdint.h>
33

4+
#ifndef __TIMER_H__
5+
#define __TIMER_H__
6+
47
/**
58
* @brief Stores number of systick interrupts
69
*
@@ -15,7 +18,9 @@ extern volatile uint32_t msTicks;
1518
void delay(uint32_t ms);
1619

1720
/**
18-
* @brief Event handler for systick timer overflow event
19-
* As address of this function is to be inserted in the vector table, this should not be made inline
21+
* @brief Interrupt handler for systick timer
22+
* should not be made inline as address of this handler is to be placed in the vector table
2023
*/
21-
void SysTick_Handler(void);
24+
void SysTick_Handler(void);
25+
26+
#endif

dma/src/main.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,10 @@
1515
#include <stdint.h>
1616
#include <stdio.h>
1717
#include <stm32f1xx.h>
18-
19-
#include <time.h>
18+
#include <timer.h>
2019
#include <main.h>
2120

22-
#define RX_BUFFER_LENGTH 20U
23-
#define TX_BUFFER_LENGTH 13U
24-
25-
const char *msg = "Hello world\r\n\0";
26-
27-
char buff[RX_BUFFER_LENGTH];
21+
const char * msg = "Hello world\r\n\0";
2822

2923
void dma1_clock_enable(void)
3024
{
@@ -41,7 +35,7 @@ void dma_usart_tx_init(void)
4135
DMA1_Channel4->CMAR = (uint32_t)msg;
4236

4337
// set number od dma transactions
44-
DMA1_Channel4->CNDTR = RX_BUFFER_LENGTH;
38+
DMA1_Channel4->CNDTR = 13;
4539

4640
// set memory address incement by 1byte
4741
DMA1_Channel4->CCR |= DMA_CCR_MINC;
@@ -73,7 +67,7 @@ void usart1_init(void)
7367
GPIOA->CRH |= GPIO_CRH_CNF10_0;
7468

7569
// set baud rate as 9600
76-
uint32_t baud = (uint32_t)(SystemCoreClock / 9600);
70+
uint32_t baud = (uint32_t)(SystemCoreClock / 115200);
7771
USART1->BRR = baud;
7872

7973
// Enable transmitter
@@ -91,13 +85,8 @@ void usart1_enable(void)
9185
int main(void)
9286
{
9387
dma1_clock_enable();
94-
SysTick_Config(SystemCoreClock / 1000);
9588
usart1_init();
9689
dma_usart_tx_init();
9790
dma_usart_tx_enable();
9891
usart1_enable();
99-
100-
while (1)
101-
{
102-
}
10392
}

0 commit comments

Comments
 (0)