|
6 | 6 |
|
7 | 7 | #include "bindings/espulp/__init__.h"
|
8 | 8 | #include "bindings/espulp/ULP.h"
|
| 9 | +#include "bindings/espidf/__init__.h" |
9 | 10 |
|
10 | 11 | #include "py/runtime.h"
|
11 | 12 | #include "shared-bindings/microcontroller/Pin.h"
|
@@ -37,10 +38,7 @@ void espulp_reset(void) {
|
37 | 38 | }
|
38 | 39 |
|
39 | 40 | void common_hal_espulp_ulp_set_wakeup_period(espulp_ulp_obj_t *self, size_t period_index, uint32_t period_us) {
|
40 |
| - int _errno = ulp_set_wakeup_period(period_index, period_us); |
41 |
| - if (_errno != ESP_OK) { |
42 |
| - mp_raise_ValueError(MP_ERROR_TEXT("Invalid parameters")); |
43 |
| - } |
| 41 | + CHECK_ESP_RESULT(ulp_set_wakeup_period(period_index, period_us)); |
44 | 42 | }
|
45 | 43 |
|
46 | 44 | void common_hal_espulp_ulp_run(espulp_ulp_obj_t *self, uint32_t *program, size_t length, uint32_t entry_point, uint32_t pin_mask) {
|
@@ -83,24 +81,24 @@ void common_hal_espulp_ulp_run(espulp_ulp_obj_t *self, uint32_t *program, size_t
|
83 | 81 | esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
|
84 | 82 | }
|
85 | 83 |
|
86 |
| - int _errno; |
| 84 | + esp_err_t result; |
87 | 85 | switch (self->arch) {
|
88 | 86 | #ifdef CONFIG_ULP_COPROC_TYPE_FSM
|
89 | 87 | case FSM:
|
90 |
| - _errno = ulp_load_binary(0, (const uint8_t *)program, length / sizeof(uint32_t)); |
91 |
| - if (_errno != ESP_OK) { |
92 |
| - mp_raise_RuntimeError(MP_ERROR_TEXT("Load binary failed")); |
93 |
| - } |
94 |
| - _errno = ulp_run(entry_point / sizeof(uint32_t)); |
95 |
| - if (_errno != ESP_OK) { |
96 |
| - mp_raise_RuntimeError(MP_ERROR_TEXT("Run binary failed")); |
| 88 | + result = ulp_load_binary(0, (const uint8_t *)program, length / sizeof(uint32_t)); |
| 89 | + if (result != ESP_OK) { |
| 90 | + mp_raise_ValueError_varg(MP_ERROR_TEXT("Invalid %q"), MP_QSTR_program); |
97 | 91 | }
|
| 92 | + CHECK_ESP_RESULT(ulp_run(entry_point / sizeof(uint32_t))); |
98 | 93 | break;
|
99 | 94 | #endif
|
100 | 95 | #ifdef CONFIG_ULP_COPROC_TYPE_RISCV
|
101 | 96 | case RISCV:
|
102 |
| - ulp_riscv_load_binary((const uint8_t *)program, length); |
103 |
| - ulp_riscv_run(); |
| 97 | + result = ulp_riscv_load_binary((const uint8_t *)program, length); |
| 98 | + if (result != ESP_OK) { |
| 99 | + mp_raise_ValueError_varg(MP_ERROR_TEXT("Invalid %q"), MP_QSTR_program); |
| 100 | + } |
| 101 | + CHECK_ESP_RESULT(ulp_riscv_run()); |
104 | 102 | break;
|
105 | 103 | #endif
|
106 | 104 | default:
|
|
0 commit comments