Commit Graph

717 Commits

Author SHA1 Message Date
Damien George
321d75e087 esp8266/modnetwork: Automatically do radio sleep if no interface active.
Reduces current of device by about 55mA when radio is sleeping.
2018-12-01 17:20:05 +11:00
Damien George
9e2dd93145 esp8266/ets_alt_task: Process idle callback if no other events occurred. 2018-12-01 17:20:05 +11:00
Damien George
485514f57a esp32: Allocate task TCB and stack from system heap not uPy heap.
This is necessary for two reasons: 1) FreeRTOS still needs the TCB data
structure even after vPortCleanUpTCB has been called, so this latter hook
function cannot free the TCB, and there is no where else to safely delete
it (this behaviour has changed recently in the ESP IDF); 2) when using
external SPI RAM the uPy heap is in this external memory but the task stack
must be allocated from internal SRAM.

Fixes issue #3904.
2018-11-28 15:00:45 +11:00
Damien George
0233049b79 esp32/mpthreadport: Prevent deadlocks when deleting all threads.
vTaskDelete now immediately calls vPortCleanUpTCB, which requires the
thread_mutex mutex, so vTaskDelete must be called after this mutex is
released.
2018-11-28 14:30:11 +11:00
Damien George
afd1ce0c15 stm32/powerctrl: Disable IRQs during stop mode to allow reconfig on wake 2018-11-28 12:44:54 +11:00
Damien George
66ca8e9b2c stm32/powerctrl: Move (deep)sleep funcs from modmachine.c to powerctrl.c 2018-11-28 12:22:20 +11:00
Damien George
3a723ad2fe stm32/usb: Fully deinitialise USB periph when it is deactivated. 2018-11-28 12:06:47 +11:00
Damien George
5f67b03e99 stm32/servo: Only initialise TIM5 if it is needed, to save power. 2018-11-28 12:06:24 +11:00
Paul Sokolovsky
80aca27a40 unix/modos: Rename unlink to remove to be consistent with other ports.
We standardized to provide uos.remove() as a more obvious and user-friendly
name.  That's what written in the docs.  The Unix port implementation
predates this convention, so update it now.
2018-11-26 23:27:04 +11:00
Michael Paul Coder
fe452afab2 stm32/flashbdev: Add missing include for irq.h.
This is required for mboot to build.
2018-11-26 16:34:13 +11:00
Tobias Badertscher
9acc32b40f stm32/adc: Add ADC auto-calibration for L4 MCUs.
This increases the precision of the ADC.
2018-11-26 16:16:29 +11:00
Damien George
51482ba925 README: Remove references to "make axtls", it's no longer needed.
Since 0be2ea50e9 axtls is automatically built
as part of the usual "make" build process.
2018-11-15 14:48:17 +11:00
roland
30ed2b3cab stm32/system_stm32: Introduce configuration defines for PLL3 settings.
A board must be able to set the PLL3 values based on the HSE that it uses.
2018-11-01 13:25:47 +11:00
Damien George
746dbf78d3 py/py.mk: When building axtls use -Wno-all to prevent all warnings.
Building axtls gives a lot of warnings with -Wall enabled, and explicitly
disabling all of them cannot be done in a way compatible with gcc and
clang, and likely other compilers.  So just use -Wno-all to prevent all of
the extra warnings (in addition to the necessary -Wno-unused-parameter,
-Wno-uninitialized, -Wno-sign-compare and -Wno-old-style-definition).

Fixes issue #4182.
2018-10-27 23:53:08 +11:00
Paul m. p. P
454cca6016 py/objmodule: Implement PEP 562's __getattr__ for modules.
Configurable via MICROPY_MODULE_GETATTR, disabled by default.  Among other
things __getattr__ for modules can help to build lazy loading / code
unloading at runtime.
2018-10-23 11:22:50 +11:00
Paul Sokolovsky
5a91fce9f8 py/objstr: Make str.count() method configurable.
Configurable via MICROPY_PY_BUILTINS_STR_COUNT.  Default is enabled.
Disabled for bare-arm, minimal, unix-minimal and zephyr ports.  Disabling
it saves 408 bytes on x86.
2018-10-22 22:49:05 +11:00
Eric Poulsen
3c6f639aa5 esp32/network_ppp: Add PPPoS functionality.
This commit adds network.PPP(stream) which allows to create a TCP/IP
network interface over a stream object (eg a UART).
2018-10-19 23:32:02 +11:00
Eric Poulsen
5e5aef53fb esp32/modesp32: Add hall_sensor() function. 2018-10-19 17:28:02 +11:00
Paul Sokolovsky
6ddcfe68b8 unix/Makefile: Allow to override/omit pthread lib name.
For example, on Android, pthread functions are part of libc, so LIBPTHREAD
should be empty.
2018-10-19 17:22:37 +11:00
Damien George
d2c5496894 stm32/boards/stm32h743.ld: Fix total flash size, should be 2048k.
Fixes issue #4240.
2018-10-17 15:29:56 +11:00
iabdalkader
f0db1a5ab1 stm32/spi: Fix calculation of SPI clock source on H7 MCUs. 2018-10-17 15:26:26 +11:00
Paul Sokolovsky
6c5b2bded2 unix/modffi: Add support for "q"/"Q" specs (int64_t/uint64_t). 2018-10-17 15:17:05 +11:00
Paul Sokolovsky
0c18633ea9 unix/modusocket: Finish socket.settimeout() implementation.
1. Return correct error code for non-blocking vs timed out socket
(POSIX returns EAGAIN for both, we want ETIMEDOUT in case of timed
out socket). To achieve this, blocking/non-blocking flag is added
to the mp_obj_socket_t, to avoid issuing fcntl() syscall each time
EAGAIN occurs. (mp_obj_socket_t used to be 8 bytes, having some room
in a standard 16-byte alloc block.)

