Skip to content

Commit e32e84a

Browse files
committed
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>
1 parent 6e0cdf5 commit e32e84a

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

ports/stm32/factoryreset.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,16 @@ static const char fresh_boot_py[] =
4242
"\r\n"
4343
"import machine\r\n"
4444
"import pyb\r\n"
45-
"pyb.country('US') # ISO 3166-1 Alpha-2 code, eg US, GB, DE, AU\r\n"
4645
"#pyb.main('main.py') # main script to run after this one\r\n"
4746
#if MICROPY_HW_ENABLE_USB
4847
"#pyb.usb_mode('VCP+MSC') # act as a serial and a storage device\r\n"
4948
"#pyb.usb_mode('VCP+HID') # act as a serial device and a mouse\r\n"
5049
#endif
50+
#if MICROPY_PY_NETWORK
51+
"#import network\r\n"
52+
"#network.country('US') # ISO 3166-1 Alpha-2 code, eg US, GB, DE, AU or XX for worldwide\r\n"
53+
"#network.hostname('...') # DHCP/mDNS hostname\r\n"
54+
#endif
5155
;
5256

5357
static const char fresh_main_py[] =

ports/stm32/modpyb.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_repl_uart_obj, 0, 1, pyb_repl_uar
116116

117117
#if MICROPY_PY_NETWORK
118118
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mod_network_country_obj);
119+
#else
120+
// Provide a no-op version of pyb.country for backwards compatibility on
121+
// boards that don't support networking.
122+
STATIC mp_obj_t pyb_country(size_t, const mp_obj_t *) {
123+
return mp_const_none;
124+
}
125+
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_network_country_obj, 0, 1, pyb_country);
119126
#endif
120127

121128
STATIC const mp_rom_map_elem_t pyb_module_globals_table[] = {
@@ -148,10 +155,8 @@ STATIC const mp_rom_map_elem_t pyb_module_globals_table[] = {
148155
{ MP_ROM_QSTR(MP_QSTR_main), MP_ROM_PTR(&pyb_main_obj) },
149156
{ MP_ROM_QSTR(MP_QSTR_repl_uart), MP_ROM_PTR(&pyb_repl_uart_obj) },
150157

151-
#if MICROPY_PY_NETWORK
152158
// Deprecated (use network.country instead).
153159
{ MP_ROM_QSTR(MP_QSTR_country), MP_ROM_PTR(&mod_network_country_obj) },
154-
#endif
155160

156161
#if MICROPY_HW_ENABLE_USB
157162
{ MP_ROM_QSTR(MP_QSTR_usb_mode), MP_ROM_PTR(&pyb_usb_mode_obj) },

0 commit comments

Comments
 (0)