Page 19 of 24
Re: Where to start STM32H7 support
Posted: Wed Jan 20, 2021 9:26 am
by andypiper
Giovanni wrote:Hi,
As far I know TIMs are exactly the same on all platforms. Are you changing PWM channels settings on the fly?
Giovanni
Yeah so the process is:
1. setup PWM and output pulses using DMAR on the UP channel
2. output the pulses
3. switch the PWM timer to do input capture using one of the CH channels but sharing the same DMA channel as (1) so use dmaSetRequestSource()
4. once input capture is complete reset dmaSetRequestSource and reset PWM for output through pwmStop()/pwmStart()
So I have tested this on an F745 board with identical pinout and it works fine, so something is going on on H7
Re: Where to start STM32H7 support
Posted: Wed Jan 20, 2021 10:16 am
by Giovanni
Changing the timer settings while the timer is active does not look very clean, it is possible they added some logic to prevent this kind of things (for safety).
Giovanni
Re: Where to start STM32H7 support
Posted: Wed Jan 20, 2021 11:04 am
by andypiper
Giovanni wrote:Changing the timer settings while the timer is active does not look very clean, it is possible they added some logic to prevent this kind of things (for safety).
Giovanni
Ok so maybe I should disable the timer before any settings change each time? What would be the best way of doing this cleanly?
Re: Where to start STM32H7 support
Posted: Wed Jan 20, 2021 12:06 pm
by Giovanni
You should do all settings before starting the timer, the PWM driver does not allow this because the start function writes all registers then starts it (CEN bit).
You may try to toggle CEN to zero then do your setup and see if this solves your problem but the driver has not been designed for this.
Giovanni
Re: Where to start STM32H7 support
Posted: Wed Jan 20, 2021 2:31 pm
by andypiper
Giovanni wrote:You should do all settings before starting the timer, the PWM driver does not allow this because the start function writes all registers then starts it (CEN bit).
You may try to toggle CEN to zero then do your setup and see if this solves your problem but the driver has not been designed for this.
Giovanni
Ok that's ok - when I do the input capture I am essentially ignoring the pwm setup (pwm is done), I do the input capture then restart the pwm driver.
What I am thinking is perhaps I should call pwmStop before this second part - is that safe/efficient in an ISR context?
Re: Where to start STM32H7 support
Posted: Wed Jan 20, 2021 3:05 pm
by Giovanni
It is not possible, stop() and start() functions cannot be used from ISR and stop() would also stop clocks, you could not write registers anymore.
Giovanni
Re: Where to start STM32H7 support
Posted: Wed Jan 20, 2021 3:40 pm
by andypiper
Giovanni wrote:It is not possible, stop() and start() functions cannot be used from ISR and stop() would also stop clocks, you could not write registers anymore.
Giovanni
Ok thanks - I'll try with CEN for now. I notice that we are setting it to 0 but only after manipulating CCER/CCMR1/CCMR2
Re: Where to start STM32H7 support
Posted: Wed Jan 20, 2021 10:58 pm
by andypiper
andypiper wrote:Giovanni wrote:It is not possible, stop() and start() functions cannot be used from ISR and stop() would also stop clocks, you could not write registers anymore.
Giovanni
Ok thanks - I'll try with CEN for now. I notice that we are setting it to 0 but only after manipulating CCER/CCMR1/CCMR2
Makes no difference and I am out of ideas, will have to park this for now

Re: Where to start STM32H7 support
Posted: Fri Jan 22, 2021 9:26 am
by andypiper
On a related note are there any examples of setting up MPU attributes on memory regions? It looks like STM recommend using non-cacheable memory for DMA, so I am going to try that but struggling to find an example of doing this the ChibiOS way
Re: Where to start STM32H7 support
Posted: Fri Jan 22, 2021 9:54 am
by Giovanni
Hi,
No need to struggle too much, in mcuconf.h there is this:
Code: Select all
/*
* Memory attributes settings.
*/
#define STM32_NOCACHE_MPU_REGION MPU_REGION_6
#define STM32_NOCACHE_SRAM1_SRAM2 FALSE
#define STM32_NOCACHE_SRAM3 TRUE
The related code is in hal_lld.c, you can use that as example.
Giovanni