summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStig Bjørlykke <stig@bjorlykke.org>2018-07-31 22:19:31 +0200
committerGlenn Ruben Bakke <glennbakke@gmail.com>2018-08-01 14:56:07 +0200
commit0c161691b490b885c40c96b34bbb13264e259dff (patch)
tree38ca0a44269cd6cb79581a3c5c04a0da310e3ef5
parent7f0c5f2ef955a09abf2f05e9ef0b4b0513f41f11 (diff)
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.
-rw-r--r--ports/nrf/modules/machine/adc.c2
-rw-r--r--ports/nrf/modules/machine/pwm.c2
-rw-r--r--ports/nrf/modules/machine/rtcounter.c2
3 files changed, 3 insertions, 3 deletions
diff --git a/ports/nrf/modules/machine/adc.c b/ports/nrf/modules/machine/adc.c
index d863aebb3..ce4805692 100644
--- a/ports/nrf/modules/machine/adc.c
+++ b/ports/nrf/modules/machine/adc.c
@@ -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;
}
diff --git a/ports/nrf/modules/machine/pwm.c b/ports/nrf/modules/machine/pwm.c
index 27355f2b1..f4354818f 100644
--- a/ports/nrf/modules/machine/pwm.c
+++ b/ports/nrf/modules/machine/pwm.c
@@ -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,
diff --git a/ports/nrf/modules/machine/rtcounter.c b/ports/nrf/modules/machine/rtcounter.c
index d3c0280d6..ea4a17626 100644
--- a/ports/nrf/modules/machine/rtcounter.c
+++ b/ports/nrf/modules/machine/rtcounter.c
@@ -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,