DMA Introduction: Master – Slave Communication

A free video tutorial from FastBit Embedded Brain Academy
? Amplify Your Embedded Skills ?
Rating: 4.6 out of 5Instructor rating
11 courses
120,547 students
DMA Introduction: Master – Slave Communication

Learn more from the full course

ARM Cortex M Microcontroller DMA Programming Demystified

Direct Memory Access Demystified with STM32 Peripherals (ADC, SRAM,UART,M2M,M2P,P2M) and Embedded C code Exercises

09:42:49 of on-demand video • Updated December 2023

Please watch free preview videos you will learn something today without even enrolling for this course
Fundamentals of Direct Memory Access in a Microcontroller
The Microcontroller Architecture and Bus interfaces
Bus matrix of the ARM cortex M based MCU
Concurrent data access from ARM and DMA
DMA control configurations like burst size, FIFO, Alignment
DMA Controller internals and Bus interfaces
DMA Controller channels,Streams,priority
Memory to Memory data transfer using DMA and Exercises
Peripheral to Memory and Memory to Peripheral DMA and Programming exercises
Peripheral DMA configurations
DMA controller interrupts and interrupts handling
All right.So, now let's get started with our course and before understanding the direct memory access,it's features, and it's internals on the microcontroller. It's really important to understand the master slave communication in the microcontroller architecture. Here in this lecture, I will also give a quick introduction to the direct memory access. Great. So, now let's say you have a microcontroller which is running with let's say ARM Cortex M4 processor or any ARM processor. And let's say you also have one peripheral let's say ADC which is connected to the main bus of the microcontroller, and the processor is also connected to the main bus. So, that's how they communicate. isn't it? So, now let's say ADC is a peripheral and its job is to digitize the analog signal. Isn't it? So, which is given as input. Right? And when you trigger the operation what happens. It starts calculating, digitizing the data, and when the operation completes it will have its own register called data register and there it will store the value. Isn't it? So, let's say that value is AA. So, now the peripheral is ready with the data. Right? So now, what's the use? If this data is with the peripheral it has to be moved to the memory .Isn't it? So, what you do? So, you write some instructions in order to copy that data from the peripheral into the memory. Right? So, what ARM does? it actually executes a you know load instruction. Right? In order to read this data from this memory location that is every data registers so every register of the peripheral will be having its own address. Isn't it? So, it use the load instruction in order to read the data from the peripheral into the internal register. Right? Internal registers of the processor then, it uses store instruction STR. Right? Instruction to load that value from register into the memory, So, that's how the data is moved from the peripheral into the memory. So, it is like this path, it goes to the processor register and then it comes to the memory. Isn't it? So, that's the path. All right. Now,let me just erase this. So, that's the path. Now, here you can ask one question. Why that path is required? Why can't the ADC anyway disconnected to the bus. This memory is also connected to the bus. Then why can't the ADC just push that data into the memory.So, why it should go all the way through the processor? So, that's a valid question. Isn't it? Now, the answer for that question is it's not possible.Because, even though the ADC is connected to the bus, the ADC doesn't come with that intelligence in order to generate lots of bus transactions and the control signals that are involved in order to move data from one location to another. So, what is actually load instruction? So, it is an instruction to load data from memory into the register. Let's say, So, when the processor decodes this instruction what exactly happens, it creates or actuates lots of control signals. Isn't it? It actually generates lots of bus transactions. Right? And all those work together in order to move data from one location to another. Isn't it? So, similar things happen when it decodes the STR instruction. Right? So, in other words here the processor knows how to get control of the bus. But, a peripheral will not have that intelligence in the hardware to take over the bus, in order to move data from it's data register into the memory. So, that's why we call anyone who can take over the bus in order to generate all those bus transactions in order to move data from one place to another. We call them as masters. OK. So, you might have heard a word bus masters in literature or wherever you are reading some document. OK.So, here ARM is a bus master, that it has the capacity to take over or that intelligence to take over the bus in order to generate bus transactions. But, on the other hand all those who cannot do this are called as slaves.So, here ADC is a slave. OK. So, whenever the data is ready with the slave a master has to move it. So, that means a slave cannot move data asynchronously. OK. Remember a slave can generate asynchronous events. OK. To indicate the processor that hey I have a data that's you call as interrupts. Isn't it? But, a slave cannot generate bus transactions in order to move data from one part of the microcontroller to another. So, that's why ADC, the UART, all are called as slaves. Where as the processor is called as a bus master or a master. All right. So, we now know that in order to transfer data from let's say peripheral to the memory we need ARMs intervention. Isn't it? So, data has to be first, the data has to be copied into the ARM processor register and from there it has to be stored on to the memory. Right? Now the question is, Can we offload this task of data transfer from processor to someone else? If yes, to whom we can transfer. So, for that what the manufacturer has done is they have introduced something called direct memory access controller, that we call as DMA controller. OK. And this is also a master. So, let's say this is master 1, this is master 2. And this is also hanging on the bus. But, this has the intelligence to create all those bus transactions in order to take over the bus to move data from peripherals to peripheral, to peripheral to memory, or to the memory to the peripheral,or you can even do memory to memory data transfer without taking the helpful ARM. It's like offloading the data transfer work to another controller, that is the DMA controller. OK. So, why ARM has to do all the work. So, if we can offload some of the work to some other master and in microcontroller design a DMA controller will be used in order to take care of data transfer directly from the peripheral into the memory. So, remember that the DMA controller won't execute any instruction. So, in your microcontroller processor is the only master which has the capacity to execute instructions. Here, DMA just has a logic implemented in the hardware to take over the bus and to do the data transfer from peripheral to the memory or memory to the peripheral. OK. Now, let's say some use cases where this design will be very useful. So, let's say you have 2 peripherals on your microcontroller. Let's say ADC and UART. OK. Now, let's say ADC is a producing some output. That is it is digitizing some analog signal, and it stores its data or output in the data register, and lets say ARM is currently engaged with ADC in order to move that data from its register into the memory. So, now at the same time let's say UART starts receiving data stream of bytes from the external world. So, now what happens. UART is receiving data and that data needs to be copied into the memory. Isn't it? Otherwise, the data will be lost. So, what you are does whenever it receives data. It actually triggers interrupt to the controller. Isn't it? So, it triggers interrupt with the controller saying that, hey I have some data needs to be copied into the memory. So, but the core is already engaged with ADC. It is moving its data. So, unless UARTs priority is higher than ADC, the ARM processor cannot attend UART. Isn't it? So, one way to solve this issue is rise the priority of UART, so that, whenever the interrupt happens OK ARM attends UART first.But, So, that doesn't solve the problem fully because ARM may lose the output of the ADC. So, now how to solve this issue. So, this problem can be efficiently solved by taking the help of DMA controller. What we have to do is, instead of UART triggering interrupt to the master, we should make UART triggers interrupt to the DMA controller. Because, that is also another master. So, when DMA sees this interrupt from the UART, What it does is, it copies data from UART to the memory directly without taking the help of the core.OK. The core can be engaged at the same time with ADC. So, of course you need to configure DMA to do so, that will see later. OK. But, this is actually an efficient design. Isn't it? So, all we wanted here was to move data from UART to the memory.That's it. And why do we need ARM for that? Right? It's a just data transfer work and we can easily offload this work to DMA controller OK. Which would be more efficient, and again whether to use DMA in application or not, a should come from the design perspective and you should work it out at your site. OK. All the application you know they don't demand usage of DMA controller. OK. And another interesting use case would be and it will definitely add more advantage is in order to save the power consumption of your application. All right. So, now let's say you have to move data which is coming from UART to the memory. OK. With the help of processors. So, what processor does? It actually executes you know series of load and store instructions. Right? So, first it executes LDR and then SDR. OK. In order to move data from UART to the memory. Right? And in order to execute these instructions ARM has to spend lot of bus cycles. Isn't it? So, it's instruction decoding engine should be on various other engine of the processor has to be on. So, if you use ARM for this purpose that is actually this path OK, then if you measure the power consumption in this case it will be higher if you consider DMA for the same purpose. Now, if you consider DMA for this purpose what happens.So, whenever data arrives, it generate interrupts and DMA then copies data straight into the memory and it won't execute any instructions. OK. And you can keep ARM Off until it finishes the work. Right? So, here ARM is On , here ARM is Off. So, making the processor Off will indeed reduces the power of your application. OK. So, what we have to do is, whenever data transfer happens let's say this is the place where data transfer happens, and you can keep ARM Off. OK. let's say,the ARM is Off whenever DMA is active here. OK. And making that ARM Off in between saves lots of current and your power consumption of the application will come down. So, that's why so most of the you know low power applications can take benefit out of usage of DMA controllers. OK. And all these things have to be worked out by analyzing the current consumption profile of your application, and turning Off of ARM means you are turning Off the whole building blocks of ARM controller like its internal peripherals and other computation blocks. Right? So, surely that reduces power because ARM consumes more power than the DMA controller. Great. So, that's the advantage of using DMA in your design. And don't worry we will do some experiments using DMA controller in this course, and if you don't understand anything now, you'll understand as you make a progress in this course. And with that note, I would like to end this video and let me quickly summarize what we learnt in this video. OK. In every microcontroller architecture, a microcontroller may have multiple masters. So, there will be at least one master that is the processor itself. And it may have DMA controller 1, DMA controller 2, DMA controller 3, Ethernet controller, USB controller as Masters. So, Masters means they have the capacity to generate bus transactions to move data from one place to another by taking control of the bus. And a peripheral like ADC, UART, SPI, Timer, they cannot do this. So, that's why they are called Slave. OK. Slave cannot push data asynchronously from it's register to the memory. It needs the intervention of the master. And in the next lecture what will do is, will take one practical example of a microcontroller and we will see how exactly this architecture is implemented and how things work.