Skip to content

Commit

Permalink
stm32/dac: Deinit all DACs on soft reset.
Browse files Browse the repository at this point in the history
DAC timed functions continue to run after a soft reset cycle, using
collected memory in the case of write_timed.
  • Loading branch information
iabdalkader authored and dpgeorge committed Jan 27, 2022
1 parent c1841c2 commit a00e1e5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ports/stm32/dac.c
Expand Up @@ -131,6 +131,13 @@ STATIC void dac_deinit(uint32_t dac_channel) {
#endif
}

void dac_deinit_all(void) {
dac_deinit(DAC_CHANNEL_1);
#if !defined(STM32L452xx)
dac_deinit(DAC_CHANNEL_2);
#endif
}

STATIC void dac_config_channel(uint32_t dac_channel, uint32_t trig, uint32_t outbuf) {
DAC->CR &= ~(DAC_CR_EN1 << dac_channel);
uint32_t cr_off = DAC_CR_DMAEN1 | DAC_CR_MAMP1 | DAC_CR_WAVE1 | DAC_CR_TSEL1 | DAC_CR_TEN1;
Expand Down
2 changes: 2 additions & 0 deletions ports/stm32/dac.h
Expand Up @@ -28,4 +28,6 @@

extern const mp_obj_type_t pyb_dac_type;

void dac_deinit_all(void);

#endif // MICROPY_INCLUDED_STM32_DAC_H
3 changes: 3 additions & 0 deletions ports/stm32/main.c
Expand Up @@ -654,6 +654,9 @@ void stm32_main(uint32_t reset_mode) {
#if MICROPY_HW_ENABLE_CAN
can_deinit_all();
#endif
#if MICROPY_HW_ENABLE_DAC
dac_deinit_all();
#endif
machine_deinit();

#if MICROPY_PY_THREAD
Expand Down

0 comments on commit a00e1e5

Please sign in to comment.