使用环境
- 操作系统版本:Windows 11 家庭中文版
- 操作系统平台(x86/x64):x64
- VsCode 版本:April 2025 (version 1.100)
- EIDE 插件版本:3.21.2
- C/C++ 插件版本:1.25.3
- 何种编译器(keil_c51/sdcc/armcc5/armgcc/...):arm-none-eabi-gcc
- 编译器版本(非编译问题可忽略):arm-none-eabi-gcc (GNU Arm Embedded Toolchain 10.3-2021.10) 10.3.1 20210824 (release)
描述问题
<!-- 使用简明清晰的语言描述您的问题 -->
There is the Error:
(1) undefined reference to 'DMA_Init'
Here is my effort to find the problem:
(1) when I comment the code "DMA_Init(DMA1_Channel1, &DMA_InitStructure);" in MyDMA.c,The Program compile normally.
(2) Uncomment the code "DMA_Init(DMA1_Channel1, &DMA_InitStructure);"in MyDMA.c. And Add the stm32f10x_dma.c to my folder where main.c and MyDMA.c/.h storaged.The Program compile normally.
屏幕截图
<!--使用一些截图能够更好地展现问题 -->
Here is my code:
(1) MyDMA.h
`#ifndef MYDMA_H
#define MYDMA_H
void MyDMA_Init(uint32_t AddrA, uint32_t AddrB, uint16_t size);
#endif`
(2)MyDMA.c
`#include "stm32f10x.h"
void MyDMA_Init(uint32_t AddrA, uint32_t AddrB, uint16_t size)
{
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
DMA_InitTypeDef DMA_InitStructure;
DMA_InitStructure.DMA_PeripheralBaseAddr = AddrA;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Enable;
DMA_InitStructure.DMA_MemoryBaseAddr = AddrB;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = size;
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
DMA_InitStructure.DMA_M2M = DMA_M2M_Enable;
DMA_InitStructure.DMA_Priority = DMA_Priority_Medium;
DMA_Init(DMA1_Channel1, &DMA_InitStructure);
}`
(3) **main.c **
`#include "stm32f10x.h"
#include "MyDMA.h"
uint8_t DataA[] = {0x01, 0x02, 0x03, 0x04};
uint8_t DataB[] = {0, 0, 0, 0};
int main()
{
MyDMA_Init((uint32_t)DataA, (uint32_t)DataB, 4);
while (1)
{
}
}`
期望现象
<!--您期望应该产生的,但实际上却没有发生的结果-->
Program compile normally.