# Is it possible to get audio tone from STM32405RG off PB7 pin?

I have been doing some software work on an open source hardware/software project that produces a video overlay, but also offers an apparent audio out pin that is so far unused. The original developer of the hardware is nowhere to be found, and no questions asked of him have been answered for almost a year.

The board (which has already been produced in quantity, so changing it is not an option currently) offers a hook to an apparent audio out line off PB7:

https://github.com/StewLG/PlayuavOSD/blob/master/hardware/PlayUAVOSD_Schematic.pdf

I would like to get a simple tone of variable pitch on this line. If it could be a smooth sine wave from the DAC, that would be best, but even a rough triangular or even square wave would be useful to the users of this board.

I am not a EE guy by trade, so the 2 hours I've put into researching this might not have been enough. If someone actually has relevant code that would be a lovely miracle, but just general directions for how I might be able to hook the components of the microprocessor together in code would be most welcome. Can I use one of the DACs? Am I limited because this is UART pin?

The alternate functions of PB7 are listed as TIM4_CH2, I2C1_SDA, USART1_RX, FSMC_NL, and DCMI_VSYNC. Are any of those functions useful for making audio?

@ChrisStratton:

TIM4 is apparently being used to count horizontal lines in the video:

// Line counter: Counts number of HSYNCS (from hsync_capture) and triggers output of first visible line  See line 274 here: https://github.com/StewLG/PlayuavOSD/blob/master/src/osdcore.c

• If TIM4 is not yet used you can use output compare 2 as a PWM DAC. If it is used, you may still be able to do that, depending on what else it needs to do. A simpler step is to just use it as a rectangular pulse generator. And if nothing else, the STM32's are certainly capable of toggling a GPIO at an audio rate from software, however this could be tricky depending on what else you need the processor to do at the same time. It's not even out of the question that you could (a)buse the DCMI to generate VSYNC pulses at a range of audible rates. – Chris Stratton Oct 18 '16 at 17:03
• TIM4 is currently being used to count horizontal lines in the video signal - I think? – StewLG Oct 18 '16 at 17:17
• @StewLG Indeed, TIM4 seems to be used. But I suspect another timer could be used for that horz lines couting purpose, because apparently, it is just triggered internally by TIM2. So you could, for example, use TIM5 instead, which can also be triggered by TIM2 (as ITR0, see ref manual). Also check who potentially uses the resulting trigger from TIM4 and make the appropriate changes (I saw it triggers an interrupt, at least - check it doesn't trigger other peripherals too). Once you have done this, you will be free to use TIM4 for some sound generation. – dim Oct 18 '16 at 20:03
• Also, if you use TIM4 as a PWM DAC rather than direct rectangluar wave generator, you'll need some capacitance (like 220nF for ~10kHz cutoff) between AUDIO_OUT and ground, because there is no low-pass in the schematic yet. – dim Oct 18 '16 at 20:13