Skip to content

Commit fb4da28

Browse files
committed
espulp: update docs and fix halt() for esp32
1 parent b5b13f5 commit fb4da28

File tree

2 files changed

+24
-10
lines changed
  • ports/espressif

2 files changed

+24
-10
lines changed

ports/espressif/bindings/espulp/ULP.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
//| Raises an exception if another ULP has been instantiated. This
4040
//| ensures that is is only used by one piece of code at a time.
4141
//|
42-
//| :param Architecture arch: The ulp arch"""
42+
//| :param Architecture arch: The ulp arch. Only `FSM` architecture
43+
//| is currently supported."""
4344
//| ...
4445
STATIC mp_obj_t espulp_ulp_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
4546
enum { ARG_arch };
@@ -148,7 +149,9 @@ STATIC mp_obj_t espulp_ulp_run(size_t n_args, const mp_obj_t *pos_args, mp_map_t
148149

149150
for (mp_uint_t i = 0; i < num_pins; i++) {
150151
mp_obj_t pin_obj = mp_obj_subscr(pins_in, MP_OBJ_NEW_SMALL_INT(i), MP_OBJ_SENTINEL);
151-
validate_obj_is_free_pin(pin_obj, MP_QSTR_pin);
152+
// common-hal checks that pin is free (that way a possible "ULP already running" error
153+
// is triggered before a possible "Pin in use" error, if ulp.run is called twice with the same pins).
154+
validate_obj_is_pin(pin_obj, MP_QSTR_pin);
152155
const mcu_pin_obj_t *pin = ((const mcu_pin_obj_t *)pin_obj);
153156
if (pin->number >= 32) {
154157
raise_ValueError_invalid_pin();
@@ -162,7 +165,9 @@ STATIC mp_obj_t espulp_ulp_run(size_t n_args, const mp_obj_t *pos_args, mp_map_t
162165
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(espulp_ulp_run_obj, 2, espulp_ulp_run);
163166

164167
//| def halt(self) -> None:
165-
//| """Halts the running program and releases the pins given in `run()`."""
168+
//| """Halts the running program and releases the pins given in `run()`.
169+
//| Note: for the FSM ULP, a running ULP program is not actually interupted.
170+
//| Instead, only the wakeup timer is stopped."""
166171
//| ...
167172
STATIC mp_obj_t espulp_ulp_halt(mp_obj_t self_in) {
168173
espulp_ulp_obj_t *self = MP_OBJ_TO_PTR(self_in);

ports/espressif/common-hal/espulp/ULP.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,22 @@ void common_hal_espulp_ulp_run(espulp_ulp_obj_t *self, uint32_t *program, size_t
131131
}
132132

133133
void common_hal_espulp_ulp_halt(espulp_ulp_obj_t *self) {
134-
#ifdef CONFIG_ULP_COPROC_TYPE_RISCV
135-
if (self->arch == RISCV) {
136-
ulp_riscv_timer_stop();
137-
ulp_riscv_halt();
138-
}
139-
#endif
140-
CLEAR_PERI_REG_MASK(RTC_CNTL_ULP_CP_TIMER_REG, RTC_CNTL_ULP_CP_SLP_TIMER_EN);
134+
switch (self->arch) {
135+
#ifdef CONFIG_ULP_COPROC_TYPE_FSM
136+
case FSM:
137+
ulp_timer_stop();
138+
break;
139+
#endif
140+
#ifdef CONFIG_ULP_COPROC_TYPE_RISCV
141+
case RISCV:
142+
ulp_riscv_timer_stop();
143+
ulp_riscv_halt();
144+
break;
145+
#endif
146+
default:
147+
mp_raise_NotImplementedError(NULL);
148+
break;
149+
}
141150

142151
// Release pins we were using.
143152
for (uint8_t i = 0; i < 32; i++) {

0 commit comments

Comments
 (0)