Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 870ceac

Browse files
author
Daniel Campora
committed
esp32: Merge with master up to version 1.17.3.b1
1 parent 1bf377b commit 870ceac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+93
-57
lines changed

drivers/sx127x/sx1272/sx1272.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,7 @@ IRAM_ATTR void SX1272OnDio0Irq( void )
10721072
int8_t snr = 0;
10731073

10741074
// Store the packet timestamp
1075-
SX1272.Settings.LoRaPacketHandler.TimeStamp = mp_hal_ticks_us();
1075+
SX1272.Settings.LoRaPacketHandler.TimeStamp = mp_hal_ticks_us_non_blocking();
10761076

10771077
// Clear Irq
10781078
SX1272Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_RXDONE );

drivers/sx127x/sx1276/sx1276.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1237,7 +1237,7 @@ IRAM_ATTR void SX1276OnDio0Irq( void )
12371237
int8_t snr = 0;
12381238

12391239
// Store the packet timestamp
1240-
SX1276.Settings.LoRaPacketHandler.TimeStamp = mp_hal_ticks_us();
1240+
SX1276.Settings.LoRaPacketHandler.TimeStamp = mp_hal_ticks_us_non_blocking();
12411241

12421242
// Clear Irq
12431243
SX1276Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_RXDONE );
-2.51 KB
Binary file not shown.

esp32/bootloader/lib/liblog.a

140 Bytes
Binary file not shown.

esp32/bootloader/lib/libmicro-ecc.a

52 Bytes
Binary file not shown.

esp32/bootloader/lib/libsoc.a

592 Bytes
Binary file not shown.

esp32/bootloader/lib/libspi_flash.a

72 Bytes
Binary file not shown.

esp32/ftp/updater.c

+1-16
Original file line numberDiff line numberDiff line change
@@ -121,24 +121,9 @@ bool updater_start (void) {
121121

122122
bool updater_write (uint8_t *buf, uint32_t len) {
123123

124-
// the len has to be round-up to multiple of 16
125-
// so, actually up to 15Bytes(garbage) could be written to flash
126-
uint32_t len_aligned_16 = ((len + ENCRYP_FLASH_MIN_CHUNK - 1) / ENCRYP_FLASH_MIN_CHUNK) * ENCRYP_FLASH_MIN_CHUNK;
127-
// sl_LockObjLock (&wlan_LockObj, SL_OS_WAIT_FOREVER);
128-
129-
if (len != len_aligned_16) {
130-
ESP_LOGD(TAG, "Writing %d bytes, actually %d\n", len, len_aligned_16);
131-
}
132-
133-
// check if starting address is 16bytes aligned
134-
if (updater_data.offset % 16) {
135-
ESP_LOGE(TAG, "Start address, not 16 aligned, %X\n", updater_data.offset);
136-
return false;
137-
}
138-
139124
// the actual writing into flash, not-encrypted,
140125
// because it already came encrypted from OTA server
141-
if (ESP_OK != updater_spi_flash_write(updater_data.offset, (void *)buf, len_aligned_16, false)) {
126+
if (ESP_OK != updater_spi_flash_write(updater_data.offset, (void *)buf, len, false)) {
142127
ESP_LOGE(TAG, "SPI flash write failed\n");
143128
return false;
144129
}

esp32/hal/esp32_mphal.c

+8
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,14 @@ IRAM_ATTR uint32_t mp_hal_ticks_us(void) {
173173
return now.tv_sec * 1000000 + now.tv_usec;
174174
}
175175

176+
IRAM_ATTR uint64_t mp_hal_ticks_ms_non_blocking(void) {
177+
return esp_timer_get_time() / 1000;
178+
}
179+
180+
IRAM_ATTR uint64_t mp_hal_ticks_us_non_blocking(void) {
181+
return esp_timer_get_time();
182+
}
183+
176184
void mp_hal_delay_ms(uint32_t delay) {
177185
MP_THREAD_GIL_EXIT();
178186
vTaskDelay (delay / portTICK_PERIOD_MS);

esp32/hal/esp32_mphal.h

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ void mp_hal_stdout_tx_strn_cooked(const char *str, uint32_t len);
2323
uint32_t mp_hal_ticks_s(void);
2424
uint32_t mp_hal_ticks_ms(void);
2525
uint32_t mp_hal_ticks_us(void);
26+
uint64_t mp_hal_ticks_ms_non_blocking(void);
27+
uint64_t mp_hal_ticks_us_non_blocking(void);
2628
void mp_hal_delay_ms(uint32_t delay);
2729
void mp_hal_set_interrupt_char(int c);
2830
void mp_hal_reset_safe_and_boot(bool reset);

esp32/lib/libbootloader_support.a

-482 Bytes
Binary file not shown.

esp32/lib/libbt.a

32.4 KB
Binary file not shown.

esp32/lib/libcxx.a

368 Bytes
Binary file not shown.

esp32/lib/libdriver.a

4.82 KB
Binary file not shown.

esp32/lib/libesp32.a

6.96 KB
Binary file not shown.

esp32/lib/libesp_adc_cal.a

284 Bytes
Binary file not shown.

esp32/lib/libexpat.a

688 Bytes
Binary file not shown.

esp32/lib/libfreertos.a

2.39 KB
Binary file not shown.

esp32/lib/libheap.a

788 Bytes
Binary file not shown.

esp32/lib/libjsmn.a

68 Bytes
Binary file not shown.

esp32/lib/libjson.a

232 Bytes
Binary file not shown.

esp32/lib/liblog.a

200 Bytes
Binary file not shown.

esp32/lib/liblwip.a

12.9 KB
Binary file not shown.

esp32/lib/libmbedtls.a

7.73 KB
Binary file not shown.

esp32/lib/libmicro-ecc.a

88 Bytes
Binary file not shown.

esp32/lib/libnewlib.a

760 Bytes
Binary file not shown.

esp32/lib/libnghttp.a

2.98 KB
Binary file not shown.

esp32/lib/libnvs_flash.a

1.26 KB
Binary file not shown.

esp32/lib/libopenssl.a

1.06 KB
Binary file not shown.

esp32/lib/libpthread.a

548 Bytes
Binary file not shown.

esp32/lib/libsdmmc.a

268 Bytes
Binary file not shown.

esp32/lib/libsoc.a

932 Bytes
Binary file not shown.

esp32/lib/libspi_flash.a

888 Bytes
Binary file not shown.

esp32/lib/libtcpip_adapter.a

308 Bytes
Binary file not shown.

esp32/lib/libvfs.a

496 Bytes
Binary file not shown.

esp32/lib/libwpa_supplicant.a

4.59 KB
Binary file not shown.

esp32/lib/libxtensa-debug-module.a

244 Bytes
Binary file not shown.

esp32/main.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include "machpin.h"
5151
#include "pins.h"
5252
#include "mperror.h"
53+
#include "machtimer.h"
5354

5455

5556
TaskHandle_t mpTaskHandle;
@@ -104,6 +105,9 @@ void app_main(void) {
104105
// remove all the logs from the IDF
105106
esp_log_level_set("*", ESP_LOG_NONE);
106107

108+
// setup the timer used as a reference in mphal
109+
machtimer_preinit();
110+
107111
// this one gets the remaining sleep time
108112
machine_init0();
109113

@@ -113,7 +117,7 @@ void app_main(void) {
113117
nvs_flash_init();
114118
}
115119

116-
// Initialise heartbeat on Core0
120+
// initialise heartbeat on Core 0
117121
mperror_pre_init();
118122

119123
// differentiate the Flash Size (either 8MB or 4MB) based on ESP32 rev id

esp32/mods/machpin.c

+4
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ void pin_init0(void) {
127127
if (self == &PIN_MODULE_P17 || self == &PIN_MODULE_P18 || self == &PIN_MODULE_P19 || self == &PIN_MODULE_P20) {
128128
continue;
129129
}
130+
#elif defined (GPY)
131+
if (self == &PIN_MODULE_P5 || self == &PIN_MODULE_P6 || self == &PIN_MODULE_P7) {
132+
continue;
133+
}
130134
#endif
131135
pin_config(self, -1, -1, GPIO_MODE_INPUT, MACHPIN_PULL_DOWN, 0);
132136
}

esp32/mods/machtimer.c

+15-14
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414
#include "py/nlr.h"
1515
#include "py/runtime.h"
1616

17-
#include "mods/machtimer_alarm.h"
18-
#include "mods/machtimer_chrono.h"
19-
20-
#define CLK_FREQ (APB_CLK_FREQ / 2)
17+
#include "machtimer.h"
18+
#include "machtimer_alarm.h"
19+
#include "machtimer_chrono.h"
2120

2221
static uint64_t us_timer_calibration;
2322

@@ -38,27 +37,29 @@ void calibrate_us_timer(void) {
3837
us_timer_calibration = t2 - t1;
3938
}
4039

41-
void machtimer_init0(void) {
42-
timer_config_t config = {.alarm_en = false, .counter_en = false,
43-
.counter_dir = TIMER_COUNT_UP,
44-
.intr_type = TIMER_INTR_LEVEL,
45-
.auto_reload = false, .divider = 2};
46-
47-
mach_timer_alarm_init_heap();
40+
void machtimer_preinit(void) {
41+
timer_config_t config = { .alarm_en = false,
42+
.counter_en = false,
43+
.counter_dir = TIMER_COUNT_UP,
44+
.intr_type = TIMER_INTR_LEVEL,
45+
.auto_reload = false, .divider = 2};
4846

4947
timer_init(TIMER_GROUP_0, TIMER_0, &config);
5048
timer_set_counter_value(TIMER_GROUP_0, TIMER_0, 0);
51-
timer_enable_intr(TIMER_GROUP_0, TIMER_0);
5249
timer_start(TIMER_GROUP_0, TIMER_0);
5350
calibrate_us_timer();
5451
}
5552

53+
void machtimer_init0(void) {
54+
mach_timer_alarm_init_heap();
55+
timer_enable_intr(TIMER_GROUP_0, TIMER_0);
56+
}
57+
5658
void machtimer_deinit(void) {
57-
timer_pause(TIMER_GROUP_0, TIMER_0);
5859
timer_disable_intr(TIMER_GROUP_0, TIMER_0);
5960
}
6061

61-
uint64_t machtimer_get_timer_counter_value(void) {
62+
IRAM_ATTR uint64_t machtimer_get_timer_counter_value(void) {
6263
uint64_t t;
6364
timer_get_counter_value(TIMER_GROUP_0, TIMER_0, &t);
6465
return t;

esp32/mods/machtimer.h

+4
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@
1010
#ifndef MACHTIMER_H_
1111
#define MACHTIMER_H_
1212

13+
#define CLK_FREQ (APB_CLK_FREQ / 2)
14+
1315
extern const mp_obj_type_t mach_timer_type;
1416

1517

18+
extern void machtimer_preinit(void);
19+
1620
extern void machtimer_init0(void);
1721

1822
extern void machtimer_deinit(void);

esp32/mods/machtimer_alarm.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
#include "util/mpirq.h"
1414

1515
#include "esp_system.h"
16+
#include "machtimer.h"
1617
#include "machtimer_alarm.h"
1718

1819
/******************************************************************************
1920
DEFINE PRIVATE CONSTANTS
2021
******************************************************************************/
2122
#define ALARM_HEAP_MAX_ELEMENTS (16U)
22-
#define CLK_FREQ (APB_CLK_FREQ / 2)
2323

2424
/******************************************************************************
2525
DEFINE PRIVATE TYPES

esp32/mods/machuart.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,11 @@ void uart_init0 (void) {
111111
}
112112

113113
void uart_deinit_all (void) {
114-
for (int i = 0; i < MACH_NUM_UARTS; i++) {
114+
uint32_t num_uarts = MACH_NUM_UARTS;
115+
#if defined(GPY) || defined(FIPY)
116+
num_uarts -= 1;
117+
#endif
118+
for (int i = 0; i < num_uarts; i++) {
115119
mach_uart_deinit(&mach_uart_obj[i]);
116120
}
117121
}

esp32/mods/modpycom.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ STATIC mp_obj_t mod_pycom_heartbeat (mp_uint_t n_args, const mp_obj_t *args) {
5656
mperror_enable_heartbeat (mp_obj_is_true(args[0]));
5757
if (!mp_obj_is_true(args[0])) {
5858
do {
59-
mp_hal_delay_ms(1);
59+
mp_hal_delay_ms(2);
6060
} while (!mperror_heartbeat_disable_done());
6161
}
6262
} else {

esp32/mods/modutime.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ STATIC mp_obj_t time_ticks_us(void) {
163163
STATIC MP_DEFINE_CONST_FUN_OBJ_0(time_ticks_us_obj, time_ticks_us);
164164

165165
STATIC mp_obj_t time_ticks_cpu(void) {
166-
return mp_obj_new_int_from_uint(machtimer_get_timer_counter_value());
166+
return mp_obj_new_int_from_uint(mp_hal_ticks_us_non_blocking());
167167
}
168168
STATIC MP_DEFINE_CONST_FUN_OBJ_0(time_ticks_cpu_obj, time_ticks_cpu);
169169

esp32/mptask.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,13 @@ void TASK_Micropython (void *pvParameters) {
261261

262262
pyexec_frozen_module("_boot.py");
263263

264-
if (!safeboot) {
264+
if (!soft_reset) {
265265
#if defined(GPY) || defined (FIPY)
266266
modlte_init0();
267267
#endif
268+
}
269+
270+
if (!safeboot) {
268271
// run boot.py
269272
int ret = pyexec_file("boot.py");
270273
if (ret & PYEXEC_FORCED_EXIT) {

esp32/pycom_version.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#ifndef VERSION_H_
1111
#define VERSION_H_
1212

13-
#define SW_VERSION_NUMBER "1.17.2.b1"
13+
#define SW_VERSION_NUMBER "1.17.3.b1"
1414

1515
#define LORAWAN_VERSION_NUMBER "1.0.2"
1616

esp32/util/mperror.c

+39-18
Original file line numberDiff line numberDiff line change
@@ -68,27 +68,32 @@ led_info_t led_info = {
6868
#endif
6969

7070
struct mperror_heart_beat {
71-
uint32_t off_time;
72-
uint32_t on_time;
71+
uint64_t off_time;
72+
uint64_t on_time;
7373
bool beating;
7474
bool enabled;
7575
bool do_disable;
7676
} mperror_heart_beat;
7777

78+
static void disable_and_wait (void);
79+
7880
/******************************************************************************
7981
DEFINE PUBLIC FUNCTIONS
8082
******************************************************************************/
8183
void mperror_pre_init(void) {
84+
mperror_heart_beat.enabled = false;
8285
esp_register_freertos_idle_hook(mperror_heartbeat_signal);
8386
}
8487

8588
void mperror_init0 (void) {
8689
// configure the heartbeat led pin
8790
pin_config(&pin_GPIO0, -1, -1, GPIO_MODE_OUTPUT, MACHPIN_PULL_NONE, 0);
8891
led_init(&led_info);
89-
mperror_heart_beat.enabled = (config_get_heartbeat_on_boot()) ? true:false;
90-
mperror_heart_beat.do_disable = (config_get_heartbeat_on_boot()) ? false:true;
91-
mperror_heartbeat_switch_off();
92+
mperror_heart_beat.on_time = 0;
93+
mperror_heart_beat.off_time = 0;
94+
mperror_heart_beat.beating = false;
95+
mperror_heart_beat.enabled = (config_get_heartbeat_on_boot()) ? true : false;
96+
mperror_heart_beat.do_disable = (config_get_heartbeat_on_boot()) ? false : true;
9297
}
9398

9499
void mperror_signal_error (void) {
@@ -101,6 +106,7 @@ void mperror_signal_error (void) {
101106
} else {
102107
led_info.color.value = 0;
103108
}
109+
disable_and_wait();
104110
led_set_color(&led_info, false);
105111
toggle = ~toggle;
106112
mp_hal_delay_ms(MPERROR_TOOGLE_MS);
@@ -109,25 +115,27 @@ void mperror_signal_error (void) {
109115

110116
void mperror_heartbeat_switch_off (void) {
111117
if (mperror_heart_beat.enabled) {
112-
mperror_heart_beat.on_time = 0;
113-
mperror_heart_beat.off_time = 0;
114118
led_info.color.value = 0;
119+
disable_and_wait();
115120
led_set_color(&led_info, false);
116121
}
122+
mperror_heart_beat.on_time = 0;
123+
mperror_heart_beat.off_time = 0;
124+
mperror_heart_beat.beating = false;
117125
}
118126

119127
bool mperror_heartbeat_signal (void) {
120128
if (mperror_heart_beat.do_disable) {
121129
mperror_heart_beat.do_disable = false;
122130
} else if (mperror_heart_beat.enabled) {
123131
if (!mperror_heart_beat.beating) {
124-
if ((mperror_heart_beat.on_time = mp_hal_ticks_ms()) - mperror_heart_beat.off_time > MPERROR_HEARTBEAT_OFF_MS) {
132+
if ((mperror_heart_beat.on_time = mp_hal_ticks_ms_non_blocking()) - mperror_heart_beat.off_time > MPERROR_HEARTBEAT_OFF_MS) {
125133
led_info.color.value = MPERROR_HEARTBEAT_COLOR;
126134
led_set_color(&led_info, false);
127135
mperror_heart_beat.beating = true;
128136
}
129137
} else {
130-
if ((mperror_heart_beat.off_time = mp_hal_ticks_ms()) - mperror_heart_beat.on_time > MPERROR_HEARTBEAT_ON_MS) {
138+
if ((mperror_heart_beat.off_time = mp_hal_ticks_ms_non_blocking()) - mperror_heart_beat.on_time > MPERROR_HEARTBEAT_ON_MS) {
131139
led_info.color.value = 0;
132140
led_set_color(&led_info, false);
133141
mperror_heart_beat.beating = false;
@@ -173,20 +181,21 @@ void nlr_jump_fail(void *val) {
173181
#endif
174182

175183
void mperror_enable_heartbeat (bool enable) {
176-
if (enable) {
184+
if (enable && !mperror_heart_beat.enabled) {
185+
mperror_heart_beat.enabled = true;
186+
mperror_heart_beat.do_disable = false;
187+
mperror_heart_beat.on_time = 0;
188+
mperror_heart_beat.off_time = 0;
189+
mperror_heart_beat.beating = false;
177190
led_info.color.value = MPERROR_HEARTBEAT_COLOR;
178191
pin_config(&pin_GPIO0, -1, -1, GPIO_MODE_OUTPUT, MACHPIN_PULL_NONE, 0);
179192
led_init(&led_info);
180-
mperror_heart_beat.enabled = true;
181-
mperror_heart_beat.do_disable = false;
182-
mperror_heartbeat_switch_off();
183-
//mperror_init0();
184-
} else {
193+
led_set_color(&led_info, false);
194+
} else if (!enable) {
185195
led_info.color.value = 0;
186-
mperror_heart_beat.do_disable = true;
187-
mperror_heart_beat.enabled = false;
196+
disable_and_wait();
197+
led_set_color(&led_info, false);
188198
}
189-
led_set_color(&led_info, false);
190199
}
191200

192201
bool mperror_is_heartbeat_enabled (void) {
@@ -196,3 +205,15 @@ bool mperror_is_heartbeat_enabled (void) {
196205
bool mperror_heartbeat_disable_done (void) {
197206
return mperror_heart_beat.do_disable == false;
198207
}
208+
209+
/******************************************************************************
210+
DEFINE PRIVATE FUNCTIONS
211+
******************************************************************************/
212+
213+
static void disable_and_wait (void) {
214+
mperror_heart_beat.enabled = false;
215+
mperror_heart_beat.do_disable = true;
216+
while (!mperror_heartbeat_disable_done()) {
217+
mp_hal_delay_ms(2);
218+
}
219+
}

0 commit comments

Comments
 (0)