Reputation: 1
We're transitioning from embedded firmware to Linux development and have a specific requirement: we need to generate a digital waveform (a sequence of 1s and 0s) on a GPIO pin at a specific frequency between 10KHz-500KHz using DMA. We're using the STM32MP131 chip.
While we're aware that we can create a custom kernel driver to achieve this, we're curious if there's a pre-existing, more general-purpose solution. A digital waveform generator seems like a versatile tool that could be useful in many scenarios.
Does anyone know of such a driver or module? A similar driver we could leverage as a starting point? Or perhaps a more efficient approach to generate digital waveforms on Linux?
We have looked at https://github.com/torvalds/linux/blob/master/drivers but didn't find anything that suited our needs.
Upvotes: 0
Views: 78
Reputation: 105
Depending on your hardware you can use the pwm driver + device tree configuration to configure and output a waveform using the on chip PWM hardware. You can find a list of mainline PWM drivers here: https://github.com/torvalds/linux/tree/master/drivers/pwm . Once you have the driver in, supporting hardware, and the electronics correct, then you can write out to the corresponding files around /sys/class/pwm/ to configure the period and set your duty cycle. The last project I did with this was to link a GPIO pin and a timer channel to get PWM out on the GPIO pin.
I know it's not what you asked but you can hook the DAC pins together with the DMA to play the output waveform via DMA. Here is the application note. https://www.st.com/resource/en/application_note/an3126-audio-and-waveform-generation-using-the-dac-in-stm32-products-stmicroelectronics.pdf
Edit 1: Thank you for the hardware info in the edit, I have used the STM32MP157C fairly extensively for the last few years myself. Something like this might be useful. https://wiki.analog.com/resources/tools-software/linux-software/libiio?rev=1700088641 https://wiki.analog.com/resources/tools-software/linux-software/libiio_internals
Chapter 15 and 16 cover the MDMA and DMA https://www.st.com/resource/en/reference_manual/rm0475-stm32mp13xx-advanced-armbased-32bit-mpus-stmicroelectronics.pdf
Upvotes: 1