Commit Graph

912 Commits

Author SHA1 Message Date
Damien George
6a95e74387 esp32: Use SPIRAM in mem-map mode so all of it can be used for uPy heap.
Also enable CONFIG_SPIRAM_IGNORE_NOTFOUND to allow boards with faulty or
missing SPIRAM to still boot.
2019-02-06 00:10:50 +11:00
Stig Bjørlykke
98f790b03a nrf/timer: Fix disabling Timer 1 when using soft PWM.
Don't exclude the Timer instance 1 entry from machine_timer_obj[] when
using soft PWM. The usage is already checked when creating the Timer,
so just create an empty entry.
2019-02-02 11:15:52 +01:00
Andrew Leech
67689bfd7e stm32/usb: Add flow control option for USB VCP data received from host.
It's off by default and can be enabled at run-time with:

    pyb.USB_VCP().init(flow=pyb.USB_VCP.RTS)
2019-01-31 23:31:26 +11:00
Stig Bjørlykke
63eae33b7b nrf/ticker: Remove duplicate NRFX_IRQ_PRIORITY_SET. 2019-01-31 17:50:10 +11:00
Ayke van Laethem
e8678cd1c9 nrf/pin: Print pull information in Pin.__str__. 2019-01-31 17:38:13 +11:00
Ayke van Laethem
2d293873a6 nrf/pin: Cleanup Pin.__str__ to print relevant information.
Code size change:
nrf51: -44
nrf52: -52
2019-01-31 17:31:58 +11:00
Ayke van Laethem
4e1c2fc831 nrf: Shrink "<peripheral> does not exist" error messages.
Code size reductions:
nrf51: -132
nrf52: -188
2019-01-31 17:26:26 +11:00
Ayke van Laethem
1ba962ff57 nrf/uart: Remove unused machine.UART() parameters.
If needed these parameters can be added back and made functional one at a
time.  It's better to explicitly not support them than to silently allow
but ignore them.
2019-01-31 17:18:23 +11:00
Ayke van Laethem
a293fa3d6d nrf/uart: Use formula instead of switch for baudrate calculation.
This saves a bit of code:
nrf51: -176
nrf52: -152
2019-01-31 17:06:59 +11:00
Paul Sokolovsky
2f5d113fad py/warning: Support categories for warnings.
Python defines warnings as belonging to categories, where category is a
warning type (descending from exception type). This is useful, as e.g.
allows to disable warnings selectively and provide user-defined warning
types.  So, implement this in MicroPython, except that categories are
represented just with strings.  However, enough hooks are left to implement
categories differently per-port (e.g. as types), without need to patch each
and every usage.
2019-01-31 16:48:30 +11:00
Damien George
86f06d6a87 stm32/sdcard: Don't use SD clock bypass on F7 MCUs.
With clock bypass enabled the attached SD card is clocked at the maximum
48MHz.  But some SD cards are unreliable at these rates.  Although it's
nice to have high speed transfers it's more important that the transfers
are reliable for all cards.  So disable this clock bypass option.
2019-01-31 12:49:48 +11:00
Damien George
e5509a910f stm32/mboot: Add option to autodetect the USB port that DFU uses.
Enable in mpconfigboard.h via #define MBOOT_USB_AUTODETECT_USB (1).
Requires MICROPY_HW_USB_FS and MICROPY_HW_USB_HS to be enabled as well.
2019-01-31 12:05:39 +11:00
Damien George
4bed17e786 stm32/boards/stm32f429_af.csv: Fix typos in UART defs Tx->TX and Rx->RX.
Fixes issue #4445.
2019-01-31 01:02:42 +11:00
Damien George
3ff3e96865 esp8266/modmachine: In lightsleep, only waiti if wifi is turned off.
Otherwise the STA interface can't do DTIM sleeping correctly and power
consumption goes up.
2019-01-31 00:05:00 +11:00
Damien George
d5d060ead9 nrf/modmachine: Rename machine.sleep to machine.lightsleep. 2019-01-30 14:15:38 +11:00
Damien George
0a954e0196 cc3200/modmachine: Rename machine.sleep to machine.lightsleep. 2019-01-30 14:15:08 +11:00
Damien George
808dc95ab8 esp8266/modmachine: Implement simple machine.lightsleep function.
Use of "waiti 0" reduces power consumption by about 3mA compared to a
time.sleep_ms call.
2019-01-30 14:05:53 +11:00
Damien George
2911e3554a esp8266/modmachine: Rename machine.sleep to machine.lightsleep.
While keeping machine.sleep as an alias for machine.lightsleep for
backwards compatibility.
2019-01-30 14:05:53 +11:00
Damien George
d7cc92383c esp8266/modmachine: Implement optional time_ms arg to machine.deepsleep. 2019-01-30 14:05:53 +11:00
Damien George
8de17b3d96 esp32/modmachine: Rename machine.sleep to machine.lightsleep.
While keeping machine.sleep as an alias for machine.lightsleep for
backwards compatibility.
2019-01-30 13:00:26 +11:00
Damien George
dadee5fa24 esp32/modsocket: Fix crashes when connect/bind can't resolve given addr.
Fixes issue #4441.
2019-01-30 12:40:50 +11:00
Damien George
38022ddb2c stm32/main: Make board-defined UART REPL use a static object and buffer.
This way the UART REPL does not need the MicroPython heap and exists
outside the MicroPython runtime, allowing characters to still be received
during a soft reset.
2019-01-28 22:56:55 +11:00
Damien George
f431795caf esp32/boards: Use auto xtal freq config instead of default 40MHz.
Auto-detection of the crystal frequency is convenient and allows for a
single binary for many different boards.  But it can be unreliable in
certain situations so in production, for a given board, it's recommended to
configure the correct fixed frequency.
2019-01-28 20:42:12 +11:00
Damien George
5d88272342 esp32/Makefile: Make sure that directory exists for sdkconfig.h. 2019-01-28 20:41:13 +11:00
Damien George
9ac9aa989c esp32/machine_timer: Deinit all active timers on soft reset.
Otherwise they will keep triggering the callback and access invalid data on
the heap.
2019-01-28 16:16:03 +11:00
Damien George
3d49b157b8 esp32: Update to latest ESP IDF using sdkconfig and new ldgen procedure.
Configuration for the build is now specified using sdkconfig rather than
sdkconfig.h, which allows for much easier configuration with defaults from
the ESP IDF automatically applied.  sdkconfig.h is generated using the new
ESP IDF kconfig_new tool written in Python.  Custom configuration for a
particular ESP32 board can be specified via the make variable SDKCONFIG.

