Commit Graph

9090 Commits

Author SHA1 Message Date
Damien George
47ecbbbecb stm32/usb: Add ability to have 2x VCP interfaces on the one USB device.
This patch adds the configuration MICROPY_HW_USB_ENABLE_CDC2 which enables
a new USB device configuration at runtime: VCP+VCP+MSC.  It will give two
independent VCP interfaces available via pyb.USB_VCP(0) and pyb.USB_VCP(1).
The first one is the usual one and has the REPL on it.  The second one is
available for general use.

This configuration is disabled by default because if the mode is not used
then it takes up about 2200 bytes of RAM.  Also, F4 MCUs can't support this
mode on their USB FS peripheral (eg PYBv1.x) because they don't have enough
endpoints.  The USB HS peripheral of an F4 supports it, as well as both the
USB FS and USB HS peripherals of F7 MCUs.
2018-05-14 23:44:45 +10:00
Damien George
2e565cc0d4 stm32/usb: Change HID report funcs to take HID state, not usbdev state. 2018-05-14 17:04:43 +10:00
Damien George
91bca340ec stm32/usb: Change CDC tx/rx funcs to take CDC state, not usbdev state. 2018-05-14 16:55:04 +10:00
Damien George
68271a27e6 stm32/usb: Make CDC endpoint definitions private to core usbdev driver. 2018-05-14 16:53:45 +10:00
Damien George
ed92d62326 stm32/usb: Combine HID lower-layer and interface state into one struct. 2018-05-14 16:34:31 +10:00
Damien George
bf08a99ccd stm32/usb: Combine CDC lower-layer and interface state into one struct. 2018-05-14 16:15:58 +10:00
Damien George
ed32284b70 stm32/usb: Use usbd_cdc_itf_t pointer directly in USB_VCP class. 2018-05-14 15:24:44 +10:00
Damien George
fb25c81062 stm32/modpyb: Remove unused includes and clean up comments.
The documentation (including the examples) for elapsed_millis and
elapsed_micros can be found in docs/library/pyb.rst so doesn't need to be
written in full in the source code.
2018-05-14 14:01:50 +10:00
Damien George
88c26a48b4 stm32/pyb_i2c: Put pyb.I2C under MICROPY_PY_PYB_LEGACY setting.
When disabled, the pyb.I2C class saves around 8k of code space and 172
bytes of RAM.  The same functionality is now available in machine.I2C
(for F4 and F7 MCUs).

