summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2017-11-01 14:19:17 -0400
committerGitHub <noreply@github.com>2017-11-01 14:19:17 -0400
commit3b179808224bceaf40ffd1da0a6295c2d0f3e970 (patch)
treede5f79a21c9299f3e34009870c49451da0f00054
parent0076a3c868b489cf837bfcde72890aefdcb93bed (diff)
parentcfbb74ffe77d81ec0b67ee722ab18cd3b890872a (diff)
Merge pull request #391 from tannewt/longint_usb_fix
Enable LONGINT on M4 + usb fix
-rw-r--r--ports/atmel-samd/Makefile2
-rw-r--r--ports/atmel-samd/mpconfigport.h7
-rw-r--r--ports/atmel-samd/mpconfigport.mk7
-rw-r--r--ports/atmel-samd/usb.c11
4 files changed, 19 insertions, 8 deletions
diff --git a/ports/atmel-samd/Makefile b/ports/atmel-samd/Makefile
index bb5c39e99..2546c416d 100644
--- a/ports/atmel-samd/Makefile
+++ b/ports/atmel-samd/Makefile
@@ -10,8 +10,8 @@ endif
BUILD ?= build-$(BOARD)
include ../../py/mkenv.mk
--include mpconfigport.mk
include boards/$(BOARD)/mpconfigboard.mk
+-include mpconfigport.mk
# qstr definitions (must come before including py.mk)
QSTR_DEFS = qstrdefsport.h
diff --git a/ports/atmel-samd/mpconfigport.h b/ports/atmel-samd/mpconfigport.h
index 88a467c20..e6728d83d 100644
--- a/ports/atmel-samd/mpconfigport.h
+++ b/ports/atmel-samd/mpconfigport.h
@@ -59,8 +59,6 @@
#define MICROPY_PY_URANDOM_EXTRA_FUNCS (0)
#define MICROPY_PY_STRUCT (0)
#define MICROPY_PY_SYS (1)
-// If you change MICROPY_LONGINT_IMPL, also change MPY_TOOL_LONGINT_IMPL in mpconfigport.mk.
-#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_NONE)
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT)
#define MICROPY_STREAMS_NON_BLOCK (1)
@@ -141,12 +139,17 @@ typedef long mp_off_t;
#define CIRCUITPY_MCU_FAMILY samd21
#define MICROPY_PY_SYS_PLATFORM "Atmel SAMD21"
#define PORT_HEAP_SIZE (16384 + 4096)
+// If you change MICROPY_LONGINT_IMPL, also change MPY_TOOL_LONGINT_IMPL in mpconfigport.mk.
+#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_NONE)
#endif
#ifdef SAMD51
#define CIRCUITPY_MCU_FAMILY samd51
#define MICROPY_PY_SYS_PLATFORM "MicroChip SAMD51"
#define PORT_HEAP_SIZE (0x20000) // 128KiB
+// If you change MICROPY_LONGINT_IMPL, also change MPY_TOOL_LONGINT_IMPL in mpconfigport.mk.
+#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ)
+#define MP_SSIZE_MAX (0x7fffffff)
#endif
// extra built in modules to add to the list of known ones
diff --git a/ports/atmel-samd/mpconfigport.mk b/ports/atmel-samd/mpconfigport.mk
index c3b2f22d4..0f3f399e2 100644
--- a/ports/atmel-samd/mpconfigport.mk
+++ b/ports/atmel-samd/mpconfigport.mk
@@ -1,7 +1,12 @@
# Define an equivalent for MICROPY_LONGINT_IMPL, to pass to $(MPY-TOOL) in py/mkrules.mk
# $(MPY-TOOL) needs to know what kind of longint to use (if any) to freeze long integers.
# This should correspond to the MICROPY_LONGINT_IMPL definition in mpconfigport.h.
+ifeq ($(CHIP_FAMILY), samd21)
MPY_TOOL_LONGINT_IMPL = -mlongint-impl=none
+endif
-INTERNAL_LIBM = 1
+ifeq ($(CHIP_FAMILY), samd51)
+MPY_TOOL_LONGINT_IMPL = -mlongint-impl=mpz
+endif
+INTERNAL_LIBM = 1
diff --git a/ports/atmel-samd/usb.c b/ports/atmel-samd/usb.c
index 993ac7eaa..740486aa1 100644
--- a/ports/atmel-samd/usb.c
+++ b/ports/atmel-samd/usb.c
@@ -107,7 +107,11 @@ static volatile bool pending_read;
static int32_t start_read(void) {
pending_read = true;
- return cdcdf_acm_read(cdc_packet_buffer, 64);
+ int32_t result = cdcdf_acm_read(cdc_packet_buffer, 64);
+ if (result != ERR_NONE) {
+ pending_read = false;
+ }
+ return result;
}
static bool read_complete(const uint8_t ep, const enum usb_xfer_code rc, const uint32_t count) {
@@ -222,7 +226,7 @@ void init_usb(void) {
usbdc_attach();
}
-static inline bool cdc_enabled(void) {
+static bool cdc_enabled(void) {
if (mp_cdc_enabled) {
return true;
}
@@ -239,11 +243,10 @@ static inline bool cdc_enabled(void) {
}
bool usb_bytes_available(void) {
- if (!pending_read) {
+ if (cdc_enabled() && !pending_read) {
start_read();
}
if (usb_rx_count == 0) {
- cdc_enabled();
return false;
}
return usb_rx_count > 0;