File tree Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -251,13 +251,19 @@ void pwmout_period_us(pwmout_t* obj, int us)
251
251
TimHandle .Init .Period = (us - 1 );
252
252
253
253
/* In case period or pre-scalers are out of range, loop-in to get valid values */
254
- while ((TimHandle .Init .Period > 0xFFFF ) || (TimHandle .Init .Period > 0xFFFF )) {
254
+ while ((TimHandle .Init .Period > 0xFFFF ) || (TimHandle .Init .Prescaler > 0xFFFF )) {
255
255
obj -> prescaler = obj -> prescaler * 2 ;
256
256
if (APBxCLKDivider == RCC_HCLK_DIV1 )
257
257
TimHandle .Init .Prescaler = (((PclkFreq ) / 1000000 ) * obj -> prescaler ) - 1 ;
258
258
else
259
259
TimHandle .Init .Prescaler = (((PclkFreq * 2 ) / 1000000 ) * obj -> prescaler ) - 1 ;
260
260
TimHandle .Init .Period = (us - 1 ) / obj -> prescaler ;
261
+ /* Period decreases and prescaler increases over loops, so check for
262
+ * possible out of range cases */
263
+ if ((TimHandle .Init .Period < 0xFFFF ) && (TimHandle .Init .Prescaler > 0xFFFF )) {
264
+ error ("Cannot initialize PWM\n" );
265
+ break ;
266
+ }
261
267
}
262
268
263
269
TimHandle .Init .ClockDivision = 0 ;
You can’t perform that action at this time.
0 commit comments