Skip to content

Commit e9ce66f

Browse files
authored
Merge branch 'micropython:master' into samd_i2c
2 parents b01a360 + f212bbe commit e9ce66f

File tree

181 files changed

+3188
-873
lines changed

Some content is hidden

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

181 files changed

+3188
-873
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ track of the code size of the core runtime and VM.
108108

109109
In addition, the following ports are provided in this repository:
110110
- [cc3200](ports/cc3200) -- Texas Instruments CC3200 (including PyCom WiPy).
111-
- [esp32](ports/esp32) -- Espressif ESP32 SoC (including ESP32S2, ESP32S3, ESP32C3).
111+
- [esp32](ports/esp32) -- Espressif ESP32 SoC (including ESP32S2, ESP32S3, ESP32C3, ESP32C6).
112112
- [esp8266](ports/esp8266) -- Espressif ESP8266 SoC.
113113
- [mimxrt](ports/mimxrt) -- NXP m.iMX RT (including Teensy 4.x).
114114
- [nrf](ports/nrf) -- Nordic Semiconductor nRF51 and nRF52.

docs/esp32/quickref.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ working with this board it may be useful to get an overview of the microcontroll
1818
general.rst
1919
tutorial/index.rst
2020

21-
Note that there are several varieties of ESP32 -- ESP32, ESP32C3, ESP32S2, ESP32S3 --
21+
Note that there are several varieties of ESP32 -- ESP32, ESP32C3, ESP32C6, ESP32S2, ESP32S3 --
2222
supported by MicroPython, with some differences in functionality between them.
2323

2424
Installing MicroPython
@@ -61,13 +61,13 @@ The :mod:`esp32` module::
6161
import esp32
6262

6363
esp32.raw_temperature() # read the internal temperature of the MCU, in Fahrenheit
64-
esp32.ULP() # access to the Ultra-Low-Power Co-processor, not on ESP32C3
64+
esp32.ULP() # access to the Ultra-Low-Power Co-processor, not on ESP32C3/C6
6565

6666
Note that the temperature sensor in the ESP32 will typically read higher than
6767
ambient due to the IC getting warm while it runs. This effect can be minimised
6868
by reading the temperature sensor immediately after waking up from sleep.
6969

70-
ESP32C3, ESP32S2, and ESP32S3 also have an internal temperature sensor available.
70+
ESP32C3, ESP32C6, ESP32S2, and ESP32S3 also have an internal temperature sensor available.
7171
It is implemented a bit differently to the ESP32 and returns the temperature in
7272
Celsius::
7373

docs/library/machine.UART.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ Methods
160160

161161
.. note::
162162

163-
For the rp2, esp8266 and nrf ports the call returns while the last byte is sent.
163+
For the esp8266 and nrf ports the call returns while the last byte is sent.
164164
If required, a one character wait time has to be added in the calling script.
165165

166166
Availability: rp2, esp32, esp8266, mimxrt, cc3200, stm32, nrf ports, renesas-ra
@@ -172,7 +172,7 @@ Methods
172172

173173
.. note::
174174

175-
For the rp2, esp8266 and nrf ports the call may return ``True`` even if the last byte
175+
For the esp8266 and nrf ports the call may return ``True`` even if the last byte
176176
of a transfer is still being sent. If required, a one character wait time has to be
177177
added in the calling script.
178178

docs/library/rp2.PIO.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ Constructors
2727
Methods
2828
-------
2929

30+
.. method:: PIO.gpio_base([base])
31+
32+
Query and optionally set the current GPIO base for this PIO instance.
33+
34+
If an argument is given then it must be a pin (or integer corresponding to a pin
35+
number), restricted to either GPIO0 or GPIO16. The GPIO base will then be set to
36+
that pin. Setting the GPIO base must be done before any programs are added or state
37+
machines created.
38+
39+
Returns the current GPIO base pin.
40+
3041
.. method:: PIO.add_program(program)
3142

3243
Add the *program* to the instruction memory of this PIO instance.

