diff options
| author | Jim Mussared <jim.mussared@gmail.com> | 2023-02-02 14:46:28 +1100 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2023-03-01 01:28:12 +1100 |
| commit | 7d40317a4af2a8f46d3ed5546d27671ed0c75838 (patch) | |
| tree | bb38269bfd9ece733adf7f78390a0d932c5f5211 | |
| parent | 8b277d3c34f2613c1e204fcf055ebe91f119715b (diff) | |
stm32: Add a default implementation of pyb.country.
This is for boards without networking support so that the default boot.py
continues to work.
Also update boot.py to use network.country and network.hostname instead.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
| -rw-r--r-- | ports/stm32/factoryreset.c | 6 | ||||
| -rw-r--r-- | ports/stm32/modpyb.c | 11 |
2 files changed, 14 insertions, 3 deletions
diff --git a/ports/stm32/factoryreset.c b/ports/stm32/factoryreset.c index 10eb3a17a..2ac656db5 100644 --- a/ports/stm32/factoryreset.c +++ b/ports/stm32/factoryreset.c @@ -42,12 +42,16 @@ static const char fresh_boot_py[] = "\r\n" "import machine\r\n" "import pyb\r\n" - "pyb.country('US') # ISO 3166-1 Alpha-2 code, eg US, GB, DE, AU\r\n" "#pyb.main('main.py') # main script to run after this one\r\n" #if MICROPY_HW_ENABLE_USB "#pyb.usb_mode('VCP+MSC') # act as a serial and a storage device\r\n" "#pyb.usb_mode('VCP+HID') # act as a serial device and a mouse\r\n" #endif +#if MICROPY_PY_NETWORK + "#import network\r\n" + "#network.country('US') # ISO 3166-1 Alpha-2 code, eg US, GB, DE, AU or XX for worldwide\r\n" + "#network.hostname('...') # DHCP/mDNS hostname\r\n" +#endif ; static const char fresh_main_py[] = diff --git a/ports/stm32/modpyb.c b/ports/stm32/modpyb.c index 641d66efa..94aa6e65d 100644 --- a/ports/stm32/modpyb.c +++ b/ports/stm32/modpyb.c @@ -116,6 +116,15 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_repl_uart_obj, 0, 1, pyb_repl_uar #if MICROPY_PY_NETWORK MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mod_network_country_obj); +#else +// Provide a no-op version of pyb.country for backwards compatibility on +// boards that don't support networking. +STATIC mp_obj_t pyb_country(size_t n_args, const mp_obj_t *args) { + (void)n_args; + (void)args; + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_network_country_obj, 0, 1, pyb_country); #endif STATIC const mp_rom_map_elem_t pyb_module_globals_table[] = { @@ -148,10 +157,8 @@ STATIC const mp_rom_map_elem_t pyb_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_main), MP_ROM_PTR(&pyb_main_obj) }, { MP_ROM_QSTR(MP_QSTR_repl_uart), MP_ROM_PTR(&pyb_repl_uart_obj) }, - #if MICROPY_PY_NETWORK // Deprecated (use network.country instead). { MP_ROM_QSTR(MP_QSTR_country), MP_ROM_PTR(&mod_network_country_obj) }, - #endif #if MICROPY_HW_ENABLE_USB { MP_ROM_QSTR(MP_QSTR_usb_mode), MP_ROM_PTR(&pyb_usb_mode_obj) }, |