The esp32.common.ld file is also now generated using the standard ESP IDF
ldgen.py tool.
2019-01-28 12:44:03 +11:00
Damien George
f59904f799 esp32/Makefile: Put all IDF compenents in .a libs to use IDF ld script.
When the ESP IDF builds a project it puts all separate components into
separate .a library archives.  And then the esp32.common.ld linker script
references these .a libraries by explicit name to put certain object files
in iRAM.

This patch does a similar thing for the custom build system used here,
putting all IDF .o's into their respective .a.  So a custom linker script
is no longer needed.
2019-01-28 12:41:37 +11:00
Damien George
e7ab475276 esp32: Don't put py/scheduler.o in iRAM, it's no longer needed.
ISR's no longer need to be in iRAM, and the ESP IDF provides an option to
specify that they are in iRAM if an application needs lower latency when
handling them.  But we don't use this feature for user interrupts: both
timer and gpio ISR routines are registered without the ESP_INTR_FLAG_IRAM
option, and so the scheduling code no longer needs to be in iRAM.
2019-01-27 16:15:47 +11:00
Damien George
4caf5b2358 stm32/usbdev: Add USB config option for max power drawn by the board.
The new compile-time option is MICROPY_HW_USB_MAX_POWER_MA.  Set this in
the board configuration file to the maximum current in mA that the board
will draw over USB.  The default is 500mA.
2019-01-27 14:02:10 +11:00
Damien George
7d8db42d17 stm32/usbdev: Add USB config option for board being self powered.
The new compile-time option is MICROPY_HW_USB_SELF_POWERED.  Set this
option to 1 in the board configuration file to indicate that the USB device
is self powered.  This option is disabled by default (previous behaviour).
2019-01-27 13:52:43 +11:00
Damien George
c2886868b9 stm32/rtc: Check RTCEN=1 when testing if RTC is already running on boot.
It can be that LSEON and LSERDY are set yet the RTC is not enabled (this
can happen for example when coming out of the ST DFU mode on an F405 with
the RTC not previously initialised).  In such a case the RTC is never
started because the code thinks it's already running.  This patch fixes
this case by always checking if RTCEN is set when booting up (and also
testing for a valid RTCSEL value in the case of using an LSE).
2019-01-27 13:21:31 +11:00
stijn
42863830be py: Add optional support for 2-argument version of built-in next().
Configurable via MICROPY_PY_BUILTINS_NEXT2, disabled by default.
2019-01-27 13:01:28 +11:00
Reagan Sanders
51577629b2 cc3200/mods/modussl: Fix ca_certs arg validation in mod_ssl_wrap_socket.
Commit a0d97fe408 changed the argument index
of ca_certs but missed updating one of the references to the new index.
2019-01-27 12:51:34 +11:00
Mikhail Zakharov
18723e9889 unix/mpthreadport: Remove busy wait loop in thread garbage collection.
One can't use pthread calls in a signal handler because they are not
async-signal-safe (see man signal-safety).  Instead, sem_post can be used
to post from within a signal handler and this should be more efficient than
using a busy wait loop, waiting on a volatile variable.
2019-01-27 12:40:10 +11:00
Mikhail Zakharov
1e7b422226 unix/mpthreadport: Cleanup used memory on thread exit. 2019-01-27 12:39:45 +11:00
Mikhail Zakharov
f8c1be85d1 unix/mpthreadport: Add thread deinit code to stop threads on exit.
Free unused memory for threads and cancel any outstanding threads on
interpreter exit to avoid possible segmentaiton fault.
2019-01-27 12:38:23 +11:00
Damien George
285d265eee stm32: Implement machine.lightsleep(). 2019-01-27 11:13:32 +11:00
Damien George
6d480f50ac pic16bit: Update to compile with latest xc16 v1.35 compiler.
This port has been verified to work with these latest changes.
2019-01-25 16:06:13 +11:00
Damien George
da72bb6833 esp32/machine_hw_spi: Make HW SPI objects statically allocated.
This aligns more closely with the hardware, that there are two, fixed HW
SPI peripherals.  And it allows to recreate the HW SPI objects without
error, as well as create them again after a soft reset.

