@@ -75,9 +75,6 @@ HardwareTimer::HardwareTimer(TIM_TypeDef *instance)
7575void HardwareTimer::setup (TIM_TypeDef *instance)
7676{
7777uint32_t index =get_timer_index (instance);
78- if (index == UNKNOWN_TIMER) {
79- Error_Handler ();
80- }
8178
8279// Already initialized?
8380if (_timerObj.handle .Instance ) {
@@ -174,14 +171,7 @@ void HardwareTimer::pauseChannel(uint32_t channel)
174171
175172int timAssociatedInputChannel;
176173int LLChannel =getLLChannel (channel);
177- if (LLChannel == -1 ) {
178- Error_Handler ();
179- }
180-
181174int interrupt =getIT (channel);
182- if (interrupt == -1 ) {
183- Error_Handler ();
184- }
185175
186176// Disable channel and corresponding interrupt
187177__HAL_TIM_DISABLE_IT (&(_timerObj.handle ), interrupt);
@@ -234,11 +224,11 @@ void HardwareTimer::resume(void)
234224/* *
235225 * @brief Convert arduino channel into HAL channel
236226 * @param Arduino channel [1..4]
237- * @retval HAL channel.return -1 if arduino channel is invalid
227+ * @retval HAL channel.Error handler called if arduino channel is invalid
238228*/
239229int HardwareTimer::getChannel (uint32_t channel)
240230{
241- uint32_t return_value;
231+ int return_value = - 1 ;
242232
243233switch (channel) {
244234case 1 :
@@ -254,15 +244,15 @@ int HardwareTimer::getChannel(uint32_t channel)
254244 return_value = TIM_CHANNEL_4;
255245break ;
256246default :
257- return_value = - 1 ;
247+ Error_Handler () ;
258248 }
259249return return_value;
260250}
261251
262252/* *
263253 * @brief Convert arduino channel into LL channels used (regular and/or complementary)
264254 * @param Arduino channel [1..4]
265- * @retval LL channel.return -1 if arduino channel is invalid
255+ * @retval LL channel.Error handler called if arduino channel is invalid
266256*/
267257int HardwareTimer::getLLChannel (uint32_t channel)
268258{
@@ -310,17 +300,20 @@ int HardwareTimer::getLLChannel(uint32_t channel)
310300 return_value = -1 ;
311301 }
312302 }
303+ if (return_value == -1 ) {
304+ Error_Handler ();
305+ }
313306return return_value;
314307}
315308
316309/* *
317310 * @brief Convert arduino channel into HAL Interrupt ID
318311 * @param Arduino channel [1..4]
319- * @retval HAL channel.return -1 if arduino channel is invalid
312+ * @retval HAL channel.Error handler called if arduino channel is invalid
320313*/
321314int HardwareTimer::getIT (uint32_t channel)
322315{
323- uint32_t return_value;
316+ int return_value = - 1 ;
324317
325318switch (channel) {
326319case 1 :
@@ -336,7 +329,7 @@ int HardwareTimer::getIT(uint32_t channel)
336329 return_value = TIM_IT_CC4;
337330break ;
338331default :
339- return_value = - 1 ;
332+ Error_Handler () ;
340333 }
341334return return_value;
342335}
@@ -378,19 +371,7 @@ void HardwareTimer::resumeChannel(uint32_t channel)
378371{
379372int timChannel =getChannel (channel);
380373int timAssociatedInputChannel;
381- if (timChannel == -1 ) {
382- Error_Handler ();
383- }
384-
385374int interrupt =getIT (channel);
386- if (interrupt == -1 ) {
387- Error_Handler ();
388- }
389-
390- int LLChannel =getLLChannel (channel);
391- if (LLChannel == -1 ) {
392- Error_Handler ();
393- }
394375
395376// Clear flag and enable IT
396377if (callbacks[channel]) {
@@ -643,10 +624,6 @@ void HardwareTimer::setMode(uint32_t channel, TimerModes_t mode, PinName pin, Ch
643624 TIM_OC_InitTypeDef channelOC;
644625 TIM_IC_InitTypeDef channelIC;
645626
646- if (timChannel == -1 ) {
647- Error_Handler ();
648- }
649-
650627/* Configure some default values. Maybe overwritten later*/
651628 channelOC.OCMode = TIMER_NOT_USED;
652629 channelOC.Pulse =__HAL_TIM_GET_COMPARE (&(_timerObj.handle ), timChannel);// keep same value already written in hardware register
@@ -822,10 +799,6 @@ void HardwareTimer::setCaptureCompare(uint32_t channel, uint32_t compare, TimerC
822799uint32_t Prescalerfactor =LL_TIM_GetPrescaler (_timerObj.handle .Instance ) +1 ;
823800uint32_t CCR_RegisterValue;
824801
825- if (timChannel == -1 ) {
826- Error_Handler ();
827- }
828-
829802switch (format) {
830803case MICROSEC_COMPARE_FORMAT:
831804 CCR_RegisterValue = ((compare * (getTimerClkFreq () /1000000 )) / Prescalerfactor);
@@ -889,10 +862,6 @@ uint32_t HardwareTimer::getCaptureCompare(uint32_t channel, TimerCompareFormat_
889862uint32_t Prescalerfactor =LL_TIM_GetPrescaler (_timerObj.handle .Instance ) +1 ;
890863uint32_t return_value;
891864
892- if (timChannel == -1 ) {
893- Error_Handler ();
894- }
895-
896865switch (format) {
897866case MICROSEC_COMPARE_FORMAT:
898867 return_value = (uint32_t )((CCR_RegisterValue * Prescalerfactor *1000000.0 ) /getTimerClkFreq ());
@@ -1030,9 +999,6 @@ void HardwareTimer::detachInterrupt()
1030999void HardwareTimer::attachInterrupt (uint32_t channel,callback_function_t callback)
10311000{
10321001int interrupt =getIT (channel);
1033- if (interrupt == -1 ) {
1034- Error_Handler ();
1035- }
10361002
10371003if ((channel ==0 ) || (channel > (TIMER_CHANNELS +1 ))) {
10381004Error_Handler ();// only channel 1..4 have an interrupt
@@ -1059,9 +1025,6 @@ void HardwareTimer::attachInterrupt(uint32_t channel, callback_function_t callba
10591025void HardwareTimer::detachInterrupt (uint32_t channel)
10601026{
10611027int interrupt =getIT (channel);
1062- if (interrupt == -1 ) {
1063- Error_Handler ();
1064- }
10651028
10661029if ((channel ==0 ) || (channel > (TIMER_CHANNELS +1 ))) {
10671030Error_Handler ();// only channel 1..4 have an interrupt
@@ -1198,14 +1161,6 @@ bool HardwareTimer::isRunningChannel(uint32_t channel)
11981161int interrupt =getIT (channel);
11991162bool ret;
12001163
1201- if (LLChannel == -1 ) {
1202- Error_Handler ();
1203- }
1204-
1205- if (interrupt == -1 ) {
1206- Error_Handler ();
1207- }
1208-
12091164// channel is running if: timer is running, and either output channel is
12101165// enabled or interrupt is set
12111166 ret =LL_TIM_CC_IsEnabledChannel (_timerObj.handle .Instance , LLChannel)
@@ -1365,6 +1320,9 @@ timer_index_t get_timer_index(TIM_TypeDef *instance)
13651320 index = TIMER22_INDEX;
13661321 }
13671322#endif
1323+ if (index == UNKNOWN_TIMER) {
1324+ Error_Handler ();
1325+ }
13681326return index;
13691327}
13701328