Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The primary goal of this laboratory exercise is to gain hands - on experience in configuring and using DMA to transfer data between peripheral modules

The primary goal of this laboratory exercise is to gain hands-on experience in configuring and using DMA to transfer data between peripheral modules and memory. Additionally, you will explore essential practices in managing C projects, which involve multiple '.c' and '.h' files. This knowledge is crucial for ensuring the system's maintainability and scalability, as well as for supporting effective collaboration. You are provided with a sample project, Lab8_Project_Template, which integrates the Lab 3 project and the UART_Terminal sample project. This project implements a counter that increments by one every second using the general-purpose timer TIM2 in output compare toggle mode. The counter value is converted into a character string stored in a character array named 'string,' and displayed on a PC serial terminal through the USART2 TX port. Essentially, you will see the counter value automatically increment by one and be displayed on the serial terminal every second. In this sample project, the character string representing the counter value is transferred from the memory array 'string' to the USART2 Transmit Data Register (TDR) via software (i.e., the processor). Your task is to modify the project so this array of data will be transferred using DMA instead of software. You will need to identify the DMA channel that is mapped to USART2 TX and set up the DMA module and channel to transfer data from memory to USART2 TX. The DMA transfer should be initiated whenever the counter value is updated. Hint: You can enable DMA transfer in the TIM2_IRQHandler after the counter is incremented and converted into a new string. Once the transfer is complete, an interrupt associated with the DMA channel can be triggered to disable the DMA channel. The channel will be re-enabled when the counter is updated, i.e., when the TIM2 interrupt is triggered again. You are required to add a DMA.c and a DMA.h file to the project and place the relevant DMA variables and function declarations and definitions into these two files.
main.c
#include "stm32l476xx.h"
#include "LED.h"
#include "USART2.h"
int main(void){
char msg[]= "Welcome! Please input a 5-digit number and then press Enter:
\r";
int i=0;
// Configure PA5 to serve as an output pin, used for controlling the on-board LED (LD2).
configure_LED_pin();
// Initialize USART2 for communication with a PC via serial terminal.
// Configuration details:
//- Data format: 8 data bits, no parity, 1 start bit, and 1 stop bit
//- Baud rate: 9600
//- Enable RXNE interrupt to trigger when a new character is received, allowing for responsive character echo.
USART2_Init();
// Configuring DMA1 Channel 6 as the USART2 RX channel.
DMA1_Channel6_Configruation();
// Loop to send the welcome message character by character when the system restarts.
while(msg[i]!='\0'){
// Wait until the TXE (Transmit Data Register Empty) flag is set, indicating readiness to send the next character.
while (!(USART2->ISR & USART_ISR_TXE));
// Send the current character and automatically clear the TXE flag by writing to USART_TDR.
// increment i after sending the current character
USART2->TDR = msg[i++];
}
// Enter an infinite loop to maintain the program's operation.
while (1){
}
}
DMA1.c
#include "DMA1.h"
#include
// The memory buffer array stores the data received from the USART2 receiver.
volatile uint8_t Buffer_R[6];
// Configuring DMA1 Channel 6 as the USART2 RX channel.
void DMA1_Channel6_Configruation(void)
{
// Enable the DMA1 clock in the AHB1 peripheral clock enable register
RCC->AHB1ENR |= RCC_AHB1ENR_DMA1EN;
// Map USART2 RX to DMA1 Channel 6
// C6S[3:0]='0010'
DMA1_CSELR->CSELR &= ~DMA_CSELR_C6S;
DMA1_CSELR->CSELR |=0b00104*(6-1);
// Disabling DMA1 Channel 6 to allow configuration
DMA1_Channel6->CCR &= ~DMA_CCR_EN;
// Peripheral data size for each DMA transfer: '00' equals 8 bits.
DMA1_Channel6->CCR &= ~DMA_CCR_PSIZE;
// Memory data size for each DMA transfer: '00' equals 8 bits.
DMA1_Channel6->CCR &= ~DMA_CCR_MSIZE;
// Disable peripheral increment mode (no incrementation after each transfer)
DMA1_Channel6->CCR &= ~DMA_CCR_PINC;
// Enable memory increment mode (memory address incremented by 1 after each transfer)
DMA1_Channel6->CCR |= DMA_CCR_MINC;
// Configure transfer direction: '0' indicates from peripheral to memory.
DMA1_Channel6->CCR &= ~DMA_CCR_DIR;
// Number of data to transfer
DMA1_Channel6->CNDTR =6;
// Peripheral address: the address of the USART2 RDR register
DMA1_Channel6->CPAR =(uint32_t)&(USART2->RDR);
// Memory address: the address of the memory buffer array
DMA1_Channel6->CMAR =(uint32_t)Buffer_R;
// Enable Circular Mode for DMA1 Channel 6
DMA1_Channel6->CCR |= DMA_CCR_CIRC;
// Enable the transfer complete interrupt for DMA1 Channel 6
DMA1_Channel6->CCR |= DMA_CCR_TCIE;
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Accounting And Auditing Research And Databases Practitioner's Desk Reference

Authors: Thomas R. Weirich, Natalie Tatiana Churyk, Thomas C. Pearson

1st Edition

1118334426, 978-1118334423

More Books

Students also viewed these Databases questions

Question

The paper referenced in Exercise

Answered: 1 week ago