Optimizer problem with USBPD
Hi,
I have an USBPD sink application created with CubeMX that can be found here:
https://github.com/ThiRom/H563NucleoUSBPDSink
The project can be build using cmake. If the project is build using Debug configuration, it works. But using Release it shows timeouts on requests. As you can see below during one millisecond the firmware sends 3 retries and a soft reset. 
This problem can be seen with -O2 and -O3 option. It seems that the file usbpd_timersserver.c is not working correctly. I found that function:
uint32_t USBPD_TIM_IsExpired(TIM_identifier Id)
{
uint32_t _expired = 1u;
switch (Id)
{
case TIM_PORT0_CRC:
_expired = TIMX_CHANNEL1_GETFLAG(TIMX);
break;
case TIM_PORT0_RETRY:
_expired = TIMX_CHANNEL2_GETFLAG(TIMX);
break;
case TIM_PORT1_CRC:
_expired = TIMX_CHANNEL3_GETFLAG(TIMX);
break;
case TIM_PORT1_RETRY:
_expired = TIMX_CHANNEL4_GETFLAG(TIMX);
break;
default:
break;
}
return _expired;
}
When I change it to this:
uint32_t USBPD_TIM_IsExpired(TIM_identifier Id)
{
uint32_t _expired = 1u;
switch (Id)
{
case TIM_PORT0_CRC:
_expired = TIMX_CHANNEL1_GETFLAG(TIMX);
break;
case TIM_PORT0_RETRY:
_expired = 0;
break;
case TIM_PORT1_CRC:
_expired = TIMX_CHANNEL3_GETFLAG(TIMX);
break;
case TIM_PORT1_RETRY:
_expired = TIMX_CHANNEL4_GETFLAG(TIMX);
break;
default:
break;
}
return _expired;
}
It works.
Any idea how to fix it correctly?
Best regards
Roman
