Browse Source

extmod/modmachine: Provide common Python bindings for bootloader().

Signed-off-by: Damien George <damien@micropython.org>
pull/13045/head
Damien George 12 months ago
parent
commit
48b5a7b060
  1. 14
      extmod/modmachine.c
  2. 2
      extmod/modmachine.h
  3. 4
      ports/esp32/modmachine.c
  4. 1
      ports/esp32/modmachine.h
  5. 1
      ports/esp32/mpconfigport.h
  6. 4
      ports/mimxrt/modmachine.c
  7. 1
      ports/mimxrt/mpconfigport.h
  8. 4
      ports/nrf/modules/machine/modmachine.c
  9. 1
      ports/nrf/modules/machine/modmachine.h
  10. 4
      ports/renesas-ra/modmachine.c
  11. 1
      ports/renesas-ra/modmachine.h
  12. 1
      ports/renesas-ra/mpconfigport.h
  13. 4
      ports/rp2/modmachine.c
  14. 1
      ports/rp2/modmachine.h
  15. 1
      ports/rp2/mpconfigport.h
  16. 4
      ports/samd/modmachine.c
  17. 2
      ports/samd/modmachine.h
  18. 1
      ports/samd/mpconfigport.h
  19. 4
      ports/stm32/modmachine.c
  20. 2
      ports/stm32/modmachine.h
  21. 1
      ports/stm32/mpconfigport.h
  22. 2
      shared/tinyusb/mp_cdc_common.c

14
extmod/modmachine.c

@ -39,6 +39,10 @@
STATIC void mp_machine_idle(void);
#if MICROPY_PY_MACHINE_BOOTLOADER
NORETURN void mp_machine_bootloader(size_t n_args, const mp_obj_t *args);
#endif
// The port can provide additional machine-module implementation in this file.
#ifdef MICROPY_PY_MACHINE_INCLUDEFILE
#include MICROPY_PY_MACHINE_INCLUDEFILE
@ -50,6 +54,13 @@ STATIC mp_obj_t machine_soft_reset(void) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_soft_reset_obj, machine_soft_reset);
#if MICROPY_PY_MACHINE_BOOTLOADER
NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args) {
mp_machine_bootloader(n_args, args);
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_bootloader_obj, 0, 1, machine_bootloader);
#endif
STATIC mp_obj_t machine_idle(void) {
mp_machine_idle();
return mp_const_none;
@ -66,6 +77,9 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
// Reset related functions.
{ MP_ROM_QSTR(MP_QSTR_soft_reset), MP_ROM_PTR(&machine_soft_reset_obj) },
#if MICROPY_PY_MACHINE_BOOTLOADER
{ MP_ROM_QSTR(MP_QSTR_bootloader), MP_ROM_PTR(&machine_bootloader_obj) },
#endif
// Power related functions.
{ MP_ROM_QSTR(MP_QSTR_idle), MP_ROM_PTR(&machine_idle_obj) },

2
extmod/modmachine.h

@ -237,9 +237,11 @@ uintptr_t MICROPY_MACHINE_MEM_GET_READ_ADDR(mp_obj_t addr_o, uint align);
uintptr_t MICROPY_MACHINE_MEM_GET_WRITE_ADDR(mp_obj_t addr_o, uint align);
#endif
NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args);
void machine_bitstream_high_low(mp_hal_pin_obj_t pin, uint32_t *timing_ns, const uint8_t *buf, size_t len);
mp_uint_t machine_time_pulse_us(mp_hal_pin_obj_t pin, int pulse_level, mp_uint_t timeout_us);
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_bootloader_obj);
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_bitstream_obj);
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_time_pulse_us_obj);

4
ports/esp32/modmachine.c

