[STM32 Motor Vector Control] Record 11——DMA Transfer

Publisher:TurquoiseLatest update time:2018-09-22 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

DMA transfer:

Principle: DMA transfer copies data from one address space to another.

DMA transfers data, but does not need to occupy the MCU, that is, when transferring data, the MCU can do other things, such as multithreading. Data is transferred from peripherals to memory or from memory to memory. The DMA controller includes DMA1 and DMA2, of which DMA1 has 7 channels and DMA2 has 5 channels, which can be understood as a pipeline for transferring data. It should be noted that DMA2 only exists in large-capacity microcontrollers. 

work process:

1. DMA request 
If the peripheral wants to transfer data through DMA, it must first send a DMA request to the DMA controller. After the DMA receives the request signal, the controller will give the peripheral a response signal. When the peripheral responds and the DMA controller receives the response signal, it will start the DMA transfer until the transfer is completed. 
DMA has two controllers, DMA1 and DMA2. DMA1 has two controllers. DMA1 has 7 channels and DMA2 has 5 channels. The channels of different DMA controllers have different peripheral requests. 
2. Channel 
DMA has 12 independently programmable channels. DMA1 has 7 channels and DMA2 has 5 channels. Each channel corresponds to the DMA request of different peripherals. Although each channel can receive multiple peripheral requests, it can only receive one at the same time, not multiple at the same time. 
3. Arbiter 
When there are multiple DMA requests at the same time, it means that there is a problem of responding in order, which is managed by the arbitrator. The arbitrator manages DMA requests in two stages: the first stage belongs to the software stage, which can be set in the MDA_CCRx register. There are 4 levels: very high, high, medium and low priority. The second stage belongs to the hardware stage. If two or more DMA channel requests are set with the same priority, their priority depends on the channel number. The lower the number, the higher the priority. For example, channel 0 is higher than channel 1. In large-capacity products and interconnected products, the DMA1 controller has a higher priority than the DMA2 controller.

 

Configuration:

DMA_ InitTypeDef initialization structure 

typedef struct

uint32_t DMA_PeripheralBaseAddr; // peripheral address uint32_t

DMA_MemoryBaseAddr; // memory address uint32_t

DMA_DIR; //Transmission direction uint32_t

DMA_BufferSize; //Transfer number uint32_t

DMA_PeripheralInc; // Peripheral address increment mode uint32_t

DMA_MemoryInc; // Memory address increment mode uint32_t

DMA_PeripheralDataSize; // Peripheral data width uint32_t

DMA_MemoryDataSize; // Memory data width uint32_t

DMA_Mode; //Mode selection uint32_t

DMA_Priority; // Channel priority uint32_t

DMA_M2M; // memory to memory mode;

}DMA_Init TypeDef;


DMA data configuration:

void DMA_Config(void)

 {

 DMA_InitTypeDef DMA_InitStructure;

 RCC_AHBPeriphClockCmd(DMA_CLOCK, ENABLE); // Enable DMA clock

 DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)aSRC_Const_Buffer; // Source data address

 DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)aDST_Buffer; // target address

 DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; // Direction: peripheral to memory (internal FLASH here)

 DMA_InitStructure.DMA_BufferSize = BUFFER_SIZE; // Transfer size

 DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Enable; // Peripheral (internal FLASH) address increment

 DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; // Memory address increment

 DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word; // Peripheral data unit

 DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word; // Memory data unit

 DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; // DMA mode, one-shot or loop mode

 //DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;

 DMA_InitStructure.DMA_Priority = DMA_Priority_High; // Priority: High

 DMA_InitStructure.DMA_M2M = DMA_M2M_Enable; // Enable memory to memory transfer

 DMA_Init(DMA_CHANNEL, &DMA_InitStructure); // Configure DMA channel

 DMA_Cmd(DMA_CHANNEL,ENABLE); // Enable DMA

 }

Call the RCC_AHBPeriphClockCmd function to start the DMA clock. The corresponding clock must be started before using the DMA controller. The source address and the destination address use the array first address defined previously. The amount of data to be transferred is determined by the macro BUFFER_SIZE. The source and destination address pointer addresses are incremented. The one-time transfer mode cannot be used for cyclic transfer because there is only one DMA channel. The priority can be set arbitrarily. Finally, call the DMA_Init function to complete the initialization configuration of the DMA. 

