我是新编程的STM32F发现板。我按照指示here并设法使闪烁的led灯工作。
但现在我正在尝试播放一种音频,我已经从here中借用了代码。在我的Makefile中,我包含了CFLAGS += -lm,这是我理解arm_sin_f32定义的地方。
这是main.c的代码:

#define USE_STDPERIPH_DRIVER
#include "stm32f4xx.h"
#define ARM_MATH_CM4
#include <arm_math.h>
#include <math.h>
#include "speaker.h"

//Quick hack, approximately 1ms delay
void ms_delay(int ms)
{
    while (ms-- > 0) {
      volatile int x=5971;
      while (x-- > 0)
        __asm("nop");
   }
}

volatile uint32_t msTicks = 0;

// SysTick Handler (every time the interrupt occurs, this is called)
void SysTick_Handler(void){ msTicks++; }

// initialize the system tick
void InitSystick(void){
   SystemCoreClockUpdate();
    // division occurs in terms of seconds... divide by 1000 to get ms, for example
   if (SysTick_Config(SystemCoreClock / 10000)) { while (1); } //
update every 0.0001 s, aka 10kHz
}


//Flash orange LED at about 1hz
int main(void)
{
    SystemInit();
    InitSystick();
    init_speaker();
    int16_t audio_sample;
    int loudness = 250;
    float audio_freq = 440;
    audio_sample = (int16_t) (loudness * arm_sin_f32(audio_freq*msTicks/10000));
    send_to_speaker(audio_sample);
}

但是当尝试运行make时,我得到以下错误:
main.c:42: undefined reference to `arm_sin_f32'

最佳答案

首先,arm_sin_32不存在。例如arm_sin_f32是。还有更多不同的。您需要将CMSIS中的适当c文件添加到项目中,例如:CMSIS/DSP/Source/FastMathFunctions/arm_sin_f32.c
我建议不要使用keil的版本,因为它可能已经过时了——只需从github下载CMSIS的最新版本。
手臂。。。。函数不是m库的一部分。
不要使用nop-s来延迟,因为它们会在没有执行的情况下立即从管道中排出。它们只用于填充

10-06 15:09