@ -58,7 +58,6 @@
{ MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&machine_lightsleep_obj) }, \
{ MP_ROM_QSTR(MP_QSTR_lightsleep), MP_ROM_PTR(&machine_lightsleep_obj) }, \
{ MP_ROM_QSTR(MP_QSTR_deepsleep), MP_ROM_PTR(&machine_deepsleep_obj) }, \
{ MP_ROM_QSTR(MP_QSTR_bootloader), MP_ROM_PTR(&machine_bootloader_obj) }, \
\
{ MP_ROM_QSTR(MP_QSTR_disable_irq), MP_ROM_PTR(&machine_disable_irq_obj) }, \
{ MP_ROM_QSTR(MP_QSTR_enable_irq), MP_ROM_PTR(&machine_enable_irq_obj) }, \
@ -248,12 +247,11 @@ STATIC mp_obj_t machine_reset_cause(size_t n_args, const mp_obj_t *pos_args, mp_
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_reset_cause_obj, 0, machine_reset_cause);
NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args) {
NORETURN void mp_machine_bootloader(size_t n_args, const mp_obj_t *args) {
MICROPY_BOARD_ENTER_BOOTLOADER(n_args, args);
for (;;) {
}
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_bootloader_obj, 0, 1, machine_bootloader);
void machine_init(void) {
is_soft_reset = 0;

1
ports/esp32/modmachine.h

@ -21,6 +21,5 @@ void machine_pwm_deinit_all(void);
// TODO: void machine_rmt_deinit_all(void);
void machine_timer_deinit_all(void);
void machine_i2s_init0();
NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args);
#endif // MICROPY_INCLUDED_ESP32_MODMACHINE_H

1
ports/esp32/mpconfigport.h

@ -97,6 +97,7 @@
#define MICROPY_PY_OS_URANDOM (1)
#define MICROPY_PY_MACHINE (1)
#define MICROPY_PY_MACHINE_INCLUDEFILE "ports/esp32/modmachine.c"
#define MICROPY_PY_MACHINE_BOOTLOADER (1)
#define MICROPY_PY_MACHINE_ADC (1)
#define MICROPY_PY_MACHINE_ADC_INCLUDEFILE "ports/esp32/machine_adc.c"
#define MICROPY_PY_MACHINE_ADC_ATTEN_WIDTH (1)

4
ports/mimxrt/modmachine.c

@ -71,7 +71,6 @@
\
{ MP_ROM_QSTR(MP_QSTR_disable_irq), MP_ROM_PTR(&machine_disable_irq_obj) }, \
{ MP_ROM_QSTR(MP_QSTR_enable_irq), MP_ROM_PTR(&machine_enable_irq_obj) }, \
{ MP_ROM_QSTR(MP_QSTR_bootloader), MP_ROM_PTR(&machine_bootloader_obj) }, \
\
/* Reset reasons */ \
{ MP_ROM_QSTR(MP_QSTR_PWRON_RESET), MP_ROM_INT(MP_PWRON_RESET) }, \
@ -174,7 +173,7 @@ STATIC mp_obj_t machine_enable_irq(mp_obj_t state_in) {
}
MP_DEFINE_CONST_FUN_OBJ_1(machine_enable_irq_obj, machine_enable_irq);
NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args) {
NORETURN void mp_machine_bootloader(size_t n_args, const mp_obj_t *args) {
#if defined(MICROPY_BOARD_ENTER_BOOTLOADER)
// If a board has a custom bootloader, call it first.
MICROPY_BOARD_ENTER_BOOTLOADER(n_args, args);
@ -190,4 +189,3 @@ NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args) {
;
}
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_bootloader_obj, 0, 1, machine_bootloader);

1
ports/mimxrt/mpconfigport.h

@ -79,6 +79,7 @@ uint32_t trng_random_u32(void);
#define MICROPY_PY_RANDOM_SEED_INIT_FUNC (trng_random_u32())
#define MICROPY_PY_MACHINE (1)
#define MICROPY_PY_MACHINE_INCLUDEFILE "ports/mimxrt/modmachine.c"
#define MICROPY_PY_MACHINE_BOOTLOADER (1)
#define MICROPY_PY_MACHINE_ADC (1)
#define MICROPY_PY_MACHINE_ADC_INCLUDEFILE "ports/mimxrt/machine_adc.c"
#define MICROPY_PY_MACHINE_PIN_MAKE_NEW mp_pin_make_new