Fixes issue #4103.
2019-01-23 23:47:36 +11:00
Damien George
d82f344f61 esp32/machine_hw_spi: Use separate DMA channels for HSPI and VSPI.
Otherwise only one of HSPI or VSPI can be used at a time.  Fixes
issue #4068.
2019-01-23 23:40:06 +11:00
Matt Trentini
cd52d2c691 esp32/modules/neopixel.py: Change NeoPixel to different default timings.
In order to suit the more common 800KHz by default (instead of 400KHz), and
also have the same behaviour as the esp8266 port.

Resolves #4396.

Note! This is a breaking change. Anyone that has previously used the
NeoPixel class on an ESP32 board may be affected.
2019-01-23 14:22:38 +11:00
Damien George
18d3a5df26 esp8266/esp_mphal: Provide mp_hal_pin_od_high_dht so DHT works reliably.
The original behaviour of open-drain-high was to use the open-drain mode of
the GPIO pin, and this seems to make driving a DHT more reliable.  See
issue #4233.
2019-01-22 00:26:04 +11:00
Damien George
eb446ec227 esp32/Makefile: Use system provided math library rather than uPy one.
The ESP IDF system already provides a math library, and that one is likely
to be better tuned to the Xtensa architecture.  The IDF components are also
tested against its own math library, so best not to override it.  Using the
system provided library also allows to easily switch to double-precision
floating point by changing MICROPY_FLOAT_IMPL to MICROPY_FLOAT_IMPL_DOUBLE.
2019-01-17 16:43:20 +11:00
Damien George
90f86a0197 esp32/machine_pin: Add Pin.off() and Pin.on() methods. 2019-01-16 17:33:56 +11:00
Damien George
36808d4e6a esp8266/main: Activate UART(0) on dupterm for REPL before boot.py runs.
So that the user can explicitly deactivate UART(0) if needed.  See
issue #4314.