2. Handle socket.settimeout(0) properly - in Python, that means
non-blocking mode, but SO_RCVTIMEO/SO_SNDTIMEO of 0 is infinite
timeout.

3. Overall, make sure that socket.settimeout() call switches blocking
state as expected.
2018-10-17 14:19:06 +11:00
Danielle Madeley
80a25810f9 unix/modusocket: Initial implementation of socket.settimeout(). 2018-10-17 14:19:06 +11:00
Damien George
0f6f86ca49 stm32/usbd_cdc_interface: Refactor USB CDC tx code to not use SOF IRQ.
Prior to this commit the USB CDC used the USB start-of-frame (SOF) IRQ to
regularly check if buffered data needed to be sent out to the USB host.
This wasted resources (CPU, power) if no data needed to be sent.

This commit changes how the USB CDC transmits buffered data:
- When new data is first available to send the data is queued immediately
  on the USB IN endpoint, ready to be sent as soon as possible.
- Subsequent additions to the buffer (via usbd_cdc_try_tx()) will wait.
- When the low-level USB driver has finished sending out the data queued
  in the USB IN endpoint it calls usbd_cdc_tx_ready() which immediately
  queues any outstanding data, waiting for the next IN frame.

The benefits on this new approach are:
- SOF IRQ does not need to run continuously so device has a better chance
  to sleep for longer, and be more responsive to other IRQs.
- Because SOF IRQ is off, current consumption is reduced by a small amount,
  roughly 200uA when USB is connected (measured on PYBv1.0).
- CDC tx throughput (USB IN) on PYBv1.0 is about 2.3 faster (USB OUT is
  unchanged).
- When USB is connected, Python code that is executing is slightly faster
  because SOF IRQ no longer interrupts continuously.
- On F733 with USB HS, CDC tx throughput is about the same as prior to this
  commit.
- On F733 with USB HS, Python code is about 5% faster because of no SOF.

As part of this refactor, the serial port should no longer echo initial
characters when the serial port is first opened (this only used to happen
rarely on USB FS, but on USB HS is was more evident).
2018-10-15 15:37:01 +11:00
Damien George
53ccbe6cec stm32/usbd_cdc_interface: Handle disconnect IRQ to set VCP disconnected.
pyb.USB_VCP().isconnected() will now return False if the USB is
disconnected after having previously been connected.

See issue #4210.
2018-10-15 12:24:40 +11:00
Glenn Ruben Bakke
11bc38d55f nrf/bluetooth: Set GAP_ADV_MAX_SIZE to 31 (s132/s140).
For s132 and s140, GAP_ADV_MAX_SIZE was currently set to
BLE_GATT_ATT_MTU_DEFAULT, which is 23. The correct value
should have been 31, but there are no define for this in
the s132/s140 header files as for s110.

Updating define in ble_drv.c to the correct value of 31.
2018-10-11 23:38:11 +02:00
Andrew Leech
338635ccc6 stm32/main: Add configuration macros for board to set heap start/end.
The macros are MICROPY_HEAP_START and MICROPY_HEAP_END, and if not defined
by a board then the default values will be used (maximum heap from SRAM as
defined by linker symbols).

As part of this commit the SDRAM initialisation is moved to much earlier in
main() to potentially make it available to other peripherals and avoid
re-initialisation on soft-reboot.  On boards with SDRAM enabled the heap
has been set to use that.
2018-10-05 17:30:18 +10:00
stijn
02ca8d4674 windows/msvc: Implement file/directory type query.
Add some more POSIX compatibility by adding a d_type field to the
dirent structure and defining corresponding macros so listdir_next
in the unix' port modos.c can use it, end result being uos.ilistdir
now reports the file type.
2018-10-05 17:14:33 +10:00
stijn
397ee7c00e windows/msvc: Fix incorrect indentation in dirent.c. 2018-10-05 17:14:33 +10:00
Paul Sokolovsky
b9bad7ff92 unix/moduselect: Raise OSError(ENOENT) if obj to modify is not in poller
Previously, the function silently succeeded. The new behavior is consistent
with both baremetal uselect implementation and CPython 3.
2018-10-05 16:56:43 +10:00
Damien George
bbccb0f630 esp8266: Remove scanning of GC pointers in native code block.
The native code no longer holds live GC pointers so doesn't need to be
scanned.
2018-09-27 23:46:09 +10:00
Paul Sokolovsky
af2030dec6 unix/mpconfigport.h: Enable MICROPY_PY_UHASHLIB_MD5 for uhashlib.md5.
This will allow to e.g. implement HTTP Digest authentication.