It is still enabled by default.
2018-05-14 13:53:46 +10:00
Damien George
92c5e2708d stm32/modpyb: Introduce MICROPY_PY_PYB_LEGACY config option for pyb mod.
This is enabled by default.  When it is disabled all legacy functions and
classes in the pyb module are excluded from the build.
2018-05-14 13:49:22 +10:00
Damien George
a0f7b4c678 stm32/accel: Switch pyb.Accel to use new C-level I2C API. 2018-05-14 13:23:18 +10:00
Damien George
ce824bb67e stm32/machine_i2c: Use new F4 hardware I2C driver for machine.I2C class.
And remove the old one based on ST code.
2018-05-14 13:22:12 +10:00
Damien George
b21415ed4f stm32/i2c: Add new hardware I2C driver for F4 MCUs.
This driver uses low-level register access to control the I2C peripheral
(ie it doesn't rely on the ST HAL) and provides the same C-level API as the
existing F7 hardware driver.
2018-05-14 13:19:03 +10:00
Peter D. Gray
ca36645410 stm32/usbd_hid_interface: Address possible race condition vs. interrupt.
The USB IRQ may fire once USBD_HID_ClearNAK() is called and then change the
last_read_len value.
2018-05-14 12:08:34 +10:00
Peter D. Gray
1f1623d3b7 stm32/usbdev: Be honest about data not being written to HID endpoint.
USB_HID.send() should now return 0 if it could not send the report to the
host.
2018-05-14 12:01:27 +10:00
Bas Wijnen
67e1a4f8be esp32: Update to latest ESP IDF version.
- Updated supported git hash to current IDF version.
- Added missing targets and includes to Makefile.
- Updated error codes for networking module.
- Added required constant to sdkconfig configuration.
2018-05-14 11:42:46 +10:00
Damien George
749b16174b py/mpstate.h: Adjust start of root pointer section to exclude non-ptrs.
This patch moves the start of the root pointer section in mp_state_ctx_t
so that it skips entries that are not pointers and don't need scanning.

Previously, the start of the root pointer section was at the very beginning
of the mp_state_ctx_t struct (which is the beginning of mp_state_thread_t).
This was the original assembler version of the NLR code was hard-coded to
have the nlr_top pointer at the start of this state structure.  But now
that the NLR code is partially written in C there is no longer this
restriction on the location of nlr_top (and a comment to this effect has
been removed in this patch).

So now the root pointer section starts part way through the
mp_state_thread_t structure, after the entries which are not root pointers.

This patch also moves the non-pointer entries for MICROPY_ENABLE_SCHEDULER
outside the root pointer section.

Moving non-pointer entries out of the root pointer section helps to make
the GC more precise and should help to prevent some cases of collectable
garbage being kept.

This patch also has a measurable improvement in performance of the
pystone.py benchmark: on unix x86-64 and stm32 there was an improvement of
roughly 0.6% (tested with both gcc 7.3 and gcc 8.1).
2018-05-13 22:53:28 +10:00
Damien George
aeaace0737 stm32/usbdev: Remove unused RxState variable, and unused struct. 2018-05-11 23:20:59 +10:00
Damien George
4b3c629067 .gitattributes: Remove special text handling of stm32 usbdev files. 2018-05-11 23:07:57 +10:00
Damien George
abde0fa226 stm32/usbdev: Convert files to unix line endings.
Also remove trailing whitespace and convert tabs to spaces.
2018-05-11 23:03:52 +10:00
Damien George
56a273ebff stm32/usbd_conf: Changes files to unix line endings and apply styling.
This patch is only cosmetic and has no functional change.
2018-05-11 22:17:58 +10:00
Damien George
9f4eda542a stm32/usbd_conf.h: Remove unused macros and clean up header file. 2018-05-11 22:04:56 +10:00
Damien George
9630376dbc py/mpconfig.h: Be stricter when autodetecting machine endianness.
This patch changes 2 things in the endianness detection:

1. Don't assume that __BYTE_ORDER__ not being __ORDER_LITTLE_ENDIAN__ means
   that the machine is big endian, so add an explicit check that this macro
   is indeed __ORDER_BIG_ENDIAN__ (same with __BYTE_ORDER, __LITTLE_ENDIAN
   and __BIG_ENDIAN).  A machine could have PDP endianness.

2. Remove the checks which base their autodetection decision on whether any
   little or big endian macros are defined (eg __LITTLE_ENDIAN__ or
   __BIG_ENDIAN__).  Just because a system defines these does not mean it
   has that endianness.

See issue #3760.
2018-05-11 21:51:34 +10:00
Damien George
7541be5637 tests/basics/special_methods2: Enable some additional tests that work.
These special methods are all available if MICROPY_PY_ALL_SPECIAL_METHODS
is enabled.
2018-05-11 17:37:16 +10:00
Damien George
421b84af99 docs: Bump version to 1.9.4. 2018-05-11 16:39:59 +10:00
Damien George
d2c1db1e5c tests/float/float_parse: Allow test to run on 32-bit archs.
Printing of uPy floats can differ by the floating-point precision on
different architectures (eg 64-bit vs 32-bit x86), so it's not possible to
using printing of floats in some parts of this test.  Instead we can just
check for equivalence with what is known to be the correct answer.
2018-05-11 13:51:18 +10:00
Damien George
6046e68fe1 py/repl: Initialise q_last variable to prevent compiler warnings.
Some older compilers cannot deduce that q_last is always written to before
being read.
2018-05-11 13:48:47 +10:00
Damien George
095d397017 py/objdeque: Fix sign extension bug when computing len of deque object.
For cases where size_t is smaller than mp_int_t (eg nan-boxing builds) the
difference between two size_t's is not sign extended into mp_int_t and so
the result is never negative.  This patch fixes this bug by using ssize_t
for the type of the result.
2018-05-11 13:44:50 +10:00
Damien George
b208aa189e stm32/README: Update to reflect current MCU support. 2018-05-11 10:36:46 +10:00
Damien George
3678a6bdc6 py/modbuiltins: Make built-in dir support the __dir__ special method.
If MICROPY_PY_ALL_SPECIAL_METHODS is enabled then dir() will now delegate
to the special method __dir__ if the object it is listing has this method.
2018-05-10 23:14:23 +10:00
Damien George
29d28c2574 py/modbuiltins: In built-in dir make use of mp_load_method_protected.
This gives dir() better behaviour when listing the attributes of a user
type that defines __getattr__: it will now not list those attributes for
which __getattr__ raises AttributeError (meaning the attribute is not
supported by the object).
2018-05-10 23:07:19 +10:00
Damien George
7241d90272 py/repl: Use mp_load_method_protected to prevent leaking of exceptions.
This patch fixes the possibility of a crash of the REPL when tab-completing
an object which raises an exception when its attributes are accessed.

See issue #3729.
2018-05-10 23:05:43 +10:00
Damien George
529860643b py/modbuiltins: Make built-in hasattr work properly for user types.
It now allows __getattr__ in a user type to raise AttributeError when the
attribute does not exist.
2018-05-10 23:03:30 +10:00
Damien George
bc87b862fd py/runtime: Add mp_load_method_protected helper which catches exceptions
This new helper function acts like mp_load_method_maybe but is wrapped in
an NLR handler so it can catch exceptions.  It prevents AttributeError from
propagating out, and optionally all other exceptions.  This helper can be
used to fully implement hasattr (see follow-up commit), and also for cases
where mp_load_method_maybe is used but it must now raise an exception.
2018-05-10 23:00:04 +10:00
Damien George
eb88803ac8 py/{modbuiltins,repl}: Start qstr probing from after empty qstr.
The list of qstrs starts with MP_QSTR_NULL followed by MP_QSTR_, and these
should never appear in dir() or REPL tab completion, so skip them.
2018-05-09 16:15:02 +10:00
Damien George
c1115d931f stm32/usb: Use correct type for USB HID object. 2018-05-09 16:00:19 +10:00
Damien George
e1bc85416a stm32/usb: Fix broken pyb.have_cdc() so it works again. 2018-05-09 15:59:48 +10:00
Damien George
e638defff4 stm32/i2c: Make sure stop condition is sent after receiving addr nack. 2018-05-09 15:53:09 +10:00
Damien George
2ada1124d4 tests/cpydiff: Remove types_int_tobytesfloat now that it doesn't fail.
Commit e269cabe3e added a check that the
first argument to the to_bytes() method is an integer, and now uPy
follows CPython behaviour and raises a TypeError for this test.

Note: CPython checks the argument types before checking the number of
arguments, but uPy does it the other way around, so they give different
exception messages for this test, but still the same type, a TypeError.
2018-05-08 17:05:32 +10:00
Damien George
74ab341d3a tests/cpydiff: Remove working cases from types_float_rounding. 2018-05-04 22:30:50 +10:00
Damien George
cd9d71edc8 tests/cpydiff: Remove types_str_decodeerror now that it succeeds.
Commit 68c28174d0 implemented checking for
valid utf-8 data.
2018-05-04 22:27:14 +10:00
Damien George
4b5111f8e1 tests/cpydiff: Remove core_function_unpacking now that it succeeds.
Commit 1e70fda69f fixes this difference.
2018-05-04 22:19:50 +10:00
Damien George
3cf02be4e0 py/emitnx86: Fix 32-bit x86 native emitter build by including header. 2018-05-04 20:39:16 +10:00
Damien George
aea71dbde0 stm32/Makefile: Use -O2 to optimise compilation of lib/libc/string0.c. 2018-05-04 15:53:51 +10:00
Damien George
cb3456ddfe stm32: Don't use %lu or %lx for formatting, use just %u or %x.
On this 32-bit arch there's no need to use the long version of the format
specifier.  It's only there to appease the compiler which checks the type
of the args passed to printf.  Removing the "l" saves a bit of code space.
2018-05-04 15:52:03 +10:00
Damien George
b614dc73b0 stm32/dma: Fix duplicate typedef of struct, it's typedef'd in dma.h. 2018-05-04 15:35:43 +10:00
Damien George
318f874cda extmod/modlwip: In ioctl handle case when socket is in an error state.
Using MP_STREAM_POLL_HUP for ERR_RST state follows how *nix handles this
case.
2018-05-04 15:15:04 +10:00
Damien George
12a3fccc7e esp32/modsocket: Check for pending events during blocking socket calls. 2018-05-03 00:09:25 +10:00
Damien George
5936168150 extmod/uzlib: Fix C-language sequencing error with uzlib_get_byte calls.
The order of function calls in an arithmetic expression is undefined and so
they must be written out as sequential statements.

Thanks to @dv-extrarius for reporting this issue, see issue #3690.
2018-05-02 23:16:22 +10:00
Damien George
4fa7d36cee esp32: Use mp_rom_map_elem_t and MP_ROM_xxx macros for const dicts. 2018-05-02 22:33:41 +10:00