This introduces some risk to "brick" the device, if the user disables the
REPL without providing an alternative REPL (eg WebREPL), or any way to
reenable it.  In such a case the device needs to be erased and
reprogrammed.  This seems unavoidable, given the desire to have the option
to use the UART for something other than the REPL.
2019-01-16 17:24:23 +11:00
Damien George
3431ea7205 stm32/main: Make thread and FS state static and exclude when not needed.
Without the static qualifier these objects will be kept by the linker even
if they are unused.  So this patch saves some RAM when these features are
unused by a board.
2019-01-11 01:52:17 +11:00
Damien George
5b66c7b712 stm32/wdt: Make singleton WDT object const so it goes in ROM. 2019-01-11 01:51:57 +11:00
Damien George
f350b640a0 esp32/modsocket: For socket read only release GIL if socket would block.
If there are many short reads to a socket in a row (eg by readline) then
releasing and acquiring the GIL each time will give very poor throughput.
So first poll the socket to see if it has data, and if it does then don't
release the GIL.
2019-01-10 15:46:44 +11:00
Damien George
efe0569c26 esp32/mphalport: When tx'ing to REPL only release GIL if many chars sent
Otherwise, if multiple threads are active, printing data to the REPL may be
very slow because in some cases only one character is output per call to
mp_hal_stdout_tx_strn.
2019-01-10 15:43:47 +11:00
Damien George
b33f108cde stm32/sdcard: Properly reset SD periph when SDMMC2 is used on H7 MCUs. 2018-12-30 01:28:34 +11:00
roland
4d8504425a stm32/modmachine: Fix reset_cause to correctly give DEEPSLEEP on L4 MCU.
Before this fix it returned SOFT_RESET after waking from a deepsleep
(standby).
2018-12-30 01:11:25 +11:00
Damien George
f334816df0 stm32/uart: Make sure user IRQs are handled even with a keyboard intr. 2018-12-30 01:03:22 +11:00
Damien George
7bdbea9a0c stm32/uart: Clear overrun error flag after reading RX data register.
On MCUs other than F4 the ORE (overrun error) flag needs to be cleared
independently of clearing RXNE, even though both are wired to trigger the
same RXNE IRQ.  In the case that an overrun occurred it's necessary to
explicitly clear the ORE flag or else the RXNE interrupt will keep firing.
2018-12-30 00:59:16 +11:00
Damien George
0d860fdcd0 stm32/uart: Always enable global UART IRQ handler on init.
Otherwise IRQs may not be enabled for the user UART.irq() handler.  In
particular this fixes the user IRQ_RXIDLE interrupt so that it triggers
even when there is no RX buffer.
2018-12-29 22:44:41 +11:00
Damien George
a5f7a3022d stm32/uart: Fix uart_rx_any in case of no buffer to return 0 or 1. 2018-12-29 22:43:35 +11:00
Tobias Badertscher
372e7a4dc6 stm32: Implement UART.irq() method with initial support for RX idle IRQ. 2018-12-29 17:21:37 +11:00
Andrew Leech
ce0c581179 stm32/main: Add board config option to enable/disable mounting SD card.
The new option MICROPY_HW_SDCARD_MOUNT_AT_BOOT can now be defined to 0 in
mpconfigboard.h to allow SD hardware to be enabled but not auto-mounted at
boot.  This feature is enabled by default to retain previous behaviour.

