Skip to content

Commit

Permalink
ports/psoc6: Merging latest state of ports/psoc6.
Browse files Browse the repository at this point in the history
Signed-off-by: jaenrig-ifx <[email protected]>
  • Loading branch information
jaenrig-ifx committed Apr 13, 2023
2 parents ccd80c5 + 25222f6 commit 9bbc70f
Show file tree
Hide file tree
Showing 61 changed files with 775 additions and 703 deletions.
13 changes: 12 additions & 1 deletion docs/psoc6/feature_list.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Enabled modules
* micropython
* ucryptolib
* uctypes
* network


* Port specific modules and micro-libraries
Expand All @@ -54,7 +55,6 @@ Not yet enabled

* Micropython specific modules and libraries
* btree
* network
* ubluetooth


Expand Down Expand Up @@ -113,3 +113,14 @@ Table :ref:`configuration details <table_mpy_configuration>` below lists specifi
| | |
| | Option to enable the port specific debug logger: ``MICROPY_LOGGER_DEBUG``. |
+-----------------+----------------------------------------------------------------------------------------------------------------------+
| network | Option ``MICROPY_NETWORK`` enabled. |
| | |
| | Functions not yet implemented: *phy_mode()*. |
| | |
| | Classes not yet implemented: *LAN*. |
+-----------------+----------------------------------------------------------------------------------------------------------------------+
| network.WLAN | Mode not yet implemented: *STA_AP*. |
| | |
| | Functions not yet implemented: *config*. |
| | |
+-----------------+----------------------------------------------------------------------------------------------------------------------+
74 changes: 74 additions & 0 deletions docs/psoc6/quickref.rst
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,77 @@ See :ref:`machine.RTC <machine.RTC>` ::
Setting a random week day in 'wday' field is not valid. The underlying library implements the logic to always
calculate the right weekday based on the year, date and month passed. However, datetime() will not raise an error
for this, but rather re-write the field with last calculated actual value.

Network Module
--------------

The :mod:`network` module

See :ref:`network.WLAN <network.WLAN>`

The network module is used to configure the WiFi connection.The WiFi interface for the station mode is only configured for
this port.Create WLAN interface object using ::

import network
wlan = network.WLAN(network.STA_IF) # create station interface

Scan for the available wireless networks using

::

wlan.scan()
Scan function returns a list of tuple information about access points
(ssid, bssid, channel, RSSI, security, hidden) .There are 7 levels of security:

* ``0 - open``,
* ``1 - WEP``,
* ``2 - WPA``,
* ``3 - WPA2``,
* ``4 - WPA2_WPA``,
* ``5 - WPA3``,
* ``6 - WPS``,
* ``7 - Unknown security``.

These are the other functions available in the network module

::

wlan.active(True) # activate the interface
wlan.scan() # scan for access points
wlan.isconnected() # check if the station is connected to an AP
wlan.connect('ssid', 'key') # connect to an AP
wlan.disconnect() # disconnect from the connected AP
wlan.status() # check the link status and returns 1 for linkup & 0 for linkdown
wlan.ifconfig() # get the interface's IP/netmask/gateway/DNS addresses


Here is a function you can run (or put in your boot.py file) to automatically connect to your WiFi network:

::

def network_connect() :
import network
from utime import sleep,sleep_ms
wlan = network.WLAN(network.STA_IF)
if wlan.isconnected():
print('[Network] already connected')
return

# enable and connect wlan
wlan.active(True)
wlan.connect('<ssid>','<key>')

# wait for connection to establish
sleep(5)
for i in range(0,100):
if not wlan.isconnected() and wlan.status() >= 0:
print("[Network] Waiting to connect..")
sleep(2)

# check connection
if not wlan.isconnected():
print("[Network] Connection failed!")
else:
print(wlan.ifconfig())

8 changes: 7 additions & 1 deletion drivers/ninaw10/machine_pin_nina.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#define NINA_GPIO_MODE (0x50)
#define NINA_GPIO_READ (0x53)
#define NINA_GPIO_WRITE (0x51)
#define NINA_GPIO_IS_INPUT_ONLY(p) ((p >= 34 && p <= 36) || (p == 39))

static uint8_t pin_map[MICROPY_HW_PIN_EXT_COUNT] = {
27, // LEDR
Expand Down Expand Up @@ -82,12 +83,17 @@ void machine_pin_ext_config(machine_pin_obj_t *self, int mode, int value) {
} else if (mode == MACHINE_PIN_MODE_OUT) {
mode = NINA_GPIO_OUTPUT;
self->is_output = true;
machine_pin_ext_set(self, value);
} else {
mp_raise_ValueError("only Pin.OUT and Pin.IN are supported for this pin");
}
if (self->id >= 0 && self->id < MICROPY_HW_PIN_EXT_COUNT) {
uint8_t buf[] = {pin_map[self->id], mode};
if (mode == NINA_GPIO_OUTPUT) {
if (NINA_GPIO_IS_INPUT_ONLY(buf[0])) {
mp_raise_ValueError("only Pin.IN is supported for this pin");
}
machine_pin_ext_set(self, value);
}
nina_ioctl(NINA_GPIO_MODE, sizeof(buf), buf, 0);
}
}
Expand Down
10 changes: 9 additions & 1 deletion extmod/network_cyw43.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,14 @@ STATIC mp_obj_t network_cyw43_status(size_t n_args, const mp_obj_t *args) {

// one argument: return status based on query parameter
switch (mp_obj_str_get_qstr(args[1])) {
case MP_QSTR_rssi: {
if (self->itf != CYW43_ITF_STA) {
mp_raise_ValueError(MP_ERROR_TEXT("STA required"));
}
int32_t rssi;
cyw43_wifi_get_rssi(self->cyw, &rssi);
return mp_obj_new_int(rssi);
}
case MP_QSTR_stations: {
// return list of connected stations
if (self->itf != CYW43_ITF_AP) {
Expand Down Expand Up @@ -474,7 +482,7 @@ STATIC mp_obj_t network_cyw43_config(size_t n_args, const mp_obj_t *args, mp_map
case MP_QSTR_hostname: {
// TODO: Deprecated. Use network.hostname(name) instead.
size_t len;
const char *str = mp_obj_str_get_data(args[0], &len);
const char *str = mp_obj_str_get_data(e->value, &len);
if (len >= MICROPY_PY_NETWORK_HOSTNAME_MAX_LEN) {
mp_raise_ValueError(NULL);
}
Expand Down
36 changes: 21 additions & 15 deletions extmod/network_ninaw10.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,13 +486,33 @@ STATIC int network_ninaw10_socket_listening(mod_network_socket_obj_t *socket, in
STATIC int network_ninaw10_socket_socket(mod_network_socket_obj_t *socket, int *_errno) {
debug_printf("socket_socket(%d %d %d)\n", socket->domain, socket->type, socket->proto);

uint8_t socket_type;

switch (socket->type) {
case MOD_NETWORK_SOCK_STREAM:
socket_type = NINA_SOCKET_TYPE_TCP;
break;

case MOD_NETWORK_SOCK_DGRAM:
socket_type = NINA_SOCKET_TYPE_UDP;
break;

case MOD_NETWORK_SOCK_RAW:
socket_type = NINA_SOCKET_TYPE_RAW;
break;

default:
*_errno = MP_EINVAL;
return -1;
}

if (socket->domain != MOD_NETWORK_AF_INET) {
*_errno = MP_EAFNOSUPPORT;
return -1;
}

// open socket
int fd = nina_socket_socket(socket->type, socket->proto);
int fd = nina_socket_socket(socket_type, socket->proto);
if (fd < 0) {
nina_socket_errno(_errno);
debug_printf("socket_socket() -> errno %d\n", *_errno);
Expand Down Expand Up @@ -522,20 +542,6 @@ STATIC void network_ninaw10_socket_close(mod_network_socket_obj_t *socket) {

STATIC int network_ninaw10_socket_bind(mod_network_socket_obj_t *socket, byte *ip, mp_uint_t port, int *_errno) {
debug_printf("socket_bind(%d, %d)\n", socket->fileno, port);
uint8_t type;
switch (socket->type) {
case MOD_NETWORK_SOCK_STREAM:
type = NINA_SOCKET_TYPE_TCP;
break;

case MOD_NETWORK_SOCK_DGRAM:
type = NINA_SOCKET_TYPE_UDP;
break;

default:
*_errno = MP_EINVAL;
return -1;
}

int ret = nina_socket_bind(socket->fileno, ip, port);
if (ret < 0) {
Expand Down
2 changes: 1 addition & 1 deletion ports/esp32/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ void mp_task(void *pvParameter) {
#endif

// run boot-up scripts
pyexec_frozen_module("_boot.py");
pyexec_frozen_module("_boot.py", false);
pyexec_file_if_exists("boot.py");
if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL) {
int ret = pyexec_file_if_exists("main.py");
Expand Down
2 changes: 1 addition & 1 deletion ports/esp8266/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ STATIC void mp_reset(void) {
}

#if MICROPY_MODULE_FROZEN
pyexec_frozen_module("_boot.py");
pyexec_frozen_module("_boot.py", false);
pyexec_file_if_exists("boot.py");
if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL) {
pyexec_file_if_exists("main.py");
Expand Down
55 changes: 32 additions & 23 deletions ports/mimxrt/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ SRC_HAL_IMX_C += \
$(MCU_DIR)/drivers/fsl_lpuart.c \
$(MCU_DIR)/drivers/fsl_pit.c \
$(MCU_DIR)/drivers/fsl_pwm.c \
$(MCU_DIR)/drivers/fsl_romapi.c \
$(MCU_DIR)/drivers/fsl_sai.c \
$(MCU_DIR)/drivers/fsl_snvs_lp.c \
$(MCU_DIR)/drivers/fsl_wdog.c \
Expand Down Expand Up @@ -228,21 +229,33 @@ SHARED_SRC_C += \
shared/runtime/sys_stdio_mphal.c \
shared/timeutils/timeutils.c \

# Add sources for respective board flash type
ifeq ($(MICROPY_HW_FLASH_TYPE),$(filter $(MICROPY_HW_FLASH_TYPE),qspi_nor_flash qspi_hyper_flash))
# Add hal/flexspi_nor_flash.c or hal/flashspi_hyper_flash.c respectively
SRC_HAL_C += hal/flexspi_$(subst qspi_,,$(MICROPY_HW_FLASH_TYPE)).c
#
# Add custom (board specific) or default configuration
ifeq ($(MICROPY_HW_BOARD_FLASH_FILES),1)
SRC_HAL_C += $(BOARD_DIR)/$(MICROPY_HW_FLASH_TYPE)_config.c
else
SRC_HAL_C += hal/$(MICROPY_HW_FLASH_TYPE)_config.c
endif
# Set flash driver name, base address and internal flash flag, based on the flash type.
ifeq ($(MICROPY_HW_FLASH_TYPE),$(filter $(MICROPY_HW_FLASH_TYPE),qspi_nor_flash))
MICROPY_HW_FLASH_BASE = 0x60000000
FLEXSPI_FLASH_TYPE = $(MICROPY_HW_FLASH_TYPE)
else ifeq ($(MICROPY_HW_FLASH_TYPE),$(filter $(MICROPY_HW_FLASH_TYPE),qspi_hyper_flash))
MICROPY_HW_FLASH_BASE = 0x60000000
FLEXSPI_FLASH_TYPE = $(MICROPY_HW_FLASH_TYPE)
else ifeq ($(MICROPY_HW_FLASH_TYPE),$(filter $(MICROPY_HW_FLASH_TYPE),internal))
# The internal flash is an SPI NOR Flash.
MICROPY_HW_FLASH_BASE = 0x70000000
FLEXSPI_FLASH_TYPE = qspi_nor_flash
CFLAGS += -DMICROPY_HW_FLASH_INTERNAL
else
$(error Error: Unknown board flash type $(MICROPY_HW_FLASH_TYPE))
endif

# Add sources for respective board flash type
# Add hal/flexspi_nor_flash.c or hal/flashspi_hyper_flash.c respectively
SRC_HAL_C += hal/flexspi_$(subst qspi_,,$(FLEXSPI_FLASH_TYPE)).c
#
# Add custom (board specific) or default configuration
ifeq ($(MICROPY_HW_BOARD_FLASH_FILES),1)
SRC_HAL_C += $(BOARD_DIR)/$(FLEXSPI_FLASH_TYPE)_config.c
else
SRC_HAL_C += hal/$(FLEXSPI_FLASH_TYPE)_config.c
endif

# Math library source files
ifeq ($(MICROPY_FLOAT_IMPL),double)
LIBM_SRC_C += $(addprefix lib/libm_dbl/,\
Expand Down Expand Up @@ -341,18 +354,14 @@ CFLAGS += \
-Wno-error=unused-parameter

# Configure respective board flash type
ifeq ($(MICROPY_HW_FLASH_TYPE),$(filter $(MICROPY_HW_FLASH_TYPE),qspi_nor_flash qspi_hyper_flash))
# Add hal/flexspi_nor_flash.h or hal/flexspi_hyper_flash.h respectively
CFLAGS += -DBOARD_FLASH_OPS_HEADER_H=\"hal/flexspi_$(subst qspi_,,$(MICROPY_HW_FLASH_TYPE)).h\"
#
# Add custom (board specific) or default configuration
ifeq ($(MICROPY_HW_BOARD_FLASH_FILES),1)
CFLAGS += -DBOARD_FLASH_CONFIG_HEADER_H=\"$(BOARD)_flexspi_flash_config.h\"
else
CFLAGS += -DBOARD_FLASH_CONFIG_HEADER_H=\"hal/flexspi_flash_config.h\"
endif
# Add hal/flexspi_nor_flash.h or hal/flexspi_hyper_flash.h respectively
CFLAGS += -DBOARD_FLASH_OPS_HEADER_H=\"hal/flexspi_$(subst qspi_,,$(FLEXSPI_FLASH_TYPE)).h\"
#
# Add custom (board specific) or default configuration
ifeq ($(MICROPY_HW_BOARD_FLASH_FILES),1)
CFLAGS += -DBOARD_FLASH_CONFIG_HEADER_H=\"$(BOARD)_flexspi_flash_config.h\"
else
$(error Error: Unknown board flash type $(MICROPY_HW_FLASH_TYPE))
CFLAGS += -DBOARD_FLASH_CONFIG_HEADER_H=\"hal/flexspi_flash_config.h\"
endif

# Configure floating point support
Expand Down Expand Up @@ -399,7 +408,7 @@ LDFLAGS += \
# the C preprocessor. Therefore keep LDDEFINES separated from LDFLAGS!

LDDEFINES = \
-DMICROPY_HW_FLASH_TYPE=$(MICROPY_HW_FLASH_TYPE) \
-DMICROPY_HW_FLASH_BASE=$(MICROPY_HW_FLASH_BASE) \
-DMICROPY_HW_FLASH_SIZE=$(MICROPY_HW_FLASH_SIZE)

ifdef MICROPY_HW_FLASH_RESERVED
Expand Down
10 changes: 1 addition & 9 deletions ports/mimxrt/boards/MIMXRT1064.ld
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,7 @@
reserved_size = MICROPY_HW_FLASH_RESERVED;
#endif

#if MICROPY_HW_FLASH_TYPE == qspi_nor_flash
flash_start = 0x60000000;
#elif MICROPY_HW_FLASH_TYPE == qspi_hyper_flash
flash_start = 0x60000000;
#elif MICROPY_HW_FLASH_TYPE == internal
flash_start = 0x70000000;
#else
#error Unknown MICROPY_HW_FLASH_TYPE
#endif
flash_start = MICROPY_HW_FLASH_BASE;
flash_size = MICROPY_HW_FLASH_SIZE;
flash_end = DEFINED(reserved_size) ? ((flash_start) + (flash_size - reserved_size)) : ((flash_start) + (flash_size));
flash_config_start = flash_start;
Expand Down
4 changes: 2 additions & 2 deletions ports/mimxrt/boards/MIMXRT1064_EVK/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ MCU_VARIANT = MIMXRT1064DVL6A

MICROPY_FLOAT_IMPL = double
MICROPY_PY_MACHINE_SDCARD = 1
MICROPY_HW_FLASH_TYPE = qspi_hyper_flash
MICROPY_HW_FLASH_SIZE = 0x4000000 # 64MB
MICROPY_HW_FLASH_TYPE = internal
MICROPY_HW_FLASH_SIZE = 0x400000 # 4MB

MICROPY_HW_SDRAM_AVAIL = 1
MICROPY_HW_SDRAM_SIZE = 0x2000000 # 32MB
Expand Down
4 changes: 2 additions & 2 deletions ports/mimxrt/eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "py/mperrno.h"
#include "ticks.h"

#if defined(MICROPY_HW_ETH_MDC)
#if defined(IOMUX_TABLE_ENET)

#include "pin.h"
#include "shared/netutils/netutils.h"
Expand Down Expand Up @@ -639,4 +639,4 @@ void eth_low_power_mode(eth_t *self, bool enable) {
ENET_EnableSleepMode(ENET, enable);
#endif
}
#endif // defined(MICROPY_HW_ETH_MDC)
#endif // defined(IOMUX_TABLE_ENET)
5 changes: 4 additions & 1 deletion ports/mimxrt/hal/flexspi_hyper_flash.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
#include "fsl_flexspi.h"
// #include BOARD_FLASH_CONFIG_HEADER_H

#if defined MIMXRT117x_SERIES
#if defined MICROPY_HW_FLASH_INTERNAL
#define BOARD_FLEX_SPI FLEXSPI2
#define BOARD_FLEX_SPI_ADDR_BASE FlexSPI2_AMBA_BASE
#elif defined MIMXRT117x_SERIES
#define BOARD_FLEX_SPI FLEXSPI1
#define BOARD_FLEX_SPI_ADDR_BASE FlexSPI1_AMBA_BASE
#else
Expand Down
6 changes: 5 additions & 1 deletion ports/mimxrt/hal/flexspi_nor_flash.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@
#define MICROPY_INCLUDED_MIMXRT_HAL_FLEXSPI_NOR_FLASH_H

#include "fsl_flexspi.h"
#include "mpconfigboard.h"
#include BOARD_FLASH_CONFIG_HEADER_H

#if defined MIMXRT117x_SERIES
#if defined MICROPY_HW_FLASH_INTERNAL
#define BOARD_FLEX_SPI FLEXSPI2
#define BOARD_FLEX_SPI_ADDR_BASE FlexSPI2_AMBA_BASE
#elif defined MIMXRT117x_SERIES
#define BOARD_FLEX_SPI FLEXSPI1
#define BOARD_FLEX_SPI_ADDR_BASE FlexSPI1_AMBA_BASE
#else
Expand Down
Loading

0 comments on commit 9bbc70f

Please sign in to comment.