-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
stm32: Fix DAC issue for MCUs those have D-Cache. #17770
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
stm32: Fix DAC issue for MCUs those have D-Cache. #17770
Conversation
Code size report:
|
ports/stm32/dac.c
Outdated
@@ -485,6 +485,11 @@ mp_obj_t pyb_dac_write_timed(size_t n_args, const mp_obj_t *pos_args, mp_map_t * | |||
#endif | |||
} | |||
|
|||
#if defined(STM32F7) || defined(STM32H7) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be able to remove this if conditional. The MP_HAL_CLEAN_DCACHE
macro is defined to nothing on MCUs that don't have a D-cache.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your comment.
Indeed, MP_HAL_CLEAN_DCACHE can use without condition with STM32F7/H7.
micropython/ports/stm32/mpconfigboard_common.h
Lines 705 to 716 in c9b52b2
// D-cache clean/invalidate helpers | |
#if __DCACHE_PRESENT == 1 | |
// Note: The SCB_Clean<...> functions automatically align their arguments to cover full cache lines. | |
// CLEANINVALIDATE will write back (flush) any dirty lines in this region to RAM, then | |
// invalidate (evict) the whole region from the cache. | |
#define MP_HAL_CLEANINVALIDATE_DCACHE(addr, size) SCB_CleanInvalidateDCache_by_Addr((volatile void *)(addr), (size)) | |
// CLEAN will write back (flush) any dirty lines in this region to RAM. | |
#define MP_HAL_CLEAN_DCACHE(addr, size) SCB_CleanDCache_by_Addr((volatile void *)(addr), (size)) | |
#else | |
#define MP_HAL_CLEANINVALIDATE_DCACHE(addr, size) | |
#define MP_HAL_CLEAN_DCACHE(addr, size) | |
#endif |
I removed condition for STM32F7/H7.
d0ff58f
to
d929c70
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updating, looks good now.
To prevent wrong DAC output, clean D-cache before starting DMA. For more details, please refer to the following document: https://www.st.com/resource/en/application_note/DM00272913.pdf Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
d929c70
to
365329c
Compare
Summary
The following code does not work with NUCLEO-F767ZI.
Incorrect wave may be output on PA4. STM32H7 has same issue.
For MCUs which has D-Cache (such as STM32F7, STM32H7), clean D-cache before starting DMA.
For more details, please refer follwing document:
https://www.st.com/resource/en/application_note/DM00272913.pdf
This PR cleans D-cache before starting DMA.
Testing
Tested code above with:
-> Both boards output wave as expected.