docs/reference/mpremote.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,12 @@ The full list of supported commands are:
227227
- ``cat <file..>`` to show the contents of a file or files on the device
228228
- ``ls`` to list the current directory
229229
- ``ls <dirs...>`` to list the given directories
230-
- ``cp [-r] <src...> <dest>`` to copy files
230+
- ``cp [-rf] <src...> <dest>`` to copy files
231231
- ``rm <src...>`` to remove files on the device
232232
- ``mkdir <dirs...>`` to create directories on the device
233233
- ``rmdir <dirs...>`` to remove directories on the device
234234
- ``touch <file..>`` to create the files (if they don't already exist)
235+
- ``sha256sum <file..>`` to calculate the SHA256 sum of files
235236

236237
The ``cp`` command uses a convention where a leading ``:`` represents a remote
237238
path. Without a leading ``:`` means a local path. This is based on the
@@ -256,6 +257,11 @@ The full list of supported commands are:
256257
This will copy the file to the device then enter the REPL. The ``+`` prevents
257258
``"repl"`` being interpreted as a path.
258259

260+
The ``cp`` command supports the ``-r`` option to make a recursive copy. By
261+
default ``cp`` will skip copying files to the remote device if the SHA256 hash
262+
of the source and destination file matches. To force a copy regardless of the
263+
hash use the ``-f`` option.
264+
259265
**Note:** For convenience, all of the filesystem sub-commands are also
260266
:ref:`aliased as regular commands <mpremote_shortcuts>`, i.e. you can write
261267
``mpremote cp ...`` instead of ``mpremote fs cp ...``.

extmod/extmod.mk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ SRC_EXTMOD_C += \
4242
extmod/modsocket.c \
4343
extmod/modtls_axtls.c \
4444
extmod/modtls_mbedtls.c \
45+
extmod/mbedtls/mbedtls_alt.c \
4546
extmod/modtime.c \
4647
extmod/moductypes.c \
4748
extmod/modvfs.c \
@@ -242,6 +243,10 @@ MBEDTLS_CONFIG_FILE ?= \"mbedtls/mbedtls_config_port.h\"
242243
GIT_SUBMODULES += $(MBEDTLS_DIR)
243244
CFLAGS_EXTMOD += -DMBEDTLS_CONFIG_FILE=$(MBEDTLS_CONFIG_FILE)
244245
CFLAGS_EXTMOD += -DMICROPY_SSL_MBEDTLS=1 -I$(TOP)/$(MBEDTLS_DIR)/include
246+
ifeq ($(MICROPY_PY_SSL_ECDSA_SIGN_ALT),1)
247+
CFLAGS_EXTMOD += -DMICROPY_PY_SSL_ECDSA_SIGN_ALT=1
248+
LDFLAGS_EXTMOD += -Wl,--wrap=mbedtls_ecdsa_write_signature
249+
endif
245250
SRC_THIRDPARTY_C += lib/mbedtls_errors/mp_mbedtls_errors.c
246251
SRC_THIRDPARTY_C += $(addprefix $(MBEDTLS_DIR)/library/,\
247252
aes.c \

extmod/mbedtls/mbedtls_alt.c

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Copyright The Mbed TLS Contributors
7+
* Copyright (c) 2024 Damien P. George
8+
*
9+
* This file provides default fallback functions for use with alternate
10+
* cryptography functions implemented in Python.
11+
*/
12+
#if MICROPY_PY_SSL_ECDSA_SIGN_ALT
13+
#if defined(MBEDTLS_ECP_RESTARTABLE) || defined(MBEDTLS_ECDSA_DETERMINISTIC)
14+
#error "MICROPY_PY_SSL_ECDSA_SIGN_ALT cannot be used with MBEDTLS_ECP_RESTARTABLE or MBEDTLS_ECDSA_DETERMINISTIC"
15+
#endif
16+
17+
#include <string.h>
18+
#define MBEDTLS_ALLOW_PRIVATE_ACCESS
19+
#include "mbedtls/platform.h"
20+
#include "mbedtls/ssl.h"
21+
#include "mbedtls/error.h"
22+
#include "mbedtls/ecdsa.h"
23+
#include "mbedtls/asn1write.h"
24+
25+
extern int micropy_mbedtls_ecdsa_sign_alt(const mbedtls_mpi *d, const unsigned char *hash, size_t hlen,
26+
unsigned char *sig, size_t sig_size, size_t *slen);
27+
28+
29+
// Compute and write signature
30+
// See lib/mbedtls/library/ecdsa.c:688
31+
//
32+
// Note: To avoid duplicating a lot of code, MBEDTLS_ECDSA_SIGN_ALT is not defined,
33+
// which allows the default mbedtls_ecdsa_sign to be used as a fallback function.
34+
// However, mbedtls_ecdsa_sign cannot be wrapped because it is called internally
35+
// within its object file, so we wrap mbedtls_ecdsa_read/write_signature instead.
36+
int __wrap_mbedtls_ecdsa_write_signature(mbedtls_ecdsa_context *ctx,
37+
mbedtls_md_type_t md_alg,
38+
const unsigned char *hash, size_t hlen,
39+
unsigned char *sig, size_t sig_size, size_t *slen,
40+
int (*f_rng)(void *, unsigned char *, size_t),
41+
void *p_rng) {
42+
43+
(void)md_alg;
44+
45+
if (f_rng == NULL) {
46+
return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
47+
}
48+
49+
// Check if curve is supported for ECDSA.
50+
if (!mbedtls_ecdsa_can_do(ctx->grp.id) || ctx->grp.N.p == NULL) {
51+
return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
52+
}
53+
54+
// Try signing with the alternative function first.
55+
int ret = micropy_mbedtls_ecdsa_sign_alt(&ctx->d, hash, hlen, sig, sig_size, slen);
56+
57+
// Fallback to the default mbedtls implementation if needed.
58+
if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED) {
59+
mbedtls_mpi r, s;
60+
mbedtls_mpi_init(&r);
61+
mbedtls_mpi_init(&s);
62+
63+
size_t len = 0;
64+
unsigned char buf[MBEDTLS_ECDSA_MAX_LEN] = { 0 };
65+
unsigned char *p = buf + sizeof(buf);
66+
67+
MBEDTLS_MPI_CHK(mbedtls_ecdsa_sign(&ctx->grp, &r, &s, &ctx->d, hash, hlen, f_rng, p_rng));
68+
MBEDTLS_ASN1_CHK_CLEANUP_ADD(len, mbedtls_asn1_write_mpi(&p, buf, &s));
69+
MBEDTLS_ASN1_CHK_CLEANUP_ADD(len, mbedtls_asn1_write_mpi(&p, buf, &r));
70+
MBEDTLS_ASN1_CHK_CLEANUP_ADD(len, mbedtls_asn1_write_len(&p, buf, len));
71+
MBEDTLS_ASN1_CHK_CLEANUP_ADD(len, mbedtls_asn1_write_tag(&p, buf, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE));
72+
73+
if (len > sig_size) {
74+
ret = MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL;
75+
} else {
76+
ret = 0;
77+
*slen = len;
78+
memcpy(sig, p, len);
79+
}
80+
81+
cleanup:
82+
mbedtls_mpi_free(&r);
83+
mbedtls_mpi_free(&s);
84+
}
85+
86+
return ret;
87+
}
88+
#endif

extmod/modframebuf.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,23 +282,29 @@ static mp_obj_t framebuf_make_new(const mp_obj_type_t *type, size_t n_args, size
282282
mp_raise_ValueError(NULL);
283283
}
284284

285-
size_t height_required = height;
286285
size_t bpp = 1;
286+
size_t height_required = height;
287+
size_t width_required = width;
288+
size_t strides_required = height - 1;
287289

288290
switch (format) {
289291
case FRAMEBUF_MVLSB:
290292
height_required = (height + 7) & ~7;
293+
strides_required = height_required - 8;
291294
break;
292295
case FRAMEBUF_MHLSB:
293296
case FRAMEBUF_MHMSB:
294297
stride = (stride + 7) & ~7;
298+
width_required = (width + 7) & ~7;
295299
break;
296300
case FRAMEBUF_GS2_HMSB:
297301
stride = (stride + 3) & ~3;
302+
width_required = (width + 3) & ~3;
298303
bpp = 2;
299304
break;
300305
case FRAMEBUF_GS4_HMSB:
301306
stride = (stride + 1) & ~1;
307+
width_required = (width + 1) & ~1;
302308
bpp = 4;
303309
break;
304310
case FRAMEBUF_GS8:
@@ -314,7 +320,7 @@ static mp_obj_t framebuf_make_new(const mp_obj_type_t *type, size_t n_args, size
314320
mp_buffer_info_t bufinfo;
315321
mp_get_buffer_raise(args_in[0], &bufinfo, MP_BUFFER_WRITE);
316322

317-
if (height_required * stride * bpp / 8 > bufinfo.len) {
323+
if ((strides_required * stride + (height_required - strides_required) * width_required) * bpp / 8 > bufinfo.len) {
318324
mp_raise_ValueError(NULL);
319325
}
320326

0 commit comments

Comments
 (0)