stm32f407 discovery board as a 100MHz FM transmitter using crystal feedback trick

Hi All,
     It's been a long time I haven't updated my blog coz it is hard to get some free time.  Anyways, I have a small hack to share now.

This is a very simple hack, the aim of this project is to transmit a song stored in STM32F407 flash memory over air by FM at 100MHz. At first you can have a look at the below video, a weird demo taken through my mobile phone. A fixed song is repeatedly transmitted from the stm32f407 discovery and it received on a mobile phone FM radio which is tuned at 100MHz.


How it works?

 A song + voice in wav format is saved in the flash memory from an offset after application code.
The *.wav can be directly dumped into the flash say from address 0x08005000 after renaming the file as *.bin.  This can be done directly by using ST-LINK utility in windows.

Now a small application code is written which starts at 0x08000000 which will read the song file at location 0x08005000 and throws the bytes to a PWM pin. This is done repeatedly in an infinite loop by a timer interrupt which is configured according to the sampling rate of song+voice wav. It can be done by DMA as well.

Now one more thing, the system clock is derived from 8MHz external crystal oscillator. Using the internal PLL, the system clock is set to 100MHz. Now the Master Clock Output option is enabled to toggle a pin (PA8) at 100MHz. So the carrier frequency for FM is ready!

Now if we run the code, the PWM pin (PE9) will get the song data in a pulse width modulated format. An RC filter is connected to this pin to demodulate it and thus we will get a decent analog song signal. If we connect a earphone or an amplifier over here, we should be able to hear the song.

 Fine, now how to transmit the song over air?

"Crystal feedback hack"

The trick over here is to disturb the crystal oscillator according to the song data. For this a 22K resistor is connected from the analog song signal to one of the crystal PIN. This setup will load the crystal circuitry according to the instantaneous amplitude of song signal. The frequency of the crystal is getting affected by this. In simple words, frequency modulation is happening over here. The song data is getting modulated over 8MHz.

We already set the MCO pin to toggle at 100MHz. Since the 100MHz is generated from the 8MHz crystal clock, the modulation will be observed in the 100MHz signal also (obviously magnified). The feedback resistor 22K is selected in such a way that it won't affect the working of the crystal circuitry and won't do over modulation. We can play with these values later.


Sorry, need to connect an antenna on pin PA8 to transmit the signal properly over air.
For time being, I connected a small female jumper wire which was more than enough for the demo.

Yes, now it is done. :)

I am getting range of around 30 meters with this simple 20 cm wire antenna. If we connect a proper quarter wave length wire/telescopic antenna, the range may increase beyond 100meters as well.

(In below photo you can see a 22K resistor connected from RC filter output to crystal pin.
That is the only external hardware modification for FM modulation)

RC filter:
 R = 100 ohms
 C = 0.1 uF

Feedback resistor:
  R = 22K. (Remove R24 and short those contacts and connect feedback resistor from filter output to R24 pin as in the above photo)

The same experiment can be done by connecting an SD card and can transmit the song over the air the same way...... May be we can use helix mp3 decoder to play mp3 files from sd card and can do the same crystal feedback hack...

Thanks to ST for providing a nice GUI tool called stm32CubeMX which generates the initialization code for clock, MCO settings, timer settings etc. This makes the development process much easier and no need to dig into the datasheet to configure the registers.

Source Code: 

Hex file with audio:

  Try it under your own risk.
 This project is for educational purposes only and is not intended to interfere with any radio channels in restricted/commercial bands. Neither site nor I, am liable for careless actions. Please check for the legality before attempting the project within your area. Since the GPIO toggling is not sinusoidal, higher harmonics will be there in the transmitted signal, so be careful while trying it out as it can transmit harmonics in restricted band.