After much digging and looking in the datasheet for this to me new MCU family, I have finally solved it. There is a small bug in function HAL_PWM_Write. The problem occurs when using an advanced timer (TIM1 or TIM8).They use some more settings in the structure (TIM_OCInitTypeDef) then the normal timers. They are then used by TIM_OCxInit, so they need to be initialized or they will have whatever value was on the stack when “allocated” and in the end causes random values in the TIM1(8)->CCER register.
Setting all the extra values in TIM_OCInitTypeDef to zeros works fine as long as you are not going into using any of the complementary outputs of the advanced timers.
So finally the small simplest fix is just to add a = {0}.
The row 51 in hal/src/stm32f2xx/pwm_hal.c should be changed to:
TIM_OCInitTypeDef TIM_OCInitStructure = {0};
I’m a bit surprised that no one else has seen the problem; it should appear on the Photon as well as the P1 and applies to all Timer1 and Timer8 (none of TIM8 channels are mapped as default) channels.
I’m hoping someone on the firmware team (@mdma) can catch this up and make the fix, seems a bit much to do a pull request for this small change.
I hope this can help someone avoiding the struggle I had with this
/Janne