Adds 540 bytes for x86_32, 332 for arm_thumb2 (for Unix port, which already
includes axTLS library).
2018-09-26 15:12:28 +10:00
Damien George
84090edaa3 stm32/mpconfigport.h: Enable math.factorial, optimised version. 2018-09-26 15:05:19 +10:00
Christopher Swenson
8c656754aa py/modmath: Add math.factorial, optimised and non-opt implementations.
This commit adds the math.factorial function in two variants:
- squared difference, which is faster than the naive version, relatively
  compact, and non-recursive;
- a mildly optimised recursive version, faster than the above one.

There are some more optimisations that could be done, but they tend to take
more code, and more storage space.  The recursive version seems like a
sensible compromise.

The new function is disabled by default, and uses the non-optimised version
by default if it is enabled.  The options are MICROPY_PY_MATH_FACTORIAL
and MICROPY_OPT_MATH_FACTORIAL.
2018-09-26 15:03:04 +10:00
Damien George
7b452e7466 stm32/usbd_conf: Allocate enough space in USB HS TX FIFO for CDC packet.
The CDC maximum packet size is 512 bytes, or 128 32-bit words, and the TX
FIFO must be configured to have at least this size.
2018-09-26 12:00:56 +10:00
Damien George
6ea6c7cc9e stm32/powerctrl: Don't configure clocks if already at desired frequency.
Configuring clocks is a critical operation and is best to avoid when
possible.  If the clocks really need to be reset to the same values then
one can pass in a slightly higher value, eg 168000001 Hz to get 168MHz.
2018-09-24 17:34:05 +10:00
Damien George
bc54c57590 stm32/powerctrl: Optimise passing of default values to set_sysclk. 2018-09-24 17:34:05 +10:00
Damien George
dae1635c71 stm32/powerctrl: Factor code that configures PLLSAI on F7 MCUs. 2018-09-24 17:34:05 +10:00
Damien George
90ea2c63a5 stm32/powerctrl: Factor code to set RCC PLL and use it in startup.
This ensures that on first boot the most optimal settings are used for the
voltage scaling and flash latency (for F7 MCUs).

This commit also provides more fine-grained control for the flash latency
settings.
2018-09-24 17:34:05 +10:00
Damien George
9e4812771b stm32/powerctrl: Fix configuring APB1/APB2 frequency when AHB also set.
APB1/APB2 are derived from AHB, so if the user sets AHB!=SYSCLK then the
APB1/APB2 dividers must be computed from the new AHB.
2018-09-24 14:51:17 +10:00
Damien George
dff14c740b stm32/powerctrl: Move function to set SYSCLK into new powerctrl file.
Power and clock control is low-level functionality and it makes sense to
have it in a dedicated file, at least so it can be reused by other parts of
the code.
2018-09-24 14:18:18 +10:00
Damien George
1acf58c08f stm32/modmachine: Re-enable PLLSAI[1] after waking from stop mode.
On F7s PLLSAI is used as a 48MHz clock source if the main PLL cannot
provide such a frequency, and on L4s PLLSAI1 is always used as a clock
source for the peripherals.  This commit makes sure these PLLs are
re-enabled upon waking from stop mode so the peripherals work.

See issues #4022 and #4178 (L4 specific).
2018-09-24 12:55:15 +10:00
Damien George
4df1943948 stm32/boards/NUCLEO_F091RC: Enable USART3-8 with default pins. 2018-09-21 14:04:33 +10:00
Damien George
cdc01408c7 stm32/uart: Add support for USART3-8 on F0 MCUs. 2018-09-21 14:02:54 +10:00
Andrew Leech
84f4d58479 stm32/dcmi: Add F4/F7/H7 hal files and dma definitions for DCMI periph. 2018-09-21 12:12:49 +10:00
Damien George
cb3c66e793 stm32/adc: Increase sample time for internal sensors on L4 MCUs.
They need time (around 4us for VREFINT) to obtain accurate results.

Fixes issue #4022.
2018-09-20 23:51:33 +10:00
Damien George
3220cedc31 stm32/adc: Fix ADC calibration scale for L4 MCUs, they use 3.0V. 2018-09-20 23:50:54 +10:00
Damien George
185716514f esp32/machine_rtc: Fix locals dict entry, init qstr points to init meth. 2018-09-20 17:52:16 +10:00
Damien George
56f275c0a2 stm32/Makefile: Include copysign.c in double precision float builds.
This is required for DEBUG=1 builds when MICROPY_FLOAT_IMPL=double.

Thanks to Andrew Leech.
2018-09-20 16:51:20 +10:00