Skip to content

stm32: Fix 12bit DAC issue on STM32H5. #17743

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

yn386
Copy link
Contributor

@yn386 yn386 commented Jul 22, 2025

Summary

The following code does not work with NUCLEO-H563ZI.

import math
from array import array
from pyb import DAC

# create a buffer containing a sine-wave, using half-word samples
buf = array('H', 2048 + int(2047 * math.sin(2 * math.pi * i / 128)) for i in range(128))

# output the sine-wave at 400Hz
dac = DAC(2, bits=12)
dac.write_timed(buf, 400 * len(buf), mode=DAC.CIRCULAR)

For STM32H5, DMA parameter should set:

  • Actual DMA source datawidth to CTR1.
  • The length is the amount of data to be transferred from source to destiniation in bytes. to use 12bit DAC.

Also, this PR modifies the definition of DMA_CIRCULAR for STM32H5 to prevent conflict with data width specification.

Testing

Tested code above with NUCLEO-H563ZI.
Also, DAC with 8bit still works after applying this PR.

Trade-offs and Alternatives

The value of DAC_CIRCULAR is changed:
from

>>> hex(DAC.CIRTUCLAR)
'0x1'

to

>>> hex(DAC.CIRCULAR)
'0x20000000'

Indeed, it won't be a problem because users do not need to be aware of value of DAC.CIRCULAR in most cases.

For STM32H5, DMA parameter should set:
 * Actual DMA source datawidth to CTR1.
 * The length is the amount of data to be transferred
   from source to destiniation in bytes.
to use 12bit DAC.

Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
Copy link

Code size report:

   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy