{"id":408,"date":"2023-06-28T11:53:55","date_gmt":"2023-06-28T11:53:55","guid":{"rendered":"http:\/\/localhost\/embeddedwala\/?p=408"},"modified":"2023-07-27T04:12:56","modified_gmt":"2023-07-27T04:12:56","slug":"what-is-dma","status":"publish","type":"post","link":"https:\/\/embeddedwala.com\/beta\/blogs\/digital-communication\/what-is-dma\/","title":{"rendered":"What is DMA?"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"408\" class=\"elementor elementor-408\" data-elementor-post-type=\"post\">\n\t\t\t\t\t\t\t\t\t<section data-particle_enable=\"false\" data-particle-mobile-disabled=\"false\" class=\"elementor-section elementor-top-section elementor-element elementor-element-5794407 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"5794407\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-bf39f19\" data-id=\"bf39f19\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t\t<section data-particle_enable=\"false\" data-particle-mobile-disabled=\"false\" class=\"elementor-section elementor-inner-section elementor-element elementor-element-44ddbd2 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"44ddbd2\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-inner-column elementor-element elementor-element-722a4b0\" data-id=\"722a4b0\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-element elementor-element-1c27f12 elementor-widget elementor-widget-text-editor\" data-id=\"1c27f12\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<p><span data-contrast=\"none\">CPU is an essential part of an Embedded System that manages all the arithmetic, logic, control, and I\/O operations. The main components of the CPU are Control Unit (CU), Arithmetic &amp; Logic Unit (ALU), and the registers.\u00a0\u00a0<\/span>\u00a0<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-411 size-full\" src=\"https:\/\/embeddedwala.com\/beta\/wp-content\/uploads\/2023\/06\/input-and-output-banner-image.jpg\" alt=\"\" width=\"750\" height=\"422\" \/>\u00a0<span data-contrast=\"none\"><strong>CU<\/strong>\u00a0manages the\u00a0<strong>ALU<\/strong>\u00a0and memory communication for executing or storing the instructions. It includes the fetching unit for fetching the instructions. On the other hand, the ALU unit manages all the arithmetic and logical operations. During the data transmission between memory and the peripherals, a delay will add if the CPU is engaged to accomplish some other task. Therefore, the system performance gets degraded.\u00a0\u00a0\u00a0<\/span><\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-415 size-full\" src=\"https:\/\/embeddedwala.com\/beta\/wp-content\/uploads\/2023\/06\/CPU-memory-image.jpg\" alt=\"\" width=\"750\" height=\"422\" \/><\/p><p><span data-contrast=\"none\">As shown above, the CPU and multiple peripherals connect with a<strong>\u00a0bus matrix<\/strong>. The in-hardware CPU uses the bus interconnected (further expands to the data, control and address bus) to load the data from one of the peripherals and then store it in memory or vice-versa. As a Use Case scenario, the UART is one of the peripherals and wants to transfer the data from its data register to the memory. Therefore, the CPU needs to be programmed to do this transfer of data from the UART Data Register to the memory.\u00a0\u00a0<\/span>\u00a0<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-414 size-full\" src=\"https:\/\/embeddedwala.com\/beta\/wp-content\/uploads\/2023\/06\/Cpu-ram-image.jpg\" alt=\"\" width=\"750\" height=\"422\" \/><\/p><p><span data-contrast=\"none\">The peripherals can only generate the asynchronous events (interrupts) to indicate to the CPU that data is ready but unable to do the bus transactions. Therefore to offload the CPU, a kind of master is essential who can do these transactions without the CPU intervention. The Hardware IP that can control the data transfer between the memory and the peripherals without the CPU involvement is known\u00a0<strong>Direct Memory Access (DMA) controller<\/strong>. DMA can access the memory and the peripherals directly for doing the bus transactions. However, Load Store instruction execution and other internal circuitry would only be active during the CPU execution. Therefore, Power Consumption will be less with DMA because the CPU can be in sleep mode during the data transmission.\u00a0\u00a0<\/span>\u00a0<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-413 size-full\" src=\"https:\/\/embeddedwala.com\/beta\/wp-content\/uploads\/2023\/06\/cpu-core-image.jpg\" alt=\"\" width=\"750\" height=\"422\" \/><\/p><p><span data-contrast=\"none\">A System on Chip (SoC) is an integrated circuit with all the essential elements required for an Embedded System. In an SoC, the\u00a0<strong>Advanced Microcontroller Bus Architecture (AMBA)<\/strong>\u00a0is an open standard that is developed by\u00a0<strong>ARM<\/strong>. AMBA has a\u00a0<strong>master-slave<\/strong>\u00a0type of topology, only the master can initiate the communication. AMBA connects and manages all the components like Memory and Peripherals e.g. UART, CPU and etc. For managing on-chip communication AMBA has three buses as follows,\u00a0<strong>Advanced High-Performance Bus (AHB)<\/strong>, the\u00a0<strong>Advanced System Bus (ASB)<\/strong>, and the\u00a0<strong>Advanced Peripheral Bus (APB)<\/strong>. The AHB facilitates high-frequency and high-performance components. On the other hand, ASB is an alternative to the AHB but with limited features. Whereas, APB is for taking care of the low bandwidth peripherals like GPIOs, Timers, and UART.\u00a0<\/span>\u00a0<\/p><p><span data-contrast=\"none\">The master has the privilege to control the bus and there can be multiple masters in an SoC, but a single master would be able to access the bus at a particular time. To resolve the multi-master access request in hardware, an<strong>\u00a0arbiter<\/strong>\u00a0is used. When any master wants to control the AHB bus, it sends a request signal to the arbiter and it will provide access if the bus is available at that particular time. If multiple masters send an access request signal simultaneously, then access will be given to the master having higher priority. Therefore, another master request can stop the CPU access to the system bus for a few bus cycles when the CPU and another master are trying to access the same destination simultaneously.\u00a0<\/span>\u00a0<\/p><p><span data-contrast=\"none\">The bus matrix provides access from a master to a slave, enabling concurrent access and efficient operation. The description of these masters is as below:<\/span>\u00a0<\/p><ul><li data-aria-posinset=\"1\" data-aria-level=\"2\"><span data-contrast=\"none\">I-Bus: Instruction Bus uses by the core for fetching the instruction. The target of this bus is a memory containing code like Flash, Static RAM, and External Memory.\u00a0<\/span>\u00a0<\/li><li data-aria-posinset=\"2\" data-aria-level=\"2\"><span data-contrast=\"none\">D-Bus: Data bus uses by the core for literal load and debugs access. The target of this bus is a memory containing code or data like Flash, Static RAM &amp; External Memory.\u00a0\u00a0<\/span>\u00a0<\/li><li data-aria-posinset=\"3\" data-aria-level=\"2\"><span data-contrast=\"none\">S-Bus: System Bus is used to access the data in a peripheral or SRAM. It is also able to fetch instructions and is slower than the I &amp; D Bus. It connects with all the slaves except Flash.\u00a0\u00a0\u00a0<\/span>\u00a0<\/li><li data-aria-posinset=\"4\" data-aria-level=\"2\"><span data-contrast=\"none\">DMA Memory: It is used by the DMA for transferring the data to\/from memories.\u00a0\u00a0\u00a0<\/span>\u00a0<\/li><li data-aria-posinset=\"5\" data-aria-level=\"2\"><span data-contrast=\"none\">DMA Peripheral: This bus is used by the DMA to access AHB peripherals or to perform memory-to-memory transfers. The targets of this bus are the AHB, APB peripherals, and data memories. DMA2 Peripheral is unable to communicate with Memories whereas it&#8217;s possible in the case of DMA1. It depends on the system architecture.\u00a0\u00a0\u00a0<\/span>\u00a0<\/li><li data-aria-posinset=\"6\" data-aria-level=\"2\"><span data-contrast=\"none\">USB OTG HS Bus: This bus is used by the<\/span><span data-contrast=\"none\">\u00a0USB OTG to load\/store<\/span><span data-contrast=\"none\">\u00a0data in memory.\u00a0\u00a0<\/span>\u00a0<\/li><\/ul><p><span data-contrast=\"none\">Let&#8217;s take an example of ARM Cortex M-4 architecture, where the system consists of a 32-bit multilayer AHB bus matrix that interconnects multiple masters and slaves. CPU Instruction, Data, System bus, DMAs, and USB are acting as masters. On the other hand, Flash, SRAM, and all the peripherals connected with AHB &amp; APB buses are working as a slave.\u00a0<\/span>\u00a0<\/p><p><span data-contrast=\"none\">DMA controller supports two transfer modes which are as below:<\/span>\u00a0<\/p><ol><li data-aria-posinset=\"1\" data-aria-level=\"2\"><b><span data-contrast=\"none\">Burst Transfer<\/span><\/b><span data-contrast=\"none\">\u00a0\u2013 The entire chunk of data is transferred continuously without interruption. The control of the bus is given back to the CPU when the entire chunk of data is transferred. The disadvantage of this transfer is that if the CPU needs any data from memory during this time, it needs to wait until the transf<\/span><span data-contrast=\"none\">er is complete.<\/span><span data-contrast=\"none\">\u00a0<\/span>\u00a0<\/li><li data-aria-posinset=\"2\" data-aria-level=\"2\"><b><span data-contrast=\"none\">Split cycle transfer<\/span><\/b><span data-contrast=\"none\">\u00a0\u2013 The control of the bus is given back to the CPU periodically. The data transfer doesn\u2019t happen continuously. The advantage is that the CPU doesn\u2019t sit idle for a given amount of time, waiting for data from memory.<\/span><span data-contrast=\"none\">\u00a0<\/span>\u00a0<\/li><\/ol><p><span data-contrast=\"none\">DMA can be configured into 3 Modes:\u00a0<\/span>\u00a0<\/p><ul><li data-aria-posinset=\"1\" data-aria-level=\"2\"><span data-contrast=\"none\">Memory to Memory\u00a0<\/span>\u00a0<\/li><li data-aria-posinset=\"2\" data-aria-level=\"2\"><span data-contrast=\"none\">Peripheral to Memory\u00a0<\/span>\u00a0<\/li><li data-aria-posinset=\"3\" data-aria-level=\"2\"><span data-contrast=\"none\">Memory to Peripheral\u00a0\u00a0<\/span>\u00a0<\/li><\/ul><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-412 size-full\" src=\"https:\/\/embeddedwala.com\/beta\/wp-content\/uploads\/2023\/06\/cpu-dam-image.jpg\" alt=\"\" width=\"750\" height=\"422\" \/><\/p><p><span data-contrast=\"none\">Let&#8217;s consider one application where a SPI based temperature sensor is connected to the microcontroller and firmware inside CPU wants to read the data from the sensor. To do the same transfer using DMA without the intervention from CPU so that data can be stored into the memory without any delay, as CPU may be busy in performing another high priority task. Communication steps would be as below:\u00a0<\/span>\u00a0<\/p><ul><li data-aria-posinset=\"1\" data-aria-level=\"2\"><span data-contrast=\"none\">Once the SPI is available with some data in the data register, it will send the request to the CPU.\u00a0<\/span><span data-contrast=\"none\">The CPU sends the signal to DMA to perform a Read\/Write between a SPI and the memory.<\/span>\u00a0<\/li><li data-aria-posinset=\"2\" data-aria-level=\"2\"><span data-contrast=\"none\">The DMA communicates with the SPI to see if it is ready for the transfer and if SPI is ready\u00a0<\/span><span data-contrast=\"none\">DMA sends a DMA request to the CPU.<\/span>\u00a0<\/li><li data-aria-posinset=\"3\" data-aria-level=\"2\"><span data-contrast=\"none\">The CPU sends a acknowledge signal to the DMA with the control of the system bus. It also gives the starting address of the data and the data count.<\/span>\u00a0<\/li><li data-aria-posinset=\"4\" data-aria-level=\"2\"><span data-contrast=\"none\">The DMA receives a unit data from the SPI, stores it in its data register and subsequently transfers it to the memory<\/span><span data-contrast=\"none\">.\u00a0<\/span><span data-contrast=\"none\">The data count is decremented by 1 and the address register is incremented by 1.<\/span>\u00a0<\/li><li data-aria-posinset=\"5\" data-aria-level=\"2\"><span data-contrast=\"none\">When the data transfer is complete, DMA sends a interrupt signal to the CPU. Upon receiving the interrupt signal, the CPU takes back the control of the system bus.<\/span>\u00a0<\/li><\/ul><p><span data-contrast=\"none\">In the end, we can conclude that Fast Data transfer between Memory and Peripherals is possible using DMA. CPU and DMA can also operate concurrently which provides better performance. It also helps in reducing power consumption if the CPU is in sleep mode.<\/span>\u00a0<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>CPU is an essential part of an Embedded System that manages all the arithmetic, logic,&#8230;<\/p>\n","protected":false},"author":1,"featured_media":409,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34],"tags":[104,103,101,100,105,102],"class_list":["post-408","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-digital-communication","tag-arbiter","tag-arm-cortext","tag-arm-dma","tag-dma","tag-master-slave","tag-peripheral-dma"],"acf":[],"views":436,"featured_image_urls":{"full":["https:\/\/embeddedwala.com\/beta\/wp-content\/uploads\/2023\/06\/DMA-banner-image.png",520,350,false],"thumbnail":["https:\/\/embeddedwala.com\/beta\/wp-content\/uploads\/2023\/06\/DMA-banner-image.png",150,101,false],"medium":["https:\/\/embeddedwala.com\/beta\/wp-content\/uploads\/2023\/06\/DMA-banner-image.png",300,202,false],"medium_large":["https:\/\/embeddedwala.com\/beta\/wp-content\/uploads\/2023\/06\/DMA-banner-image.png",520,350,false],"large":["https:\/\/embeddedwala.com\/beta\/wp-content\/uploads\/2023\/06\/DMA-banner-image.png",520,350,false],"1536x1536":["https:\/\/embeddedwala.com\/beta\/wp-content\/uploads\/2023\/06\/DMA-banner-image.png",520,350,false],"2048x2048":["https:\/\/embeddedwala.com\/beta\/wp-content\/uploads\/2023\/06\/DMA-banner-image.png",520,350,false],"tp-image-grid":["https:\/\/embeddedwala.com\/beta\/wp-content\/uploads\/2023\/06\/DMA-banner-image.png",520,350,false],"covernews-slider-full":["https:\/\/embeddedwala.com\/beta\/wp-content\/uploads\/2023\/06\/DMA-banner-image.png",520,350,false],"covernews-slider-center":["https:\/\/embeddedwala.com\/beta\/wp-content\/uploads\/2023\/06\/DMA-banner-image.png",520,350,false],"covernews-featured":["https:\/\/embeddedwala.com\/beta\/wp-content\/uploads\/2023\/06\/DMA-banner-image.png",520,350,false],"covernews-medium":["https:\/\/embeddedwala.com\/beta\/wp-content\/uploads\/2023\/06\/DMA-banner-image.png",505,340,false],"covernews-medium-square":["https:\/\/embeddedwala.com\/beta\/wp-content\/uploads\/2023\/06\/DMA-banner-image.png",371,250,false],"_nx_notification_thumb":["https:\/\/embeddedwala.com\/beta\/wp-content\/uploads\/2023\/06\/DMA-banner-image.png",100,67,false]},"author_info":{"display_name":"embeddedwala","author_link":"https:\/\/embeddedwala.com\/beta\/author\/embeddedwala\/"},"category_info":"<a href=\"https:\/\/embeddedwala.com\/beta\/category\/blogs\/digital-communication\/\" rel=\"category tag\">Digital Communication<\/a>","tag_info":"Digital Communication","comment_count":"0","_links":{"self":[{"href":"https:\/\/embeddedwala.com\/beta\/wp-json\/wp\/v2\/posts\/408","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/embeddedwala.com\/beta\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/embeddedwala.com\/beta\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/embeddedwala.com\/beta\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/embeddedwala.com\/beta\/wp-json\/wp\/v2\/comments?post=408"}],"version-history":[{"count":11,"href":"https:\/\/embeddedwala.com\/beta\/wp-json\/wp\/v2\/posts\/408\/revisions"}],"predecessor-version":[{"id":8864,"href":"https:\/\/embeddedwala.com\/beta\/wp-json\/wp\/v2\/posts\/408\/revisions\/8864"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/embeddedwala.com\/beta\/wp-json\/wp\/v2\/media\/409"}],"wp:attachment":[{"href":"https:\/\/embeddedwala.com\/beta\/wp-json\/wp\/v2\/media?parent=408"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/embeddedwala.com\/beta\/wp-json\/wp\/v2\/categories?post=408"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/embeddedwala.com\/beta\/wp-json\/wp\/v2\/tags?post=408"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}