4
ports/nrf/modules/machine/modmachine.c

@ -86,7 +86,6 @@
#define MICROPY_PY_MACHINE_EXTRA_GLOBALS \
{ MP_ROM_QSTR(MP_QSTR_info), MP_ROM_PTR(&machine_info_obj) }, \
{ MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&machine_reset_obj) }, \
{ MP_ROM_QSTR(MP_QSTR_bootloader), MP_ROM_PTR(&machine_bootloader_obj) }, \
{ MP_ROM_QSTR(MP_QSTR_enable_irq), MP_ROM_PTR(&machine_enable_irq_obj) }, \
{ MP_ROM_QSTR(MP_QSTR_disable_irq), MP_ROM_PTR(&machine_disable_irq_obj) }, \
{ MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&machine_lightsleep_obj) }, \
@ -188,12 +187,11 @@ STATIC mp_obj_t machine_reset(void) {
}
MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_obj, machine_reset);
NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args) {
NORETURN void mp_machine_bootloader(size_t n_args, const mp_obj_t *args) {
MICROPY_BOARD_ENTER_BOOTLOADER(n_args, args);
for (;;) {
}
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_bootloader_obj, 0, 1, machine_bootloader);
STATIC void mp_machine_idle(void) {
MICROPY_EVENT_POLL_HOOK;

1
ports/nrf/modules/machine/modmachine.h

@ -36,6 +36,5 @@ MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_info_obj);
MP_DECLARE_CONST_FUN_OBJ_0(machine_reset_obj);
MP_DECLARE_CONST_FUN_OBJ_0(machine_lightsleep_obj);
MP_DECLARE_CONST_FUN_OBJ_0(machine_deepsleep_obj);
NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args);
#endif // __MICROPY_INCLUDED_NRF5_MODMACHINE_H__

4
ports/renesas-ra/modmachine.c

@ -65,7 +65,6 @@
{ MP_ROM_QSTR(MP_QSTR_info), MP_ROM_PTR(&machine_info_obj) }, \
{ MP_ROM_QSTR(MP_QSTR_unique_id), MP_ROM_PTR(&machine_unique_id_obj) }, \
{ MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&machine_reset_obj) }, \
{ MP_ROM_QSTR(MP_QSTR_bootloader), MP_ROM_PTR(&machine_bootloader_obj) }, \
{ MP_ROM_QSTR(MP_QSTR_freq), MP_ROM_PTR(&machine_freq_obj) }, \
{ MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&machine_lightsleep_obj) }, \
{ MP_ROM_QSTR(MP_QSTR_lightsleep), MP_ROM_PTR(&machine_lightsleep_obj) }, \
@ -199,7 +198,7 @@ STATIC mp_obj_t machine_reset(void) {
MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_obj, machine_reset);
// Activate the bootloader without BOOT* pins.
NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args) {
NORETURN void mp_machine_bootloader(size_t n_args, const mp_obj_t *args) {
#if MICROPY_HW_ENABLE_STORAGE
storage_flush();
#endif
@ -217,7 +216,6 @@ NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args) {
;
}
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_bootloader_obj, 0, 1, machine_bootloader);
// get or set the MCU frequencies
STATIC mp_obj_t machine_freq(size_t n_args, const mp_obj_t *args) {

1
ports/renesas-ra/modmachine.h

@ -39,7 +39,6 @@ void machine_deinit(void);
void machine_pin_init(void);
void machine_pin_deinit(void);
void machine_i2s_init0(void);
NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args);
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_info_obj);
MP_DECLARE_CONST_FUN_OBJ_0(machine_unique_id_obj);

1
ports/renesas-ra/mpconfigport.h