Previously, if an SD card is enabled in hardware it is also used to boot
from.  While this can be disabled with a SKIPSD file on internal flash,
this wont be available at first boot or if the internal flash gets
corrupted.
2018-12-22 01:30:47 +11:00
Damien George
0c46419323 windows: Remove remaining traces of old GNU readline support.
GNU readline support for the unix port was removed in
acaa30b604 and in
5e83a75c78, so it's also no longer supported
in the windows port.
2018-12-15 13:54:55 +11:00
Damien George
5146e79490 stm32/boards/NUCLEO_L432KC: Specify L4 OpenOCD config file for this MCU. 2018-12-13 13:45:16 +11:00
Damien George
59f409a787 stm32/boards: Allow OpenOCD stm_flash procedure to accept single FW img.
To support deplop-openocd on target boards that use TEXT0_ADDR only and
have their firmware in a single binary image.
2018-12-13 13:43:10 +11:00
Paul Sokolovsky
fbb8335084 py/objdict: Make .fromkeys() method configurable.
On by default, turned off for minimal/bare-arm. Saves 144 bytes on x86.
2018-12-13 01:20:55 +11:00
Damien George
1db55381b6 stm32/adc: Support 16-bit ADC configuration on H7 MCUs. 2018-12-12 12:51:46 +11:00
Damien George
6cab8daee0 stm32/adc: Increase ADC sampling time for internal sources on H7 MCUs. 2018-12-12 12:51:26 +11:00
Damien George
0555ada277 stm32/adc: Fix calibrated volt/temp readings on H7 by using 16bit scale. 2018-12-12 12:50:37 +11:00
Damien George
1b4031ed64 stm32/extint: Use correct EXTI channels on H7 MCUs for RTC events. 2018-12-12 12:49:23 +11:00
Glenn Ruben Bakke
9e5768a6db nrf/bluetooth: Update BLE stack download script.
Due to new webpages at nordicsemi.com, the download links
for Bluetooth LE stacks were broken.

This patch updates the links to new locations for the current
targets.
2018-12-10 20:42:06 +01:00
Damien George
025d419a77 teensy: Add own uart.h to not rely on stm32's version of the file. 2018-12-10 23:55:11 +11:00
Damien George
dc23978dde stm32/uart: Add ability to have a static built-in UART object.
A static UART is useful for internal peripherals that require a UART and
need to persist outside the soft-reset loop.
2018-12-10 16:21:50 +11:00
Damien George
61ef031687 stm32/uart: Move config of char_width/char_mask to uart.c. 2018-12-10 16:21:50 +11:00
Damien George
6ea45277bf stm32/uart: For UART init, pass in params directly, not via HAL struct.
To provide a cleaner and more abstract C-level interface to the UART.
2018-12-10 16:21:50 +11:00
Damien George
e0c2432503 stm32/uart: Simplify deinit of UART, no need to call HAL.
The HAL just clears UE and then clears all the UART control registers.
2018-12-10 16:21:50 +11:00
Damien George
bc3f0dddac stm32/uart: Remove HAL's UART_HandleTypeDef from UART object struct.
This UART_HandleTypeDef is quite large (around 70 bytes in RAM needed for
each UART object) and is not needed: instead the state of the peripheral
held in its registers provides all the required information.
2018-12-10 16:21:50 +11:00
Damien George
7d7f59d78b stm32/uart: Factor out code to set RX buffer to function uart_set_rxbuf. 2018-12-10 16:21:50 +11:00
Damien George
9690757cca stm32/uart: Rework uart_get_baudrate so it doesn't need a UART handle. 2018-12-10 16:21:50 +11:00
Damien George
524e13b006 stm32/uart: Factor out code from machine_uart.c that computes baudrate. 2018-12-10 16:21:50 +11:00
Damien George
a2271532be stm32: Split out UART Python bindings from uart.c to machine_uart.c. 2018-12-10 16:21:50 +11:00
Damien George
da7355e213 esp32/modmachine: Enable machine.sleep() now that the IDF supports it. 2018-12-06 17:23:27 +11:00
Damien George
9c6c32cc51 esp32/machine_pwm: On deinit stop routing PWM signal to the pin.
Fixes issue #4273.
2018-12-06 17:05:16 +11:00
Damien George
287b02d98a esp32/machine_pwm: Support higher PWM freq by auto-scaling timer res. 2018-12-06 16:43:39 +11:00
Damien George
87623082e3 esp32/machine_uart: Implement UART.sendbreak() method.
The uart_write_bytes_with_break() function requires non-zero data to be
sent before the break, so a standalone break must be synthesised.
2018-12-06 15:40:22 +11:00
boochow
69b7b8fa12 stm32/boards: Add NUCLEO_L432KC board configuration files. 2018-12-06 13:33:29 +11:00
boochow
9d3372bded stm32: Add peripheral support for STM32L432.
The L432 does not have: GPIOD, TIM3, SPI2, ADC dual mode operation, 2-banks
flash.
2018-12-06 13:32:43 +11:00
boochow
1a8baad7ca stm32/boards: Add STM32L432KC chip configuration files.
The pin alternate function information is derived from ST's datasheet
https://www.st.com/resource/en/datasheet/stm32l432kc.pdf
In the datasheet, the line 2 of AF4 includes I2C2 but actually the chip
does not have I2C2 so it is removed.
2018-12-06 13:32:43 +11:00
Damien George
52bec93755 esp8266/machine_uart: Add rxbuf keyword arg to UART constructor/init.
As per the machine.UART documentation, this is used to set the length of
the UART RX buffer.
2018-12-05 23:31:24 +11:00
Damien George
9ddc182ec7 esp32/machine_uart: Add txbuf/rxbuf keyword args to UART construct/init.
As per the machine.UART documentation, these are used to set the length of
the TX and RX buffers.
2018-12-05 16:48:34 +11:00
Damien George
8007d0bd16 stm32/uart: Add rxbuf keyword arg to UART constructor and init method.
As per the machine.UART documentation, this is used to set the length of
the RX buffer.  The legacy read_buf_len argument is retained for backwards
compatibility, with rxbuf overriding it if provided.
2018-12-05 13:24:11 +11:00
Damien George
c6365ffb92 stm32/powerctrl: Add support for standby mode on L4 MCUs.
This maps to machine.deepsleep() which is now supported.
2018-12-05 00:40:05 +11:00
Damien George
a1c81761b1 stm32/mboot: Add documentation for using mboot on PYBv1.x. 2018-12-04 23:48:47 +11:00
Damien George
c040961e91 stm32/boards: Add configuration for putting mboot on PYBv1.x. 2018-12-04 23:48:18 +11:00
Damien George
eed522d69f stm32/mboot: Add support for 4th board LED. 2018-12-04 23:14:30 +11:00
Damien George
13e92e1225 stm32/mboot: Provide led_state_all function to reduce code size. 2018-12-04 23:11:51 +11:00
Damien George
9262f54138 stm32/uart: Always show the flow setting when printing a UART object.
Also change the order of printing of flow so it is after stop (so bits,
parity, stop are one after the other), and reduce code size by using
mp_print_str instead of mp_printf where possible.

