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>
This commit is contained in:
Jim Mussared 2023-02-02 14:46:28 +11:00 committed by Damien George
parent 8b277d3c34
commit 7d40317a4a
2 changed files with 14 additions and 3 deletions

View File

@ -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[] =

View File

@ -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) },