Skip to content
Snippets Groups Projects
Commit 0c161691 authored by Stig Bjørlykke's avatar Stig Bjørlykke Committed by Glenn Ruben Bakke
Browse files

nrf: Correct index checking of ADC/PWM/RTCounter instances.

Avoid trying to use ADC, PWM and RTCounter instances which is
one past last available, because this will give a HardFault.
parent 7f0c5f2e
No related branches found
No related tags found
No related merge requests found
......@@ -96,7 +96,7 @@ STATIC int adc_find(mp_obj_t id) {
int adc_idx = adc_id;
if (adc_idx >= 0 && adc_idx <= MP_ARRAY_SIZE(machine_adc_obj)
if (adc_idx >= 0 && adc_idx < MP_ARRAY_SIZE(machine_adc_obj)
&& machine_adc_obj[adc_idx].id != (uint8_t)-1) {
return adc_idx;
}
......
......@@ -97,7 +97,7 @@ STATIC int hard_pwm_find(mp_obj_t id) {
if (MP_OBJ_IS_INT(id)) {
// given an integer id
int pwm_id = mp_obj_get_int(id);
if (pwm_id >= 0 && pwm_id <= MP_ARRAY_SIZE(machine_hard_pwm_obj)) {
if (pwm_id >= 0 && pwm_id < MP_ARRAY_SIZE(machine_hard_pwm_obj)) {
return pwm_id;
}
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
......
......@@ -113,7 +113,7 @@ void rtc_init0(void) {
STATIC int rtc_find(mp_obj_t id) {
// given an integer id
int rtc_id = mp_obj_get_int(id);
if (rtc_id >= 0 && rtc_id <= MP_ARRAY_SIZE(machine_rtc_obj)) {
if (rtc_id >= 0 && rtc_id < MP_ARRAY_SIZE(machine_rtc_obj)) {
return rtc_id;
}
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment