Skip to content

Commit 06e8597

Browse files
authored
Merge branch 'micropython:master' into samd_i2c
2 parents e9ce66f + d34b15a commit 06e8597

File tree

10 files changed

+55
-52
lines changed

10 files changed

+55
-52
lines changed

ports/esp32/CMakeLists.txt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Top-level cmake file for building MicroPython on ESP32.
2-
2+
#
3+
# Note for maintainers: Where possible, functionality should be put into
4+
# esp32_common.cmake not this file. This is because this CMakeLists.txt file
5+
# needs to be duplicated for out-of-tree builds, and can easily get out of date.
36
cmake_minimum_required(VERSION 3.12)
47

58
# Retrieve IDF version
@@ -71,12 +74,5 @@ include($ENV{IDF_PATH}/tools/cmake/project.cmake)
7174
# Set the location of the main component for the project (one per target).
7275
list(APPEND EXTRA_COMPONENT_DIRS main_${IDF_TARGET})
7376

74-
# Enable the panic handler wrapper
75-
idf_build_set_property(LINK_OPTIONS "-Wl,--wrap=esp_panic_handler" APPEND)
76-
77-
# Patch LWIP memory pool allocators (see lwip_patch.c)
78-
idf_build_set_property(LINK_OPTIONS "-Wl,--wrap=memp_malloc" APPEND)
79-
idf_build_set_property(LINK_OPTIONS "-Wl,--wrap=memp_free" APPEND)
80-
8177
# Define the project.
8278
project(micropython)

ports/esp32/esp32_common.cmake

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# This is the common ESP-IDF "main component" CMakeLists.txt contents for MicroPython.
2+
#
3+
# This file is included directly from a main_${IDF_TARGET}/CMakeLists.txt file
4+
# (or included from an out-of-tree main component CMakeLists.txt for out-of-tree
5+
# builds.)
6+
17
# Set location of base MicroPython directory.
28
if(NOT MICROPY_DIR)
39
get_filename_component(MICROPY_DIR ${CMAKE_CURRENT_LIST_DIR}/../.. ABSOLUTE)
@@ -236,6 +242,13 @@ target_include_directories(${MICROPY_TARGET} PUBLIC
236242
target_link_libraries(${MICROPY_TARGET} micropy_extmod_btree)
237243
target_link_libraries(${MICROPY_TARGET} usermod)
238244

245+
# Enable the panic handler wrapper
246+
idf_build_set_property(LINK_OPTIONS "-Wl,--wrap=esp_panic_handler" APPEND)
247+
248+
# Patch LWIP memory pool allocators (see lwip_patch.c)
249+
idf_build_set_property(LINK_OPTIONS "-Wl,--wrap=memp_malloc" APPEND)
250+
idf_build_set_property(LINK_OPTIONS "-Wl,--wrap=memp_free" APPEND)
251+
239252
# Collect all of the include directories and compile definitions for the IDF components,
240253
# including those added by the IDF Component Manager via idf_components.yaml.
241254
foreach(comp ${__COMPONENT_NAMES_RESOLVED})

ports/esp32/machine_hw_spi.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ static void machine_hw_spi_init_internal(machine_hw_spi_obj_t *self, mp_arg_val_
196196
changed = true;
197197
}
198198

199+
if (args[ARG_bits].u_int != -1 && args[ARG_bits].u_int <= 0) {
200+
mp_raise_ValueError(MP_ERROR_TEXT("invalid bits"));
201+
}
202+
199203
if (args[ARG_bits].u_int != -1 && args[ARG_bits].u_int != self->bits) {
200204
self->bits = args[ARG_bits].u_int;
201205
changed = true;

ports/esp32/machine_pwm.c

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "py/mphal.h"
3535
#include "driver/ledc.h"
3636
#include "esp_err.h"
37+
#include "esp_clk_tree.h"
3738
#include "soc/gpio_sig_map.h"
3839

3940
#define PWM_DBG(...)
@@ -209,51 +210,32 @@ static void configure_channel(machine_pwm_obj_t *self) {
209210

210211
static void set_freq(machine_pwm_obj_t *self, unsigned int freq, ledc_timer_config_t *timer) {
211212
if (freq != timer->freq_hz) {
212-
// Find the highest bit resolution for the requested frequency
213-
unsigned int i = APB_CLK_FREQ; // 80 MHz
214-
#if SOC_LEDC_SUPPORT_REF_TICK
215-
if (freq < EMPIRIC_FREQ) {
216-
i = REF_CLK_FREQ; // 1 MHz
217-
}
218-
#endif
219-
220-
int divider = (i + freq / 2) / freq; // rounded
221-
if (divider == 0) {
222-
divider = 1;
223-
}
224-
float f = (float)i / divider; // actual frequency
225-
if (f <= 1.0) {
226-
f = 1.0;
227-
}
228-
i = (unsigned int)roundf((float)i / f);
229-
230-
unsigned int res = 0;
231-
for (; i > 1; i >>= 1) {
232-
++res;
233-
}
234-
if (res == 0) {
235-
res = 1;
236-
} else if (res > HIGHEST_PWM_RES) {
237-
// Limit resolution to HIGHEST_PWM_RES to match units of our duty
238-
res = HIGHEST_PWM_RES;
239-
}
240-
241-
// Configure the new resolution and frequency
242-
timer->duty_resolution = res;
213+
// Configure the new frequency and resolution
243214
timer->freq_hz = freq;
244-
#if SOC_LEDC_SUPPORT_XTAL_CLOCK
215+
216+
#if SOC_LEDC_SUPPORT_PLL_DIV_CLOCK
217+
timer->clk_cfg = LEDC_USE_PLL_DIV_CLK;
218+
#elif SOC_LEDC_SUPPORT_APB_CLOCK
219+
timer->clk_cfg = LEDC_USE_APB_CLK;
220+
#elif SOC_LEDC_SUPPORT_XTAL_CLOCK
245221
timer->clk_cfg = LEDC_USE_XTAL_CLK;
246222
#else
247-
timer->clk_cfg = LEDC_USE_APB_CLK;
223+
#error No supported PWM / LEDC clocks.
248224
#endif
249225
#if SOC_LEDC_SUPPORT_REF_TICK
250226
if (freq < EMPIRIC_FREQ) {
251227
timer->clk_cfg = LEDC_USE_REF_TICK;
252228
}
253229
#endif
230+
uint32_t src_clk_freq = 0;
231+
esp_err_t err = esp_clk_tree_src_get_freq_hz(timer->clk_cfg, ESP_CLK_TREE_SRC_FREQ_PRECISION_CACHED, &src_clk_freq);
232+
if (err != ESP_OK) {
233+
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("unable to query source clock frequency %d"), (int)timer->clk_cfg);
234+
}
235+
timer->duty_resolution = ledc_find_suitable_duty_resolution(src_clk_freq, timer->freq_hz);
254236

255237
// Set frequency
256-
esp_err_t err = ledc_timer_config(timer);
238+
err = ledc_timer_config(timer);
257239
if (err != ESP_OK) {
258240
if (err == ESP_FAIL) {
259241
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("unreachable frequency %d"), freq);

ports/pic16bit/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ QSTR_DEFS = qstrdefsport.h
77
include $(TOP)/py/py.mk
88
include $(TOP)/extmod/extmod.mk
99

10-
XCVERSION ?= 1.35
10+
XCVERSION ?= 2.10
1111
XC16 ?= /opt/microchip/xc16/v$(XCVERSION)
1212
CROSS_COMPILE ?= $(XC16)/bin/xc16-
1313

@@ -31,7 +31,7 @@ CFLAGS += -O1 -DNDEBUG
3131
endif
3232

3333
LDFLAGS += --heap=0 -nostdlib -T $(XC16)/support/$(PARTFAMILY)/gld/p$(PART).gld -Map=$@.map --cref -p$(PART)
34-
LIBS += -L$(XC16)/lib -L$(XC16)/lib/$(PARTFAMILY) -lc -lm -lpic30
34+
LIBS += -L$(XC16)/lib -L$(XC16)/lib/$(PARTFAMILY) -lc99-elf -lm-elf -lc99-pic30-elf
3535

3636
SRC_C = \
3737
main.c \

ports/pic16bit/mpconfigport.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,3 @@ typedef int mp_off_t;
9393
#define MICROPY_MPHALPORT_H "pic16bit_mphal.h"
9494
#define MICROPY_HW_BOARD_NAME "dsPICSK"
9595
#define MICROPY_HW_MCU_NAME "dsPIC33"
96-
97-
// XC16 toolchain doesn't seem to define these
98-
typedef int intptr_t;
99-
typedef unsigned int uintptr_t;

ports/rp2/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ from machine import Pin, Timer
6969
led = Pin(25, Pin.OUT)
7070
tim = Timer()
7171
def tick(timer):
72-
global led
7372
led.toggle()
7473

7574
tim.init(freq=2.5, mode=Timer.PERIODIC, callback=tick)

py/misc.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,18 @@ static inline bool mp_check(bool value) {
380380

381381
// mp_int_t can be larger than long, i.e. Windows 64-bit, nan-box variants
382382
static inline uint32_t mp_clz_mpi(mp_int_t x) {
383+
#ifdef __XC16__
384+
mp_uint_t mask = MP_OBJ_WORD_MSBIT_HIGH;
385+
mp_uint_t zeroes = 0;
386+
while (mask != 0) {
387+
if (mask & (mp_uint_t)x) {
388+
break;
389+
}
390+
zeroes++;
391+
mask >>= 1;
392+
}
393+
return zeroes;
394+
#else
383395
MP_STATIC_ASSERT(sizeof(mp_int_t) == sizeof(long long)
384396
|| sizeof(mp_int_t) == sizeof(long));
385397

@@ -389,6 +401,7 @@ static inline uint32_t mp_clz_mpi(mp_int_t x) {
389401
} else {
390402
return mp_clzll((unsigned long long)x);
391403
}
404+
#endif
392405
}
393406

394407
#endif // MICROPY_INCLUDED_PY_MISC_H

py/mpconfig.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
// as well as a fallback to generate MICROPY_GIT_TAG if the git repo or tags
3131
// are unavailable.
3232
#define MICROPY_VERSION_MAJOR 1
33-
#define MICROPY_VERSION_MINOR 24
33+
#define MICROPY_VERSION_MINOR 25
3434
#define MICROPY_VERSION_MICRO 0
35-
#define MICROPY_VERSION_PRERELEASE 0
35+
#define MICROPY_VERSION_PRERELEASE 1
3636

3737
// Combined version as a 32-bit number for convenience to allow version
3838
// comparison. Doesn't include prerelease state.

tools/mpremote/mpremote/transport.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ def fs_writefile(self, dest, data, chunk_size=256, progress_callback=None):
151151
while data:
152152
chunk = data[:chunk_size]
153153
self.exec("w(" + repr(chunk) + ")")
154-
written += len(chunk)
155154
data = data[len(chunk) :]
156155
if progress_callback:
156+
written += len(chunk)
157157
progress_callback(written, src_size)
158158
self.exec("f.close()")
159159
except TransportExecError as e:

0 commit comments

Comments
 (0)