Otherwise there is really nothing that can be done, it can't be unlocked by
the user because there is no way to allocate memory to execute the unlock.
See issue #4205 and #4209.
This patch in effect renames MICROPY_DEBUG_PRINTER_DEST to
MICROPY_DEBUG_PRINTER, moving its default definition from
lib/utils/printf.c to py/mpconfig.h to make it official and documented, and
makes this macro a pointer rather than the actual mp_print_t struct. This
is done to get consistency with MICROPY_ERROR_PRINTER, and provide this
macro for use outside just lib/utils/printf.c.
Ports are updated to use the new macro name.
Current adoption on top of nrfx only reads the GPIO->IN register.
In order to read back an output state, nrf_gpio_pin_out_read has
to be called.
This patch concatinate the two read functions such that, if
either IN or OUT register has a value 1 it will return this,
else 0.
Updating lib/nrfx submodule to latest version of master to get
the new GPIO API to read pin direction.
(nrfx: d37b16f2b894b0928395f6f56ca741287a31a244)
Summarized this squashed PR replaces the hal/ folder in the port. This has been replaced the official
HAL layer from Nordic Semiconductor; https://github.com/NordicSemiconductor/nrfx.
A Git submodule has been added under lib/nrfx, for the nrfx dependency.
The drivers / modules has been updated to use this new HAL layer; nrfx at v1.0.0.
Also, header files and system files for nrf51/nrf52x chip variants has been deleted from the device/ folder, only keeping back the startup files written in C. All other files are now fetched from nrfx.
3 new header files in the ports/nrf/ folder has been added to configure nrfx (nrfx_config.h), logging (nrfx_log.h) and glue nrfx together with the drivers and modules from micropython (nrfx_glue.h).
The PR has been a joint effort from @aykevl (Ayke van Laethem) and @glennrub.
For reference, the commit log will be kept to get an overview of the changes done:
* ports/nrf: Initial commit for moving hal to Nordic Semiconductor BSD-3 licensed nrfx-hal.
* ports/nrf: Adding nrfx, Nordic Semiconductor BSD-3 hal layer, as git submodule checked out at lib/nrfx.
* ports/nrf/modules/machine/uart: Fixing bug which set hwfc to parity excluded, always resulting in no flow control, hence corrupted output. Also adding an extra loop on uart_tx_char to prevent any tx when any ongoing tx is in progress.
* ports/nrf/i2c: Moving I2C over to nrfx driver.
* ports/nrf/modules/machine/i2c: Alignment. Renaming print function param 'o' to 'self_in'
* ports/nrf/spi: Updating SPI machine module to use nrfx drivers.
* ports/nrf: Renaming modules/machine/rtc.c/.h to rtcounter.c/.h to not confuse the peripheral with Real-Time Clock:
* ports/nrf: Updating various files after renaming machine module RTC to RTCounter.
* ports/nrf: Renaming RTC to RTCounter in modmachine globals dict table. Also updating object type name to reflect new module name.
* ports/nrf: Fixing leftovers after renaming rtc to rtcounter.
* ports/nrf: Early untested adoption of nrfx_rtc in RTCounter. Untested.
* nrf/modules/machine/i2c: Improve keyword argument handling
* ports/nrf/modules/temp: Updating Temp machine module to use nrfx defined hal nrf_temp.h. Moving logic of BLE stack awareness to machine module.
* ports/nrf/boards/pca10040: Enable machine Temp module.
* nrf/modules/machine/rtcounter: Remove magic constants.
* ports/nrf: Adding base support for nrfx module logging. Adding option to disable logging of UART as it might log its own setup over UART while the peripheral is not yet set up. Logging of UART could make sense if other transport of log is used.
* ports/nrf: updating nrfx_log.h with more correct parenthisis on macro grouping.
* ports/nrf: Updating nrfx logging with configuration to disable logging of UART module. The pattern can be used to turn off other modules as well. However, for now UART is the only module locking itself by logging before the peripheral is configured. Logging is turned off by default, can be enabled in nrfx_config.h by setting NRFX_LOG_ENABLED=1.
* ports/nrf/modules/random: Updating modrandom to use nrfx hal for rng. Not using nrfx-driver for this peripheral as its blocking mode would do the trick on RNG. Moving softdevice aware code from legacy hal to modrandom.c.
* nrf: Enable Peripheral Resource Sharing.
This enables TWI and SPI to be enabled at the same time.
* nrf/Makefile: Define MCU sub variant (e.g. NRF51822/NRF51422)
* nrf: Port TIMER peripheral to nrfx HAL.
* nrf/modules/machine/uart: Optimize UART module
For a nRF51, this results in a size reduction of:
.text: -68 bytes
.data: -56 bytes
* nrf/modules/machine/uart: Don't use magic index numbers.
* nrf/modules/machine/uart: Fix off-by-one error.
For nrf51:
.text: -40 bytes
* nrf/modules/machine/rtcounter: Update for nrfx HAL.
* nrf/modules/machine/i2c: Reduce RAM consumption.
Reductions for the nrf51:
flash: -108 bytes
RAM: -72 bytes
* nrf/mpconfigport: Avoid unnecessary root pointers.
This saves 92 bytes of RAM.
* nrf: Support SoftDevice with nrfx HAL.
* nrf: Add NVMC peripheral (microbitfs) support.
There is no support yet for a SoftDevice.
It also fixes a potentially serious bug in start_index generation.
* nrf/modules/machine/spi: Optimize SPI peripheral.
nrf51:
text: -340 bytes
data: -72 bytes
nrf52:
text: -352 bytes
data: -108 bytes
* nrf/modules/random: Forgot to commit header file.
* nrf: Make nrfx_config.h universal for all boards.
* nrf: Use SoftDevice API for flash access when built for SD
* nrf/drivers/bluetooth: Remove legacy HAL driver includes.
These were not used anymore so can be removed.
* ports/nrf/microbit: Port microbit targets to nrfx HAL
Initial port of microbit modules to use nrfx HAL layer.
Tested display/image and modmusic on micro:bit to verify that
softpwm and ticker for nrf51 is working as expected.
Changing IRQ priority on timer to priority 2, as 1 might collide if
used side by side of SD110 BLE stack.
The patch reserves Timer1 peripheral compile time. This is not ideal
and should be resolved in seperate task.
* nrf/boards/microbit: Remove custom nrfx_config.h from microbit target, adding disablement of timer1 if softpwm is enabled.
* nrf/adc: Update ADC module to use nrfx
* nrf/modules/machine/pwm: Updating machine PWM module to use nrfx HAL driver.
examples/nrf52_pwm.py and examples/nrf52_servo.py tested on pca10040.
* nrf: Removing hal folder and boards nrf5x_hal_conf.h headers.
* nrf/nrfx_glue: Adding direct NVIC access for S110 BLE stack
If SoftDevice s110 has not yet been initialized, the IRQ will not be forwarded to
the application using the sd_nvic* function calls. Hence, direct access to cmsi
nvic functions are used instead if SoftDevice is not enabled.
* nrf/drivers/ticker: Setting IRQ priority 3 on Timer1
SoftDevice fails to initilize if Timer1 has been configured to priority
level 2 before enabling the SD. The timer is set to priority 1, higher than BLE
stack in order to provide better quality of music rendering when used with the
music module. This might be too high, time will show.
* nrf/examples: Updating ubluepy_temp after moving RTCounter to nrfx.
* nrf: delete duplicate files from device folder which can be located in nrfx/mdk.
* nrf/Makefile: Fetch system files from nrfx.
Testing on each device sub-variant to figure out which system file to
use. Reason for this is that nrf52.c is actually defining nrf52832.
Removing NRF_DEFINES parameter setting the device in use into the
same sub-variant test, as NRF52 is unique to nrf52832 when using nrfx.
Without this exclusion of -DNRF52 in compilation for nrf52840, the
device will be interpreted as a nrf52, hence nrf52832.
Also, changing name on variable SRC_NRF_HAL to SRC_NRFX_HAL to
explicitly tell the origin of the file.
* nrf: Updating device #ifdefs to be more open to non-nrf51 targets.
* nrf/modules/machine/uart: Removing second instance of UART for nrf52840 as it only has one non-DMA variant.
* nrf/device: Removing system files as these are now used from nrfx/mdk
* nrf: Moving startup files in device one level up as there is no need for deep hierarchy.
* nrf: Use NRF52_SERIES defined in nrfx/mdk/nrf.h as define value when testing for both nrf52(832) and nrf52840 variants.
* nrf/modules/machine/uart: Enable UART RX by default
Enable rx by default after intiialization of the peripheral.
Else, the nrfx driver will re-enable rx for each byte read
on uart REPL, clearing the EVENT_RXDRDY before second byte,
which again will make second byte get lost and read will get stuck.
This happens if the bytes are transmitted nrf(51) while still
processing the previous byte. Not seen on nrf52, but should
also become an issue at higher speeds.
This patch sets rx to always be enabled. Hence, not clearing the event
between read bytes, and it will be able to detect next byte recieved
upon finishing the first.
* nrf/modules/machine/timer: Fixing defines excluding Timer1 if ticker/softpwm is used.
* nrf: Switching import form mpconfigboard.h to mpconfigport.h in nrfx_config.h as mpconfigboard.h might define default values for defines not set by board specific header.
* nrf/modules/machine/i2c: nrfx integration fixes
Increasing speed to 400K.
Returning Address NACK's as MP error code; MP_ENODEV.
Returning MP_ETIMEOUT on all other error codes from TWI nrfx driver
except the ANACK.
Enabling and disabling the TWI peripheral before and after each transaction.
* nrf/examples: Updating ssd1306_mod.py to split framebuffer transfer into multiple chunks
* nrf/modules/machine/i2c: Return MP_EIO error if Data NACK occurs.
* nrf: Addressing review comments.
* nrf: Updating git submodule and users to nrfx v1.0.0.
* nrf/modules/machine/adc: Update adc module to follow v1.0.0 nrfx API.
* nrf/modules/machine/spi: Implement init and deinit functions
Extending SPI objects with a config member such that
configuration can be kept between new() and init().
Moving initialization done in new() to common init
function shared between the module functions.
If SPI is already configured, the SPI peripheral will
be uninitialized before initalized again.
Adding logic to handle initialization of polarity and
phase. As well, updating default speed to 1M from 500K.
* nrf/modules/machine: Removing unused nrfx includes in machine module header files
The patch enables the possibility to disable or initialize the repl
info from outside of the module. Can also be used to initialize the
repl_display_debugging_info in pyexec.c if not startup file is clearing
.bss segment.
The definition of DEBUG_printf doesn't depend on
MICROPY_USE_INTERNAL_PRINTF so move it out of that preprocessor
block and compile it conditionally just depending on the
MICROPY_DEBUG_PRINTERS macro. This allows a port to use DEBUG_printf
while providing it's own printf definition.
tinytest is written with the idea that tests won't write to stdout, so it
prints test name witjout newline, then executes test, then writes status.
But MicroPython tests write to stdout, so the test output becomes a mess.
So, instead print it like:
# starting basics/andor.py
... test output ...
basics/andor.py: OK
Tinytest is classical assert-style framework, but MicroPython tests work
in different way - they produce content, and that content should be matched
against expected one to see if test passes. upytesthelper exactly adds
helper functions to make that possible.
This patch simplifies the str creation API to favour the common case of
creating a str object that is not forced to be interned. To force
interning of a new str the new mp_obj_new_str_via_qstr function is added,
and should only be used if warranted.
Apart from simplifying the mp_obj_new_str function (and making it have the
same signature as mp_obj_new_bytes), this patch also reduces code size by a
bit (-16 bytes for bare-arm and roughly -40 bytes on the bare-metal archs).
Header files that are considered internal to the py core and should not
normally be included directly are:
py/nlr.h - internal nlr configuration and declarations
py/bc0.h - contains bytecode macro definitions
py/runtime0.h - contains basic runtime enums
Instead, the top-level header files to include are one of:
py/obj.h - includes runtime0.h and defines everything to use the
mp_obj_t type
py/runtime.h - includes mpstate.h and hence nlr.h, obj.h, runtime0.h,
and defines everything to use the general runtime support functions
Additional, specific headers (eg py/objlist.h) can be included if needed.
This upgrades the HAL to the versions:
- F4 V1.16.0
- F7 V1.7.0
- L4 V1.8.1
The main changes were in the SD card driver. The vendor changed the SD
read/write functions to accept block number intead of byte address, so
there is no longer any need for a custom patch for this in stm32lib.
The CardType values also changed, so pyb.SDCard().info() will return
different values for the 3rd element of the tuple, but this function was
never documented.
- Changed: ValueError, TypeError, NotImplementedError
- OSError invocations unchanged, because the corresponding utility
function takes ints, not strings like the long form invocation.
- OverflowError, IndexError and RuntimeError etc. not changed for now
until we decide whether to add new utility functions.
The code conventions suggest using header guards, but do not define how
those should look like and instead point to existing files. However, not
all existing files follow the same scheme, sometimes omitting header guards
altogether, sometimes using non-standard names, making it easy to
accidentally pick a "wrong" example.
This commit ensures that all header files of the MicroPython project (that
were not simply copied from somewhere else) follow the same pattern, that
was already present in the majority of files, especially in the py folder.
The rules are as follows.
Naming convention:
* start with the words MICROPY_INCLUDED
* contain the full path to the file
* replace special characters with _
In addition, there are no empty lines before #ifndef, between #ifndef and
one empty line before #endif. #endif is followed by a comment containing
the name of the guard macro.
py/grammar.h cannot use header guards by design, since it has to be
included multiple times in a single C file. Several other files also do not
need header guards as they are only used internally and guaranteed to be
included only once:
* MICROPY_MPHALPORT_H
* mpconfigboard.h
* mpconfigport.h
* mpthreadport.h
* pin_defs_*.h
* qstrdefs*.h
These implementations are incorrect (eg f2d and d2f don't handle special
values like 0.0) and proper versions can be provided by libgcc (or
equivalent depending on the toolchain).
libgcc is now linked with the stmhal port so that library will provide
these functions from now on.
This follows the pattern of how all other headers are now included, and
makes it explicit where the header file comes from. This patch also
removes -I options from Makefile's that specify the mp-readline/timeutils/
netutils directories, which are no longer needed.
Ports should no longer use pyhelp_print_obj but instead should define
MICROPY_PY_BUILTINS_HELP to 1 and then specify their help text using
MICROPY_PY_BUILTINS_HELP_TEXT.
This happens with some compilers on some architectures, which don't define
size_t as unsigned int. MicroPython's printf() dooesn't support obscure
format specifiers for size_t, so the obvious choice is to explicitly cast
to unsigned, to match %u used in printf().
In order to have more fine-grained control over how builtin functions are
constructed, the MP_DECLARE_CONST_FUN_OBJ macros are made more specific,
with suffix of _0, _1, _2, _3, _VAR, _VAR_BETEEN or _KW. These names now
match the MP_DEFINE_CONST_FUN_OBJ macros.
Now there is just one function to allocate a new vstr, namely vstr_new
(in addition to vstr_init etc). The caller of this function should know
what initial size to allocate for the buffer, or at least have some policy
or config option, instead of leaving it to a default (as it was before).
"Forced exit" is treated as soft-reboot (Ctrl+D). But expected effect of
calling sys.exit() is termination of the current script, not any further
and more serious actions like mentioned soft reboot.
This new config option allows to control whether MicroPython uses its own
internal printf or not (if not, an external one should be linked in).
Accompanying this new option is the inclusion of lib/utils/printf.c in the
core list of source files, so that ports no longer need to include it
themselves.
Helpful when porting existing C libraries to MicroPython. abort()ing in
embedded environment isn't a good idea, so when compiling such library,
-Dabort=abort_ option can be given to redirect standard abort() to this
"safe" version.
gcc 6.1.1 warns when indentation is misleading, and in this case the
formatting of the code really is misleading. So adjust the formatting
to be clear of the meaning of the code.
From https://github.com/pfalcon/berkeley-db-1.xx, which so far contains
pristine 1.85, but will get patches and compile warning fixes going
forward.
Berkeley DB 1.xx is BSD-licensed, and will form the basis of "btree"
simple database module.
Several ports use identical code for the 1-argument form of the builtin
help function. Move this code to a library function to allow easier
re-use by ports.
A port which uses lib/utils/pyexec.c but which does not enable garbage
collection should not need to implement the gc_collect function.
This patch also moves the gc_collect call to after printing the qstr
info. Since qstrs cannot be collected it should not make any difference
to the printed statistics.
The config variable MICROPY_MODULE_FROZEN is now made of two separate
parts: MICROPY_MODULE_FROZEN_STR and MICROPY_MODULE_FROZEN_MPY. This
allows to have none, either or both of frozen strings and frozen mpy
files (aka frozen bytecode).
Before this change, if REPL blocked executing some code, it was possible
to still input new statememts and excuting them, all leading to weird,
and portentially dangerous interaction.
TODO: Current implementation may have issues processing input accumulated
while REPL was blocked.
If MICROPY_FATFS_MAX_SS is defined to power of 2 value between 1024 and
4096, support for dynamic sector size in FatFs will be enabled. Note
that FatFs reserves static buffer of MICROPY_FATFS_MAX_SS size for each
filesystem in use, so that value should be set sparingly.
Initial patch provided by @pfalcon.
This is a convenience function similar to pyexec_file. It should be used
instead of raw mp_parse_compile_execute because the latter does not catch
and report exceptions.
In other words, unix port now uses overriden printf(), instead of using
libc's. This should remove almost all dependency on libc stdio (which
is bloated).
- A single ffcon.h file to configure fatfs settings across ports.
- A single diskio.h file with common drive definitions.
- Removed now reduntand ffconf_template.h.
This patch allows you to stop auto-indent by pressing enter on a second
blank line. Easier than having to use backspace, and prevents new users
from getting stuck in auto-indent mode.
py/mphal.h contains declarations for generic mp_hal_XXX functions, such
as stdio and delay/ticks, which ports should provide definitions for. A
port will also provide mphalport.h with further HAL declarations.
If VT100 support is not available then a given implementation of
mp_hal_erase_line_from_cursor might need to know the number of characters
to erase.
This patch does not change generated code when VT100 is supported, since
compiler can optimise away the argument.
This allows to build libffi from source together with micropython, and is
useful for cross-compilation. Support for this was already merged
previously, to use:
make libffi
make MICROPY_STANDALONE=1
(To both commands appropriate cross-compilition flags can be added).
Use CTRL-E to enter paste mode. Prompt starts with "===" and accepts
all characters verbatim, echoing them back. Only control characters are
CTRL-C which cancels the input and returns to normal REPL, and CTRL-D
which ends the input and executes it. The input is executed as though
it were a file. The input is not added to the prompt history.
4 spaces are added at start of line to match previous indent, and if
previous line ended in colon.
Backspace deletes 4 space if only spaces begin a line.
Configurable via MICROPY_REPL_AUTO_INDENT. Disabled by default.
In particular, dates prior to Mar 1, 2000 are screwed up.
The easiest way to see this is to do:
>>> import time
>>> time.localtime(0)
(2000, 1, 1, 0, 0, 0, 5, 1)
>>> time.localtime(1)
(2000, 1, 2, 233, 197, 197, 6, 2)
With this patch, we instead get:
>>> import time
>>> time.localtime(1)
(2000, 1, 1, 0, 0, 1, 5, 1)
Doh - In C % is NOT a modulo operator, it's a remainder operator.
Can complete names in the global namespace, as well as a chain of
attributes, eg pyb.Pin.board.<tab> will give a list of all board pins.
Costs 700 bytes ROM on Thumb2 arch, but greatly increases usability of
REPL prompt.