File tree Expand file tree Collapse file tree 12 files changed +51
-29
lines changed Expand file tree Collapse file tree 12 files changed +51
-29
lines changed Original file line number Diff line number Diff line change 1+ {
2+ "files.associations" : {
3+ "time.h" : " c" ,
4+ "timer.h" : " c"
5+ }
6+ }
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ CXXSTD := c++17
1515
1616# Project specific configuration
1717BUILD_DIR := build
18- BUILD_TYPE ?= Release
18+ BUILD_TYPE ?= Debug
1919SRC_DIR := src
2020INC_DIRS = include
2121
Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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);
1214void 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 */
1820void dma_usart_rx_init (void );
1921
@@ -23,7 +25,7 @@ void dma_usart_rx_init(void);
2325void 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 */
2830void dma_usart_rx_enable (void );
2931
Original file line number Diff line number Diff line change 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;
1518void 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
Original file line number Diff line number Diff line change 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
2923void 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)
9185int 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}
You can’t perform that action at this time.
0 commit comments