@ -131,6 +131,7 @@
#ifndef MICROPY_PY_MACHINE
#define MICROPY_PY_MACHINE (1)
#define MICROPY_PY_MACHINE_INCLUDEFILE "ports/renesas-ra/modmachine.c"
#define MICROPY_PY_MACHINE_BOOTLOADER (1)
#define MICROPY_PY_MACHINE_ADC (1)
#define MICROPY_PY_MACHINE_ADC_INCLUDEFILE "ports/renesas-ra/machine_adc.c"
#define MICROPY_PY_MACHINE_ADC_READ (1)

4
ports/rp2/modmachine.c

@ -51,7 +51,6 @@
{ MP_ROM_QSTR(MP_QSTR_unique_id), MP_ROM_PTR(&machine_unique_id_obj) }, \
{ MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&machine_reset_obj) }, \
{ MP_ROM_QSTR(MP_QSTR_reset_cause), MP_ROM_PTR(&machine_reset_cause_obj) }, \
{ MP_ROM_QSTR(MP_QSTR_bootloader), MP_ROM_PTR(&machine_bootloader_obj) }, \
{ MP_ROM_QSTR(MP_QSTR_freq), MP_ROM_PTR(&machine_freq_obj) }, \
\
{ MP_ROM_QSTR(MP_QSTR_lightsleep), MP_ROM_PTR(&machine_lightsleep_obj) }, \
@ -94,14 +93,13 @@ STATIC mp_obj_t machine_reset_cause(void) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_cause_obj, machine_reset_cause);
NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args) {
NORETURN void mp_machine_bootloader(size_t n_args, const mp_obj_t *args) {
MICROPY_BOARD_ENTER_BOOTLOADER(n_args, args);
rosc_hw->ctrl = ROSC_CTRL_ENABLE_VALUE_ENABLE << ROSC_CTRL_ENABLE_LSB;
reset_usb_boot(0, 0);
for (;;) {
}
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_bootloader_obj, 0, 1, machine_bootloader);
STATIC mp_obj_t machine_freq(size_t n_args, const mp_obj_t *args) {
if (n_args == 0) {

1
ports/rp2/modmachine.h

@ -9,6 +9,5 @@ void machine_i2s_init0(void);
void machine_pwm_deinit_all(void);
struct _machine_spi_obj_t *spi_from_mp_obj(mp_obj_t o);
NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args);
#endif // MICROPY_INCLUDED_RP2_MODMACHINE_H

1
ports/rp2/mpconfigport.h

@ -112,6 +112,7 @@
#define MICROPY_PY_RANDOM_SEED_INIT_FUNC (rosc_random_u32())
#define MICROPY_PY_MACHINE (1)
#define MICROPY_PY_MACHINE_INCLUDEFILE "ports/rp2/modmachine.c"
#define MICROPY_PY_MACHINE_BOOTLOADER (1)
#define MICROPY_PY_MACHINE_ADC (1)
#define MICROPY_PY_MACHINE_ADC_INCLUDEFILE "ports/rp2/machine_adc.c"
#define MICROPY_PY_MACHINE_PIN_MAKE_NEW mp_pin_make_new

4
ports/samd/modmachine.c

@ -56,7 +56,6 @@
#define MICROPY_PY_MACHINE_EXTRA_GLOBALS \
{ MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&machine_reset_obj) }, \
{ MP_ROM_QSTR(MP_QSTR_bootloader), MP_ROM_PTR(&machine_bootloader_obj) }, \
{ MP_ROM_QSTR(MP_QSTR_freq), MP_ROM_PTR(&machine_freq_obj) }, \
{ MP_ROM_QSTR(MP_QSTR_unique_id), MP_ROM_PTR(&machine_unique_id_obj) }, \
\
@ -92,14 +91,13 @@ STATIC mp_obj_t machine_reset(void) {
}
MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_obj, machine_reset);
NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args) {
NORETURN void mp_machine_bootloader(size_t n_args, const mp_obj_t *args) {
*DBL_TAP_ADDR = DBL_TAP_MAGIC_LOADER;
#ifdef DBL_TAP_ADDR_ALT
*DBL_TAP_ADDR_ALT = DBL_TAP_MAGIC_LOADER;
#endif
NVIC_SystemReset();
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_bootloader_obj, 0, 1, machine_bootloader);
STATIC mp_obj_t machine_freq(size_t n_args, const mp_obj_t *args) {
if (n_args == 0) {

2
ports/samd/modmachine.h

@ -33,8 +33,6 @@
extern const mp_obj_type_t machine_dac_type;
#endif
NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args);
void rtc_gettime(timeutils_struct_time_t *tm);
#endif // MICROPY_INCLUDED_SAMD_MODMACHINE_H

1
ports/samd/mpconfigport.h

@ -94,6 +94,7 @@
#define MICROPY_PY_TIME_INCLUDEFILE "ports/samd/modtime.c"
#define MICROPY_PY_MACHINE (1)
#define MICROPY_PY_MACHINE_INCLUDEFILE "ports/samd/modmachine.c"
#define MICROPY_PY_MACHINE_BOOTLOADER (1)
#define MICROPY_PY_OS (1)
#define MICROPY_PY_OS_INCLUDEFILE "ports/samd/modos.c"
#define MICROPY_READER_VFS (1)

4
ports/stm32/modmachine.c

@ -99,7 +99,6 @@
{ MP_ROM_QSTR(MP_QSTR_info), MP_ROM_PTR(&machine_info_obj) }, \
{ MP_ROM_QSTR(MP_QSTR_unique_id), MP_ROM_PTR(&machine_unique_id_obj) }, \
{ MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&machine_reset_obj) }, \
{ MP_ROM_QSTR(MP_QSTR_bootloader), MP_ROM_PTR(&machine_bootloader_obj) }, \
{ MP_ROM_QSTR(MP_QSTR_freq), MP_ROM_PTR(&machine_freq_obj) }, \
MICROPY_PY_MACHINE_RNG_ENTRY \
{ MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&machine_lightsleep_obj) }, \
@ -298,7 +297,7 @@ STATIC mp_obj_t machine_reset(void) {
MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_obj, machine_reset);
// Activate the bootloader without BOOT* pins.
NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args) {
NORETURN void mp_machine_bootloader(size_t n_args, const mp_obj_t *args) {
#if MICROPY_HW_ENABLE_USB
pyb_usb_dev_deinit();
#endif
@ -322,7 +321,6 @@ NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args) {
;
}
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_bootloader_obj, 0, 1, machine_bootloader);
// get or set the MCU frequencies
STATIC mp_obj_t machine_freq(size_t n_args, const mp_obj_t *args) {

2
ports/stm32/modmachine.h

@ -31,12 +31,10 @@
void machine_init(void);
void machine_deinit(void);
void machine_i2s_init0();
NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args);
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_info_obj);
MP_DECLARE_CONST_FUN_OBJ_0(machine_unique_id_obj);
MP_DECLARE_CONST_FUN_OBJ_0(machine_reset_obj);
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_bootloader_obj);
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_freq_obj);
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_lightsleep_obj);

1
ports/stm32/mpconfigport.h

@ -111,6 +111,7 @@
#ifndef MICROPY_PY_MACHINE
#define MICROPY_PY_MACHINE (1)
#define MICROPY_PY_MACHINE_INCLUDEFILE "ports/stm32/modmachine.c"
#define MICROPY_PY_MACHINE_BOOTLOADER (1)
#define MICROPY_PY_MACHINE_ADC (1)
#define MICROPY_PY_MACHINE_ADC_INCLUDEFILE "ports/stm32/machine_adc.c"
#ifndef MICROPY_PY_MACHINE_BITSTREAM

2
shared/tinyusb/mp_cdc_common.c

@ -26,7 +26,7 @@
#include "py/runtime.h"
#include "py/mphal.h"
#include "modmachine.h"
#include "extmod/modmachine.h"
#if MICROPY_HW_USB_CDC_1200BPS_TOUCH && MICROPY_HW_ENABLE_USBDEV

Loading…
Cancel
Save