The DMA_ClearFlag function is used to clear the DMA flag. The code uses the transfer completion flag. Clear the transfer completion flag before use to avoid unnecessary interference. The DMA_ClearFlag function requires 1 parameter, namely the event flag. The optional options include the transfer completion flag, half transfer flag, FIFO error flag, transfer error flag, etc. There are many options. Here we choose the transfer completion flag, which is defined by the macro DMA_FLAG_TC. 

The DMA_Cmd function is used to start or stop DMA data transfer. It receives two parameters, the first one is the DMA channel, and the other one is ENABLE or DISABLE.

Main tasks completed:

1. Carefully comb through the FOC2.0 program;

2. A deeper understanding of the detailed process of startup detection and sampling;

3. Gain a deeper understanding of the sector judgment during ADC sampling and the programming of its injection method.

In general, the operation procedures of BLDC motors without Hall control in FOC2.0 have been roughly mastered, but there may still be some details that have not been discovered.

Next, we will use the motor running program with Hall control to further study FOC2.0


Keywords:STM32 Reference address:[STM32 Motor Vector Control] Record 11——DMA Transfer

Previous article:[STM32 Motor Vector Control] Record 12——IWDG Watchdog
Next article:[STM32 Motor Vector Control] Record 9 - State Observer and Phase-Locked Loop

Recommended ReadingLatest update time:2024-11-16 15:27

STM32 uses the official library to output garbled characters on the serial port
I recently learned STM32 development and applied for a free development board. I followed the content in the book and learned USART. I found that the serial port output was always garbled. Damn, I don’t understand why. The code and everything are all according to the book. Finally, after searching for a long time, I f
[Microcontroller]
STM32 assembly instructions (I) WFI and WFE
ARM assembly call Embedded development, especially when writing BSP, is very close to the bottom layer. At this time, it is possible to use some assembly instructions to ensure the simplicity and efficiency of the program. However, C/C++ is usually used for writing codes. So how to use assembly instructions?  In fac
[Microcontroller]
How to debug stm32 in ram under ulink
1. Create a new RAM.ini in the project folder  ----------------------------------------------------------------  FUNC void Setup (void) {    SP = _RDWORD(0x20000000); // Stack pointer    PC = _RDWORD(0x20000004); // PC    _WDWORD(0xE000ED08, 0x20000000); // Interrupt vector offset address  }  LOAD ./basic.ax
[Microcontroller]
How to debug stm32 in ram under ulink
Summary of the use of STM32's CRH, CRL, ODR and IDR registers
1. Download:     STM32F103 Chinese Reference Manual     Baidu Netdisk: Link: http://pan.baidu.com/s/1boYtx0b  Password: lwcg 2. Introduction of CRH and CRL: The usage of CRH and CRL is basically the same. CRH is used to control the high 8 bits (Pin15---Pin8) of GPIOX (X represents A---G), while CRL is used to control
[Microcontroller]
stm32 SysTick system timer
It is a 24-bit downward-counting timer. Each count takes 1/SYSTICK. SYSTICK is the system timer clock. It can be directly obtained from the system clock or obtained by dividing the system clock by 8.  When the timer counts to 0, the initial value of the timer will be automatically reloaded from the LOAD register and
[Microcontroller]
stm32 SysTick system timer
Write STM32 OS step by step [IV] OS basic framework
1. Review of the previous article In the previous article, we completed the function of switching between two tasks using PendSV. Let's continue with the idea. This time we completed the basic framework of OS, that is, to implement a non-preemptive task scheduling system (the scheduled process is executed, and then th
[Microcontroller]
Write STM32 OS step by step [IV] OS basic framework
Data type definition in stm32
STM32F10X.H  1 #include "core_cm3.h"  2 #include "system_stm32f10x.h"  3 #include stdint.h  4   5 /** @addtogroup Exported_types  6   * @{  7   */    8   9 /*! STM32F10x Standard Peripheral Library old types (maintained for legacy purpose) */ 10 typedef int32_t  s32; 11 typedef int16_t s16; 12 typedef int8_t  s8;
[Microcontroller]
STM32 learning six
EXTI key interrupt:  EXTI interrupt:   Note:    1. EXTI interrupt is an external interrupt, and related interrupt management devices need to be configured.    2. If it is an event interrupt, there is no need to configure and manage this register.    3. Pay special attention to this relationship: the relationship b
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号