From 2be45dd682f0ce01e4a1061375e96ce2c501a187 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Sat, 6 Jul 2024 09:18:22 +0200 Subject: [PATCH] extmod/modmachine: Allow more than one argument to machine.freq(). The limit is set by a `MICROPY_PY_MACHINE_FREQ_NUM_ARGS_MAX` define, which defaults to 1 and is set for stm32 to 4. For stm32 this fixes a regression introduced in commit e1ec6af654b1c5c4a973b6c6b029ee68bb92eb89 where the maximum number of arguments was changed from 4 to 1. Signed-off-by: robert-hh --- extmod/modmachine.c | 2 +- ports/stm32/mpconfigport.h | 1 + py/mpconfig.h | 5 +++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/extmod/modmachine.c b/extmod/modmachine.c index 2a7e315bbb..2fe72817b6 100644 --- a/extmod/modmachine.c +++ b/extmod/modmachine.c @@ -109,7 +109,7 @@ static mp_obj_t machine_freq(size_t n_args, const mp_obj_t *args) { return mp_const_none; } } -MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_freq_obj, 0, 1, machine_freq); +MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_freq_obj, 0, MICROPY_PY_MACHINE_FREQ_NUM_ARGS_MAX, machine_freq); static mp_obj_t machine_lightsleep(size_t n_args, const mp_obj_t *args) { mp_machine_lightsleep(n_args, args); diff --git a/ports/stm32/mpconfigport.h b/ports/stm32/mpconfigport.h index 9e1e24cf23..bd1ab671e0 100644 --- a/ports/stm32/mpconfigport.h +++ b/ports/stm32/mpconfigport.h @@ -113,6 +113,7 @@ #define MICROPY_PY_MACHINE_INCLUDEFILE "ports/stm32/modmachine.c" #define MICROPY_PY_MACHINE_RESET (1) #define MICROPY_PY_MACHINE_BARE_METAL_FUNCS (1) +#define MICROPY_PY_MACHINE_FREQ_NUM_ARGS_MAX (4) #define MICROPY_PY_MACHINE_BOOTLOADER (1) #define MICROPY_PY_MACHINE_ADC (1) #define MICROPY_PY_MACHINE_ADC_INCLUDEFILE "ports/stm32/machine_adc.c" diff --git a/py/mpconfig.h b/py/mpconfig.h index bc6bf75fe5..346d0c21e1 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -1736,6 +1736,11 @@ typedef double mp_float_t; #define MICROPY_PY_MACHINE_RESET (0) #endif +// Maximum number of arguments for machine.freq() +#ifndef MICROPY_PY_MACHINE_FREQ_NUM_ARGS_MAX +#define MICROPY_PY_MACHINE_FREQ_NUM_ARGS_MAX (1) +#endif + // Whether to include: bitstream #ifndef MICROPY_PY_MACHINE_BITSTREAM #define MICROPY_PY_MACHINE_BITSTREAM (0)