Skip to content

RP2: Add networking support. #7667

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions extmod/extmod.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ set(MICROPY_SOURCE_EXTMOD
${MICROPY_EXTMOD_DIR}/modutimeq.c
${MICROPY_EXTMOD_DIR}/moduwebsocket.c
${MICROPY_EXTMOD_DIR}/moduzlib.c
${MICROPY_EXTMOD_DIR}/modusocket.c
${MICROPY_EXTMOD_DIR}/modnetwork.c
${MICROPY_EXTMOD_DIR}/modwebrepl.c
${MICROPY_EXTMOD_DIR}/uos_dupterm.c
${MICROPY_EXTMOD_DIR}/utime_mphal.c
Expand Down
4 changes: 2 additions & 2 deletions extmod/modusocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include "shared/netutils/netutils.h"
#include "modnetwork.h"

#if MICROPY_PY_USOCKET && !MICROPY_PY_LWIP
#if MICROPY_PY_NETWORK && MICROPY_PY_USOCKET && !MICROPY_PY_LWIP
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The zephyr port fails here because it defines PY_USOCKET.


/******************************************************************************/
// socket class
Expand Down Expand Up @@ -517,4 +517,4 @@ const mp_obj_module_t mp_module_usocket = {
.globals = (mp_obj_dict_t *)&mp_module_usocket_globals,
};

#endif // MICROPY_PY_USOCKET && !MICROPY_PY_LWIP
#endif // MICROPY_PY_NETWORK && MICROPY_PY_USOCKET && !MICROPY_PY_LWIP
1 change: 1 addition & 0 deletions ports/rp2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ set(MICROPY_SOURCE_LIB
${MICROPY_DIR}/lib/littlefs/lfs2_util.c
${MICROPY_DIR}/lib/oofatfs/ff.c
${MICROPY_DIR}/lib/oofatfs/ffunicode.c
${MICROPY_DIR}/shared/netutils/netutils.c
${MICROPY_DIR}/shared/readline/readline.c
${MICROPY_DIR}/shared/runtime/gchelper_m0.s
${MICROPY_DIR}/shared/runtime/gchelper_native.c
Expand Down
8 changes: 8 additions & 0 deletions ports/rp2/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "modmachine.h"
#include "modrp2.h"
#include "genhdr/mpversion.h"
#include "extmod/modnetwork.h"

#include "pico/stdlib.h"
#include "pico/binary_info.h"
Expand Down Expand Up @@ -107,6 +108,10 @@ int main(int argc, char **argv) {
machine_pin_init();
rp2_pio_init();

#if MICROPY_PY_NETWORK
mod_network_init();
#endif

// Execute _boot.py to set up the filesystem.
pyexec_frozen_module("_boot.py");

Expand Down Expand Up @@ -136,6 +141,9 @@ int main(int argc, char **argv) {

soft_reset_exit:
mp_printf(MP_PYTHON_PRINTER, "MPY: soft reboot\n");
#if MICROPY_PY_NETWORK
mod_network_deinit();
#endif
rp2_pio_deinit();
machine_pin_deinit();
#if MICROPY_PY_THREAD
Expand Down
22 changes: 21 additions & 1 deletion ports/rp2/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,26 +170,46 @@ extern const struct _mp_obj_module_t mp_module_onewire;
extern const struct _mp_obj_module_t mp_module_rp2;
extern const struct _mp_obj_module_t mp_module_uos;
extern const struct _mp_obj_module_t mp_module_utime;
extern const struct _mp_obj_module_t mp_module_usocket;
extern const struct _mp_obj_module_t mp_module_network;

#if MICROPY_PY_USOCKET
#define SOCKET_BUILTIN_MODULE { MP_ROM_QSTR(MP_QSTR_usocket), MP_ROM_PTR(&mp_module_usocket) },
#else
#define SOCKET_BUILTIN_MODULE
#endif
#if MICROPY_PY_NETWORK
#define NETWORK_BUILTIN_MODULE { MP_ROM_QSTR(MP_QSTR_network), MP_ROM_PTR(&mp_module_network) },
#define NETWORK_ROOT_POINTERS mp_obj_list_t mod_network_nic_list;
#else
#define NETWORK_BUILTIN_MODULE
#define NETWORK_ROOT_POINTERS
#endif

#define MICROPY_PORT_BUILTIN_MODULES \
{ MP_OBJ_NEW_QSTR(MP_QSTR_machine), (mp_obj_t)&mp_module_machine }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR__onewire), (mp_obj_t)&mp_module_onewire }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR__rp2), (mp_obj_t)&mp_module_rp2 }, \
{ MP_ROM_QSTR(MP_QSTR_uos), MP_ROM_PTR(&mp_module_uos) }, \
{ MP_ROM_QSTR(MP_QSTR_utime), MP_ROM_PTR(&mp_module_utime) }, \
SOCKET_BUILTIN_MODULE \
NETWORK_BUILTIN_MODULE \

#ifndef MICROPY_BOARD_ROOT_POINTERS
#define MICROPY_BOARD_ROOT_POINTERS
#endif

#define MICROPY_PORT_NETWORK_INTERFACES \

#define MICROPY_PORT_ROOT_POINTERS \
const char *readline_hist[8]; \
void *machine_pin_irq_obj[30]; \
void *rp2_pio_irq_obj[2]; \
void *rp2_state_machine_irq_obj[8]; \
void *rp2_uart_rx_buffer[2]; \
void *rp2_uart_tx_buffer[2]; \
MICROPY_BOARD_ROOT_POINTERS \
NETWORK_ROOT_POINTERS \
MICROPY_BOARD_ROOT_POINTERS \
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dpgeorge can this be fixed in the code format ? It insists on indenting the last line in a #define like that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that would need to be done in the fix-up stage of tools/codeformat.py. Feel free to have a go at doing that (separate PR tho!).


#define MP_STATE_PORT MP_STATE_VM

Expand Down