DAC2 on STM32H7A3 / STM32H7B3 / STM32H7B0

Report here problems in any of ChibiOS components. This forum is NOT for support.
nikiwaibel
Posts: 29
Joined: Sat Mar 17, 2018 2:51 pm
Has thanked: 8 times
Been thanked: 15 times

DAC2 on STM32H7A3 / STM32H7B3 / STM32H7B0

Postby nikiwaibel » Sat Sep 28, 2024 10:40 pm

it seems, DAC2 is missing for / does not compile on STM32H7A3 / STM32H7B3 / STM32H7B0, so far. those H7 variations contain DAC1, which has 2 channels, as well as DAC2, which has only one channel.

to compile, when having #define STM32_DAC_USE_DAC2_CH1 TRUE in mcuconf.h, the following patch is required:

Code: Select all

Index: os/hal/ports/STM32/LLD/DACv1/hal_dac_lld.c
===================================================================
--- os/hal/ports/STM32/LLD/DACv1/hal_dac_lld.c   (revision 16600)
+++ os/hal/ports/STM32/LLD/DACv1/hal_dac_lld.c   (working copy)
@@ -166,8 +166,12 @@
   .regmask      = CHANNEL_REGISTER_MASK1,
   .dmastream    = STM32_DAC_DAC2_CH1_DMA_STREAM,
 #if STM32_DMA_SUPPORTS_DMAMUX
+#if defined(STM32_DMAMUX2_DAC2)
+  .peripheral   = STM32_DMAMUX2_DAC2,
+#else
   .peripheral   = STM32_DMAMUX1_DAC2_CH1,
 #endif
+#endif
   .dmamode      = STM32_DMA_CR_CHSEL(DAC2_CH1_DMA_CHANNEL) |
                   STM32_DMA_CR_PL(STM32_DAC_DAC2_CH1_DMA_PRIORITY) |
                   STM32_DMA_CR_MINC | STM32_DMA_CR_CIRC | STM32_DMA_CR_DIR_M2P |
Index: os/hal/ports/STM32/STM32H7xx/stm32_dmamux.h
===================================================================
--- os/hal/ports/STM32/STM32H7xx/stm32_dmamux.h   (revision 16600)
+++ os/hal/ports/STM32/STM32H7xx/stm32_dmamux.h   (working copy)
@@ -168,9 +168,16 @@
 #define STM32_DMAMUX2_SPI6_TX       12
 #define STM32_DMAMUX2_I2C4_RX       13
 #define STM32_DMAMUX2_I2C4_TX       14
+#if defined(STM32H7A3xx)  || defined(STM32H7B3xx)  ||                       \
+    defined(STM32H7A3xxQ) || defined(STM32H7B3xxQ) ||                       \
+    defined(STM32H7B0xx)
+#define STM32_DMAMUX2_DAC2          16
+#define STM32_DMAMUX2_DFSDM2        17
+#else
 #define STM32_DMAMUX2_SAI4_A        15
 #define STM32_DMAMUX2_SAI4_B        16
 #define STM32_DMAMUX2_ADC3_REQ      17
+#endif
 /** @} */

 /*===========================================================================*/
Index: os/hal/ports/STM32/STM32H7xx/stm32_rcc.h
===================================================================
--- os/hal/ports/STM32/STM32H7xx/stm32_rcc.h   (revision 16600)
+++ os/hal/ports/STM32/STM32H7xx/stm32_rcc.h   (working copy)
@@ -1093,6 +1093,29 @@
  * @api
  */
 #define rccResetDAC1() rccResetAPB1L(RCC_APB1LRSTR_DAC12RST)
+
+/**
+ * @brief   Enables the DAC2 peripheral clock.
+ *
+ * @param[in] lp        low power enable flag
+ *
+ * @api
+ */
+#define rccEnableDAC2(lp) rccEnableAPB4(RCC_APB4ENR_DAC2EN, lp)
+
+/**
+ * @brief   Disables the DAC2 peripheral clock.
+ *
+ * @api
+ */
+#define rccDisableDAC2() rccDisableAPB4(RCC_APB4ENR_DAC2EN)
+
+/**
+ * @brief   Resets the DAC2 peripheral.
+ *
+ * @api
+ */
+#define rccResetDAC2() rccResetAPB4(RCC_APB4RSTR_DAC2RST)
 /** @} */

 /**

* stm32_dmamux.h: the relevant info can be found in RM0455 on page 564.
* hal_dac_lld.c: an #if like in stm32_dmamux.h could have been used, but i found i more elegant this way.
* stm32_rcc.h: DAC2 was missing here.

Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 9 guests