STM32F4 FFT example

Posted on October 23, 2014 at 9:22 PM

As you maybe know, STM32F4 is Cortex M4 with DSP instructions. This allows you to make a FFT with a few simple steps. For that purpose, I have made an example, on how to create FFT with STM32F4.

When the ARM company issued Cortex-M4 core, it also published DSP libraries for mathematics and other stuff. And there are also FFT functions. When you’ve downloaded ST’s standard peripheral drivers, you also downloaded CMSIS (Cortex Microcontroller Software Interface Standard), which are designed for all Cortex-M4 processors from every company.

CMSIS libraries are also included in Keil uVision (5 and newest), you just need to enable them. Under “Manager Run-Time Environment” -> CMSIS select DSP. DSP or Digital Signal Processing is a library for “high mathematics” instructions, which are supported by Cortex-M4 with floating point unit.

Enable DSP library in Keil uVision

Enable DSP library in Keil uVision

Fast Fourier Transform – FFT

Very fast about FFT. FFT or Fast Fourier Transform is an algorithm to convert time based signal into frequency domain. In other words, you are able to know from which sinus components is some signal created.

Everything and more about FFT is described in Wikipedia. Continue reading

Library 41- STDIO implementation for STM32F4

Posted on October 19, 2014 at 1:51 AM

After I made a tutorial on how to use printf with STM32F4, I decided to make a library for printf and other functions that are able to output data to the stream. This library allows you to basically use unlimited different output streams, but just one can be use with printf at a time. You can use other output functions, like fprintf, which accepts stream pointer as parameter to know where to output data.

Library

Features

  • Output strings using printf or any other function, like fprintf, etc
  • Any function which is able to output data to the stream can be used
  • Basically unlimited output streams can be used
  • Version 1.1 – October 19, 2014
    • Added support to read from standard input (stdin) stream or user defined

Continue reading

Use printf to output stream on STM32F4

Posted on October 19, 2014 at 12:06 AM

It would be nice, if you can simply just use printf to direct output strings to USART, LCD, etc. With ARM C, you are able to do this. You just need to implement some things and you are ready to work.

New STDIO library is available here.

To enable printf functionality, first you need to create a new __FILE struct. This struct is then called with FILE struct. It can have only one dummy parameter, but it has to be created, because you need pointer to this structure if you want to output characters to stream. If you need any control for this, you can create your own. I created my own below:

After that, we have to create a variable with FILE struct:

Variable name __stdout is important. You can not use different name, otherwise printf will not work. Last thing we need to create is a function, that will be automatically called from printf and will actually print your charater by character to stream. Function has fixed name and can not be changed. Continue reading

Library 40- Output clocks from STM32F4

Posted on October 18, 2014 at 7:44 PM

STM32F4 has capability to output different clocks on specific 2 pins. You are able to output clocks in original frequency (no prescaler) and also with prescaler values 2, 3, 4 and 5.

2 pins are used to output different frequencies. They are not able to output the same clocks. You can output:

  • MCO1
    • HSI: High Speed Internal oscillator, 16MHz RC
    • HSE: High Speed External oscillator, or External User clock
    • LSE: Low speed, 32768Hz oscillator or ceramic resonator
    • PLLCLK: Output clock from PLL
      • Differ between settings for PLL
  • MCO2
    • SYSCLK: System core clock output
    • PLLI2SCLK: Accurate clock for high-quality audio performance in I2S and SAI interfaces
    • HSE: High Speed External oscillator, or External User clock
    • PLLCLK: Output clock from PLL
      • Differ between settings for PLL

Each clock can be output with no prescaler, or value between 2 – 5.

Library

Features

  • Output different system clocks from STM32F4
  • 2 output pins supported

Continue reading

Library 39- Power consumption modes for STM32F4

Posted on October 18, 2014 at 1:07 AM

For library 39, I made a low power modes library. This allows you to simple put STM32F4 into SLEEP, STOP or STANDBY mode. Point of this modes is simple. You want decrease current on device. If you are working on battery project, this will be very helpful.

You can set current down to about 2uA with proper low power mode.

I will tell you only the highlights of all 3 power down modes in this post. For detailed informations, check ST’s manual here.

STM32F4 Power consumption image from ST

STM32F4 Power consumption image from ST

Library

Features

  • Enable SLEEP mode
  • Enable STOP mode
  • Enable STANDBY mode
    • You can also test, if system was reset because of wakeup from Standby mode.
  • Enable/disable wakeup pin, pin PA0

Continue reading