See issue #1981.
2018-12-04 19:16:16 +11:00
Damien George
da1d849ad1 stm32,esp8266,cc3200: Use MICROPY_GC_STACK_ENTRY_TYPE to save some RAM. 2018-12-04 18:32:10 +11:00
Damien George
62b4bebf64 esp8266/modnetwork: Wait for iface to go down before forcing power mgmt.
If the STA interface is connected to an AP then it must be fully
disconnected and deactivated before forcing the power management on.
2018-12-04 10:20:45 +11:00
roland
10bddc5c28 stm32/boards/STM32F429DISC: Enable UART as secondary REPL.
The board(s) feature a VCOM through the ST-LINK, this feature is something
to keep around.
2018-12-01 17:30:48 +11:00
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
Damien George
6623d7a88c unix/modjni: Get building under coverage and nanbox builds.
Changes made:
- make use of MP_OBJ_TO_PTR and MP_OBJ_FROM_PTR where necessary
- fix shadowing of index variable i, renamed to j
- fix type of above variable to size_t to prevent comparison warning
- fix shadowing of res variable
- use "(void)" instead of "()" for functions that take no arguments
2018-09-20 16:04:08 +10:00
Paul Sokolovsky
11573fcabd unix/modjni: Update .getiter signature to include mp_obj_iter_buf_t* .
And thus be buildable again.
2018-09-20 16:03:53 +10:00
Andrew Leech
17f7c683d2 stm32: Add support for STM32F765xx MCUs.
This part is functionally similar to STM32F767xx (they share a datasheet)
so support is generally comparable.  When adding board support the
stm32f767_af.csv and stm32f767.ld should be used.
2018-09-20 15:16:03 +10:00
Paul Sokolovsky
2da5d41350 py/objstr: Make % (__mod__) formatting operator configurable.
Default is enabled, disabled for minimal builds. Saves 1296 bytes on x86,
976 bytes on ARM.
2018-09-20 14:41:08 +10:00
Damien George
a5b583adfd stm32/boards/STM32F769DISC: Add optional support for external SDRAM. 2018-09-20 11:42:03 +10:00