Skip to content

stm32: Use lib/wiznet5k instead of drivers/wiznet5k. #9019

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 4 commits 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
67 changes: 36 additions & 31 deletions extmod/network_wiznet5k.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,10 @@ STATIC void wiznet5k_lwip_init(wiznet5k_obj_t *self);

STATIC mp_obj_t mpy_wiznet_read_int(mp_obj_t none_in) {
(void)none_in;
wizchip_clrinterrupt(IK_SOCK_0);
setSn_IR(0, Sn_IR_RECV);

// Handle incoming data
wiznet5k_try_poll();
// Handle incoming data, unless the SPI bus is busy
if (mp_hal_pin_read(wiznet5k_obj.cs)) {
wiznet5k_try_poll();
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mpy_wiznet_read_int_obj, mpy_wiznet_read_int);
Expand All @@ -198,6 +197,16 @@ STATIC void wiznet5k_config_interrupt(bool enabled) {
);
}

void wiznet5k_deinit(void) {
for (struct netif *netif = netif_list; netif != NULL; netif = netif->next) {
if (netif == &wiznet5k_obj.netif) {
netif_remove(netif);
netif->flags = 0;
break;
}
}
}

STATIC void wiznet5k_init(void) {
// Configure wiznet for raw ethernet frame usage.

Expand All @@ -219,21 +228,17 @@ STATIC void wiznet5k_init(void) {
wiznet5k_config_interrupt(true);
}

// Deinit before a new init to clear the state from a previous activation
wiznet5k_deinit();

// Hook the Wiznet into lwIP
wiznet5k_lwip_init(&wiznet5k_obj);

netif_set_link_up(&wiznet5k_obj.netif);
netif_set_up(&wiznet5k_obj.netif);
}

void wiznet5k_deinit(void) {
for (struct netif *netif = netif_list; netif != NULL; netif = netif->next) {
if (netif == &wiznet5k_obj.netif) {
netif_remove(netif);
netif->flags = 0;
break;
}
}
// register with network module
mod_network_register_nic(&wiznet5k_obj);
}

STATIC void wiznet5k_send_ethernet(wiznet5k_obj_t *self, size_t len, const uint8_t *buf) {
Expand Down Expand Up @@ -320,23 +325,25 @@ STATIC void wiznet5k_lwip_init(wiznet5k_obj_t *self) {

void wiznet5k_poll(void) {
wiznet5k_obj_t *self = &wiznet5k_obj;
if (!(self->netif.flags & NETIF_FLAG_UP) ||
!(self->netif.flags & NETIF_FLAG_LINK_UP)) {
return;
}
uint16_t len;
while ((len = wiznet5k_recv_ethernet(self)) > 0) {
if (self->trace_flags & TRACE_ETH_RX) {
netutils_ethernet_trace(MP_PYTHON_PRINTER, len, self->eth_frame, NETUTILS_TRACE_NEWLINE);
}
struct pbuf *p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
if (p != NULL) {
pbuf_take(p, self->eth_frame, len);
if (self->netif.input(p, &self->netif) != ERR_OK) {
pbuf_free(p);
if ((self->netif.flags & (NETIF_FLAG_UP | NETIF_FLAG_LINK_UP)) == (NETIF_FLAG_UP | NETIF_FLAG_LINK_UP)) {
uint16_t len;
while ((len = wiznet5k_recv_ethernet(self)) > 0) {
if (self->trace_flags & TRACE_ETH_RX) {
netutils_ethernet_trace(MP_PYTHON_PRINTER, len, self->eth_frame, NETUTILS_TRACE_NEWLINE);
}
struct pbuf *p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
if (p != NULL) {
pbuf_take(p, self->eth_frame, len);
if (self->netif.input(p, &self->netif) != ERR_OK) {
pbuf_free(p);
}
}
}
}
wizchip_clrinterrupt(IK_SOCK_0);
#if _WIZCHIP_ == W5100S
setSn_IR(0, Sn_IR_RECV); // WZ5100S driver bug.
#endif
}

#endif // MICROPY_PY_LWIP
Expand Down Expand Up @@ -686,10 +693,8 @@ STATIC mp_obj_t wiznet5k_make_new(const mp_obj_type_t *type, size_t n_args, size
#endif

#ifdef MICROPY_HW_WIZNET_SPI_ID
// check arguments
mp_arg_check_num(n_args, n_kw, 0, 3, false);
// Allow auto-configuration of SPI if defined for board and no args passed
if (n_args == 0) {
if (n_args == 0 && n_kw == 0) {
// Initialize SPI.
mp_obj_t spi_obj = MP_OBJ_NEW_SMALL_INT(MICROPY_HW_WIZNET_SPI_SCK);
mp_obj_t miso_obj = MP_OBJ_NEW_SMALL_INT(MICROPY_HW_WIZNET_SPI_MISO);
Expand Down
18 changes: 11 additions & 7 deletions ports/stm32/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -458,22 +458,26 @@ LIBS += $(TOP)/drivers/cyw43/libcyw43.a
endif

ifneq ($(MICROPY_PY_NETWORK_WIZNET5K),0)
WIZNET5K_DIR=drivers/wiznet5k
INC += -I$(TOP)/$(WIZNET5K_DIR)
WIZNET5K_DIR=lib/wiznet5k
GIT_SUBMODULES += lib/wiznet5k
INC += -I$(TOP)/$(WIZNET5K_DIR) -I$(TOP)/$(WIZNET5K_DIR)/Ethernet
CFLAGS_MOD += -DMICROPY_PY_NETWORK_WIZNET5K=$(MICROPY_PY_NETWORK_WIZNET5K) -D_WIZCHIP_=$(MICROPY_PY_NETWORK_WIZNET5K)
CFLAGS_MOD += -DWIZCHIP_PREFIXED_EXPORTS=1
ifeq ($(MICROPY_PY_LWIP),1)
# When using MACRAW mode (with lwIP), maximum buffer space must be used for the raw socket
CFLAGS_MOD += -DWIZCHIP_USE_MAX_BUFFER
endif
SRC_MOD += network_wiznet5k.c modnwwiznet5k.c
SRC_MOD += extmod/network_wiznet5k.c
SRC_MOD += $(addprefix $(WIZNET5K_DIR)/,\
ethernet/w$(MICROPY_PY_NETWORK_WIZNET5K)/w$(MICROPY_PY_NETWORK_WIZNET5K).c \
ethernet/wizchip_conf.c \
ethernet/socket.c \
internet/dns/dns.c \
Ethernet/W$(MICROPY_PY_NETWORK_WIZNET5K)/w$(MICROPY_PY_NETWORK_WIZNET5K).c \
Ethernet/wizchip_conf.c \
Ethernet/socket.c \
Internet/DNS/dns.c \
Internet/DHCP/dhcp.c \
)
endif


# for CC3000 module
ifeq ($(MICROPY_PY_CC3K),1)
CC3000_DIR=drivers/cc3000
Expand Down
3 changes: 3 additions & 0 deletions ports/stm32/modmachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ extern const mp_obj_type_t machine_adc_type;
extern const mp_obj_type_t machine_timer_type;
extern const mp_obj_type_t machine_hard_i2c_type;
extern const mp_obj_type_t machine_i2s_type;
extern const mp_obj_type_t machine_hard_spi_type;

#define machine_spi_type machine_hard_spi_type

void machine_init(void);
void machine_deinit(void);
Expand Down
Loading