Wykres commitów

698 Commity (7eb29c200077096a4c6afc2679b35d70068de89d)

Autor SHA1 Wiadomość Data
Damien George b0c8a94b41 stm32/dma: Pass DMA direction as parameter to dma_init not in cfg struct
Some DMA channels (eg for SDIO) can be used in both directions and this
patch allows such peripherals to dynamically select the DMA direction.
2018-09-11 17:18:06 +10:00
Damien George 47550ef2cd stm32: For MCUs that have PLLSAI allow to set SYSCLK at 2MHz increments.
MCUs that have a PLLSAI can use it to generate a 48MHz clock for USB, SDIO
and RNG peripherals.  In such cases the SYSCLK is not restricted to values
that allow the system PLL to generate 48MHz, but can be any frequency.
This patch allows such configurability for F7 MCUs, allowing the SYSCLK to
be set in 2MHz increments via machine.freq().  PLLSAI will only be enabled
if needed, and consumes about 1mA extra.  This fine grained control of
frequency is useful to get accurate SPI baudrates, for example.
2018-09-11 16:42:57 +10:00
roland 67ee4e2401 stm32/boards/STM32L476DISC: Enable external RTC xtal to get RTC working. 2018-09-11 15:23:19 +10:00
Andrew Leech 670a2a3396 stm32/Makefile: Allow external BOARD_DIR directory to be specified.
This makes it easy to add a custom board definition outside of the
micropython tree, keeping the micropython submodule clean and official.
2018-09-11 15:15:21 +10:00
Paul Sokolovsky 5615273bb0 unix/Makefile: Build libffi inside $BUILD.
Avoids polluting the source tree, allows to build for different (sub)archs
without intermediate cleaning.
2018-09-10 11:34:46 +03:00
Damien George 5cd2c7f2e7 esp8266/main: Increase heap by 2kb, now that axtls rodata is in ROM. 2018-09-08 00:09:03 +10:00
Damien George eed83caf1d esp8266/Makefile: Remove build of libaxtls.a and add back tuned config. 2018-09-08 00:07:23 +10:00
Damien George 6ad5355e43 unix/Makefile: Remove building of libaxtls.a which is no longer needed. 2018-09-08 00:07:23 +10:00
Damien George a23719e0ad stm32/mboot/main: Use correct formula for DFU download address.
As per ST's DfuSe specification, and following their example code.
2018-09-05 15:22:05 +10:00
Damien George 5f3016c663 stm32/mboot/Makefile: Use -Wno-attributes for ll_usb.c HAL source file.
A recent version of arm-none-eabi-gcc (8.2.0) will warn about unused packed
attributes in USB_WritePacket and USB_ReadPacket.  This patch suppresses
such warnings for this file only.
2018-09-05 15:21:43 +10:00
Damien George 056e0b6293 stm32/spi: Add implementation of low-level SPI protocol.
Can be used, for example, to configure external SPI flash using a hardware
SPI interface (code to be put in a board's bdev.c file):

    STATIC const spi_proto_cfg_t hard_spi_bus = {
        .spi = &spi_obj[5],
        .baudrate = 10000000,
        .polarity = 0,
        .phase = 0,
        .bits = 8,
        .firstbit = SPI_FIRSTBIT_MSB,
    };

    STATIC mp_spiflash_cache_t spi_bdev_cache;

    const mp_spiflash_config_t spiflash_config = {
        .bus_kind = MP_SPIFLASH_BUS_SPI,
        .bus.u_spi.cs = pin_A0,
        .bus.u_spi.data = (void*)&hard_spi_bus,
        .bus.u_spi.proto = &spi_proto,
        .cache = &spi_bdev_cache,
    };

    spi_bdev_t spi_bdev;
2018-08-14 22:10:43 +10:00
Damien George 01ce2e1682 unix/Makefile: Enable ussl module with nanbox build. 2018-08-14 21:53:06 +10:00
Damien George 8300be6d0f stm32/spi: Split out pyb.SPI and machine.SPI bindings to their own files
The aim here is to have spi.c contain the low-level SPI driver which is
independent (not fully but close) of MicroPython objects and methods, and
the higher-level bindings are separated out to pyb_spi.c and machine_spi.c.
2018-08-14 17:11:07 +10:00
Damien George 48d736f491 esp32: Update to latest ESP IDF.
Among other things, this requires putting bootloader object files in to
their relevant .a archive, so that they can be correctly referenced by the
ESP IDF's linker script.
2018-08-14 16:45:37 +10:00
forester3 02fbb0a455 stm32/boards/STM32F7DISC: Enable onboard SDRAM.
The default SYSCLK frequency is reduced to 192MHz because SDRAM requires it
to be 200MHz or less.
2018-08-14 16:04:10 +10:00
forester3 502c410214 stm32/boards/STM32F429DISC: Add burst len and autorefresh to SDRAM cfg.
To align with recent changes to sdram.c.
2018-08-14 16:03:13 +10:00
forester3 e562f99263 stm32/sdram: Allow additional config by a board, and tune MPU settings.
- Allow configuration by a board of autorefresh number and burst length.
- Increase MPU region size to 8MiB.
- Make SDRAM region cacheable and executable.
2018-08-14 16:00:14 +10:00
Paul Sokolovsky fe1ef507ef unix/Makefile: coverage: Explicitly build "axtls" too.
"coverage" build uses different BUILD directory comparing to the normal
build. Previously, any build picked up libaxtls.a from normal build's
directory, but that was fixed recently. So, for each build, we must
build axtls explicitly.

This fixes Travis build in particular.
2018-08-14 15:10:52 +10:00
stijn 3f9d3e120b windows/msvc: Support custom compiler for header generation.
Use overrideable properties instead of hardcoding the use of the
default cl executable used by msvc toolsets. This allows using
arbitrary compiler commands for qstr header generation.
The CLToolExe and CLToolPath properties are used because they are,
even though absent from any official documentation, the de-facto
standard as used by the msvc toolsets themselves.
2018-08-14 15:07:19 +10:00
Damien George 86e0b25532 stm32/spi: Round up prescaler calc to never exceed requested baudrate.
Requesting a baudrate of X should never configure the peripheral to have a
baudrate greater than X because connected hardware may not be able to
handle higher speeds.  This patch makes sure to round the prescaler up so
that the actual baudrate is rounded down.
2018-08-10 16:39:47 +10:00
David Lechner 3fccd78aca stm32/dma: Fix spelling of "corresponding" in two locations. 2018-08-10 16:26:25 +10:00
Damien George 7be5bb3672 stm32/adc: Fix ADC reading on F0 MCUs to only sample a single channel.
And increase sampling time to get better results for internal channels.
2018-08-04 13:33:02 +10:00
Damien George c62b23094f stm32/adc: Disable VBAT in read channel helper function.
Prior to this patch, if VBAT was read via ADC.read() or
ADCAll.read_channel(), then it would remain enabled and subsequent reads
of TEMPSENSOR or VREFINT would not work.  This patch makes sure that VBAT
is disabled for all cases that it could be read.
2018-08-04 13:25:43 +10:00
Ayke van Laethem e755bd4932
nrf/uart: Fix UART.writechar() to write just 1 byte. 2018-08-02 22:21:24 +02:00
Ayke van Laethem 60a05485cb
nrf/uart: Remove unused UART.char_width field.
Also, clean up some code.
Code size change:
nrf51: -24
nrf52: -28
2018-08-02 22:18:16 +02:00
Stig Bjørlykke 2cf2ad943e nrf: Use separate config for each PWM instance.
The hard_configs table has entries for each PWM instance. Use them.
2018-08-02 20:36:18 +02:00
Damien George da2d2b6d88 py/mpconfig.h: Introduce MICROPY_DEBUG_PRINTER for debugging output.
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.
2018-08-02 14:04:44 +10:00
Stig Bjørlykke 0c161691b4 nrf: Correct index checking of ADC/PWM/RTCounter instances.
Avoid trying to use ADC, PWM and RTCounter instances which is
one past last available, because this will give a HardFault.
2018-08-01 14:56:07 +02:00
Stig Bjørlykke 7f0c5f2ef9 nrf: Enable all PWM, RTC and Timer instances for nrf52840.
The NRF52 define only covers nrf52832, so update the define checks
to use NRF52_SERIES to cover both nrf52832 and nrf52840.

Fixed machine_hard_pwm_instances table in modules/machine/pwm.c

This enables PWM(0) to PWM(3), RTCounter(2), Timer(3) and Timer(4),
in addition to NFC reset cause, on nrf52840.
2018-08-01 14:36:07 +02:00
Stig Bjørlykke b6e49da407
nrf/uos: Add mbfs __enter__ and __exit__ handlers.
This will make 'with open('file', 'r') as f:' work by properly close
the file after the suite is finished.
2018-08-01 14:12:34 +02:00
Damien George 5482d84673 stm32/modmachine: Get machine.sleep working on L4 MCUs.
When waking from stop mode most of the system is still in the same state as
before entering stop, so only minimal configuration is needed to bring the
system clock back online.
2018-08-01 17:14:19 +10:00
Damien George c12348700f stm32/extint.h: Use correct EXTI lines for RTC interrupts. 2018-08-01 17:13:49 +10:00
Damien George 21dae87710 stm32/modmachine: Get machine.sleep working on F0 MCUs. 2018-07-31 17:25:53 +10:00
Damien George 9dfbb6cc16 stm32/rtc: Get rtc.wakeup working on F0 MCUs.
The problem was that the EXTI line for the RTC wakeup event is line 20 on
the F0, so the interrupt was not firing.
2018-07-31 17:24:10 +10:00
Damien George f6f6452b6f stm32/Makefile: Use -Wno-attributes for ll_usb.c HAL source file.
A recent version of arm-none-eabi-gcc (8.2.0) will warn about unused packed
attributes in USB_WritePacket and USB_ReadPacket.  This patch suppresses
such warnings for this file only.
2018-07-30 15:35:05 +10:00
Damien George 90fc7c5cfa stm32/sdcard: Get SDMMC alt func macro names working with F4,F7,H7 MCUs. 2018-07-30 15:33:33 +10:00
Andrew Leech 434975defa stm32/boards/STM32F429DISC: Enable onboard SDRAM. 2018-07-23 23:16:32 +10:00
Andrew Leech 968fa47392 stm32/sdram: On F7 MCUs enable MPU on external SDRAM.
This prevents hard-faults on non-aligned accesses.

Reference: http://www.keil.com/support/docs/3777.htm
2018-07-23 23:15:18 +10:00
Andrew Leech a1db1506a2 stm32/sdram: Integrate SDRAM driver into rest of code.
If SDRAM is configured and enabled for a board then it is used for the
MicroPython GC heap.
2018-07-23 23:14:23 +10:00
Andrew Leech 7ae053abfd stm32/sdram: Add SDRAM driver from OpenMV project.
Taken from 7fbe54ad4e/src/omv/sdram.c

Code is is MIT licensed.
2018-07-23 23:13:24 +10:00
Ayke van Laethem 7067ac3573 nrf/drivers/flash: Fix incorrect page alignment check. 2018-07-23 16:12:33 +10:00
roland 6a31dcd638 nrf: Update nrfjprog links to allow to download any version.
Instead of downloading "a" version, these links point to history from where
you can download the verson you like.
2018-07-23 16:11:40 +10:00
Damien George 6ac4304284 nrf/boards/microbit: Use MICROPY_PY_BUILTINS_FLOAT to detect FP support.
This works for both single and double precision float.
2018-07-20 14:11:28 +10:00
Damien George 9addc38af4 nrf: Properly use (void) instead of () for function definitions. 2018-07-20 14:11:28 +10:00
Damien George 55632af70a nrf/Makefile: Make sure dependencies for pins_gen.c are correct. 2018-07-20 14:11:28 +10:00
Damien George 4201f36a46 stm32/sdcard: Use mp_hal_pin_config_alt_static to configure SD card pins 2018-07-20 14:03:21 +10:00
Andrew Leech 4343c9330e stm32: Add method for statically configuring pin alternate function.
Works with pins declared normally in mpconfigboard.h, eg. (pin_XX), as well
as (pyb_pin_XX).

Provides new mp_hal_pin_config_alt_static(pin_obj, mode, pull, fn_type)
function declared in pin_static_af.h to allow configuring pin alternate
functions by name at compile time.
2018-07-20 14:03:21 +10:00
Damien George ef554ef9a2 unix: Use MP_STREAM_GET_FILENO to allow uselect to poll general objects.
This mechanism will scale to to an arbitrary number of pollable objects, so
long as they implement the MP_STREAM_GET_FILENO ioctl.  Since ussl objects
pass through ioctl requests transparently to the underlying socket object,
it will allow ussl sockets to be polled.  And a user object with uio.IOBase
as a base could support polling.
2018-07-20 13:09:49 +10:00
Peter D. Gray a8736e5c36 stm32/flashbdev: Fix bug with L4 block cache, dereferencing block size.
The code was dereferencing 0x800 and loading a value from there, trying to
use a literal value (not address) defined in the linker script
(_ram_fs_cache_block_size) which was 0x800.
2018-07-19 12:15:34 +10:00
Ayke van Laethem 8df342d330 nrf: Include $(SRC_MOD) in the build.
Also, remove the unused $(SRC_LIB).
2018-07-19 00:35:24 +10:00
Ayke van Laethem 2f0f4fdcd3
nrf: Use mp_raise_ValueError instead of nlr_raise(...)
Saves 60 bytes on the nRF52 with SD disabled. There will be a bigger
saving with SD enabled and/or on the micro:bit board.
2018-07-18 15:25:17 +02:00
Glenn Ruben Bakke 264d80c84e nrf/drivers: Add license text to ticker.h and softpwm.h.
As per the LICENSE and AUTHORS files from the original source of these
header files.
2018-07-18 17:12:26 +10:00
Glenn Ruben Bakke ea00717a57 nrf: Compile nlr objects with -fno-lto flag
To prevent over-optimizations of nlr and nlrthumb when -flto is used
the flag -fno-lto is set on these modules during compilation.
2018-07-18 17:12:26 +10:00
Glenn Ruben Bakke 14d257c66b nrf: Add explicit make flag for oofatfs
Adding MICROPY_FATFS as makefile flag in order to explicitly
include oofatfs files to be compiled into the build.

The flag is set to 0 by default. Must be set in addition to
MICROPY_VFS and MICROPY_VFS_FAT in mpconfigport.h.
2018-07-18 17:12:26 +10:00
Glenn Ruben Bakke 50ee908896 nrf/bluetooth: Replace BLE REPL (WebBluetooth) URL
Updating URL of the WebBluetooth/PhysicalWeb from
https://glennrub.github.io/webbluetooth/micropython/repl to
https://aykevl.nl/apps/nus/.
2018-07-18 17:12:26 +10:00
Glenn Ruben Bakke cf58ef27af nrf: Quick-fix on const objects with open array dimension in objtuples.
Temporarly solving the issue of
"differ from the size of original declaration [-Werror=lto-type-mismatch]
until linker is fixed in upcomming release of gcc.

Bug is reported by others, and will be fixed in next version of arm-gcc.
However, this patch makes it possible to use modmusic and modimage
with current compilers.

Alternativly, the code can be compiled with LTO=0, but uses valuable 9K
more on this already squeezed target (microbit).
2018-07-18 17:12:26 +10:00
Ayke van Laethem 0e5f8425ea nrf/boards: Check for stack/heap size using an assert.
The main effect of this is that the .bss is now accurate and doesn't
include the stack and minimum heap size.
2018-07-18 17:12:26 +10:00
Glenn Ruben Bakke 7144e87ced nrf/bluetooth: Add support for s132/s140 v6, remove s132 v2/3/5
Support added for s132/s140 v6 in linker scripts and boards.
Support removed for s132 v2/3/5.

Download script updated to fetch new stacks and removed the
non-supported ones.

ble_drv.c updated to only handle s110 v8, and s132/s140 v6.

ubluepy updated to continue scanning after each individual scan
report reported to the module to keep old behaviour of the
Scanner class.
2018-07-18 17:12:26 +10:00
Glenn Ruben Bakke db67a5000f nrf: Generalize feather52 target
This patch generalize the feather52 target to be a board without
an in-built Bluetooth stack or bootloader giving all flash memory to
micropython code.

This way the feather52 target can run any supported Bluetooth LE
stack the port supports for other nrf52832 targets. Hence, this
make Makefiles/linker scripts and BLE driver support easier
to maintain in the future.
2018-07-18 17:12:26 +10:00
Glenn Ruben Bakke b7ce2f1460 nrf: Add support for reading output pin state
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)
2018-07-18 17:12:26 +10:00
Glenn Ruben Bakke 6011441342 nrf: Move pyb module to boards module
Cleaning up use of "pyb" module.
Moving the file to a new folder and updating the
makefile accordingly. New module created called
"board" to take over the functionality of the legacy
"pyb" module.

Updating outdated documentation referring to pyb.Pin,
to now point to machine.Pin.
2018-07-18 17:12:26 +10:00
Glenn Ruben Bakke 4a323f8b80 nrf/nrfx_config: Move back nrf52832 to use non-EasyDMA SPI
As EasyDMA variant of SPI(M) might clock out an additional byte
in single byte transactions this patch moves the nrf52832 to
use SPI and not SPIM to get more stable data transactions.

Ref: nrf52832 rev2 errata v1.1, suggested workaround is:
"Use the SPI module (deprecated but still available) or
use the following workaround with SPIM ..."

Current nrfx SPIM driver does not contain this workaround,
and in the meanwhile moving back to SPI fixes the issue.

Also, tabbing the nrfx_config.h a bit to make it more readable.
2018-07-18 17:12:26 +10:00
Glenn Ruben Bakke 5925004da3 nrf/modules/machine/spi: Move enable-guard to prevent wrong includes
This patch moves the check of SPI configuration before
including any SPI header files. As targets might disable SPI
support, current code ends up in including SPIM if not SPI
is configured. Hence, this is why the check whether the module is
enabled should be done before including headers.
2018-07-18 17:12:26 +10:00
Glenn Ruben Bakke 774638e2a9 nrf/boards/feather52: Move phony targets to main Makefile
dfu-gen .PHONY target is run unconditionally as first build
target when included, and might fail if the hex file is not
yet generated.

To prevent this, the dfu-gen and dfu-flash targets are moved
to the main Makefile and only exposed if feather52 is the
defined BOARD.
2018-07-18 17:12:26 +10:00
Glenn Ruben Bakke d3311681a9 nrf: Enable micro:bit FS by default
Update configuration define from
MICROPY_HW_HAS_BUILTIN_FLASH to MICROPY_MBFS.

MICROPY_MBFS will enable the builtin flash as
part of enabling the micro:bit FS.
2018-07-18 17:12:26 +10:00
Ayke van Laethem a4615672d4 nrf/modules/uos/microbitfs: Remove unused uos_mbfs_mount.
It throws an error in GCC 6.3.
2018-07-18 17:12:26 +10:00
Ayke van Laethem 635064c432 nrf/modules/uos/microbitfs: Fix errno defines.
Probably broken after the recent Clang fixes to errno.h.
2018-07-18 17:12:26 +10:00
Ayke van Laethem 1aa9ff9141 nrf/mphalport: Remove divided assembly syntax. 2018-07-18 17:12:26 +10:00
Ayke van Laethem fb17105183 nrf: Remove useless #include <errno.h>. 2018-07-18 17:12:26 +10:00
Ayke van Laethem 17769452d4 nrf/modules/machine/adc: Don't compare -1 to an unsigned number.
Clang warns about this.
2018-07-18 17:12:26 +10:00
Ayke van Laethem 4111206bd5 nrf/Makefile: Refine dead-code elimination parameters.
Clang warns about useless -Wl,--gc-sections passed in CFLAGS.
2018-07-18 17:12:26 +10:00
Ayke van Laethem ab72b5b69c nrf/Makefile: Use C11 instead of Gnu99.
Some constructs require C11 which GCC silently allows.
2018-07-18 17:12:26 +10:00
Ayke van Laethem a6ae950b75 nrf/Makefile: Remove -fstack-usage.
-fstack-usage is not supported by Clang and old GCC versions.
2018-07-18 17:12:26 +10:00
Ayke van Laethem 5fdebe62d3 nrf/Makefile: use "standard" GCC -fshort-enums instead of --short-enums.
Clang understands only -fshort-enums, not --short-enums. As
--short-enums isn't even mentioned in the gcc man page, I think this
alias exists more for backwards compatibility.
2018-07-18 17:12:26 +10:00
Glenn Ruben Bakke 03da4e33fb nrf/bluetooth: Fixes for s132 v5 BLE stack
Removing unused nrf52832_512k_64k_s132_5.0.0.ld.

Adding new linker script s132_5.0.0 following new
linker script scheme.

Updating ble_drv.c to handle de-increment of
outstanding tx packets on hvx for s132 v5.
2018-07-18 17:12:26 +10:00
Glenn Ruben Bakke 58ec23fdf7 nrf/modules/machine/adc: Fix to make adc.c compile for nrf51 targets 2018-07-18 17:12:26 +10:00
Glenn Ruben Bakke 24258cf0b9 nrf: Return immediatly from mp_hal_delay_us if 0us is given
After nrfx 1.0.0 a new macro was introduced to do a common
hardware timeout. The macro function triggers a counter of
retries or a timeout in us. However, in many cases, like in
nrfx_adc.c the timeout value is set to 0, leading to a infinite
loop in mp_hal_delay_us. This patch prevents this from happening.

Path of error:
nrfx_adc.c -> NRFX_WAIT_FOR -> NRFX_DELAY_US -> mp_hal_delay_us.
2018-07-18 17:12:26 +10:00
Glenn Ruben Bakke 63c748bfcc nrf/spi: Allow for external use of new and transfer function.
This patch also opens up for all arguments to be set as positional
arguments such that an external user of the make_new function can set
provide all parameters as positional arguments.
2018-07-18 17:12:26 +10:00
Glenn Ruben Bakke 434bd568fe nrf/adc: Allow for external use of new and value read function. 2018-07-18 17:12:26 +10:00
Glenn Ruben Bakke 3209a13bf5 nrf/modules: Align method to resolve pin object
machine/i2c already uses mp_hal_get_pin_obj which
points to pin_find function in order to locate correct
pin object to use.

The pin_find function was recently updated to also
being able to locate pins based on an integer value,
such that pin number can be used as argument to object
constructors.

This patch modfies and uniforms pin object lookup for
SPI, music and pwm.
2018-07-18 17:12:26 +10:00
Glenn Ruben Bakke 0f7da42c75 nrf/modules/random: Rename port config for RNG
Renaming config for enabling random module with hw
random number generator from MICROPY_PY_HW_RNG to
MICROPY_PY_RANDOM_HW_RNG to indicate which module it
is configuring.

Also, disabling the config by default in mpconfigport.h.

Adding the enable of RNG in all board configs.

Moving ifdef in modrandom, which test for the config being
set, earlier in the code. This is to prevent un-necessary
includes if not needed.
2018-07-18 17:12:26 +10:00
Glenn Ruben Bakke f4382a2885 nrf/boards/wt51822_s4at: Fixes after nrfx and Pin IRQ introduction 2018-07-18 17:12:26 +10:00
Glenn Ruben Bakke 72aacef02e nrf/boards: Remove unused defines from board config headers 2018-07-18 17:12:26 +10:00
Ayke van Laethem 65f8d9a643 nrf/gccollect: Use the SP register instead of MSP.
Using the current stack pointer directly saves 8 bytes of code.
We need the *current* register anyway for GC (which is always MSP).
2018-07-18 17:12:26 +10:00
Ayke van Laethem 013c23712c nrf/drivers/bluetooth/ble_drv: Increase max transfers in progress.
Increase the maximum number of queued notifications from 1 to 6. This
massively speeds up the NUS console - especially when printing large
amounts of text. The reason is that multiple transfers can be done in a
single connection event, in ideal cases 6 at a time.
2018-07-18 17:12:26 +10:00
Glenn Ruben Bakke 67fd67f549 nrf/modules/machine/spi: SPIM (EasyDMA) backend for nrf52x
This patch moves all nrf52 targets to use SPIM backend
for SPI which features EasyDMA. The main benefit of doing
this is to utilize the SPIM3 on nrf52840 which is
EasyDMA only peripheral.
2018-07-18 17:12:26 +10:00
Glenn Ruben Bakke 6e8a605500 nrf/modules/machine/pin: Add support for IRQ on Pin's
This patch ads irq method to the pin object. Handlers
registered in the irq method will be kept as part of the
ROOT_POINTERS.

In order to resolve which pin object is the root of the
IRQ, the pin_find has been extended to also be able to
search up Pin objects based on mp_int_t pin number.
This also implies that the Pin.new API is now also supporting
creation of Pin objects based on the integer value of the
pin instead of old style mandating string name of the Pin.

All boards have been updated to use real pin number from
0-48 instead of pin_Pxx for UART/SPI and music module pins.

UART/SPI/modmusic has also been updated to use pin number
provided directly or look up the Pin object based on the
integer value of the pin (modmusic).

Pin generation has been updated to create a list of pins, where
the board/cpu dicts are now refering to an index in this list
instead of having one const declaration for each pin. This new
const table makes it possible to iterate through all pins generated
in order to locate the correct Pin object.
2018-07-18 17:12:26 +10:00
Glenn Ruben Bakke 864f671744 nrf: Remove port member from Pin object
In order to be able to support GPIO1 port on nrf52840
the port has been removed from the Pin object.

All pins on port1 will now be incrementally on top of
the pin numbers for gpio0. Hence, Pin 1.00 will become
P32, and Pin 1.15 will become P47.

The modification is done to address the new gpio HAL
interface in nrfx, which resolves the port to be
configured base on a multiple of 32.

The patch also affects the existing devices which does
not have a second GPIO port in the way that the
port indication A and B is removed from Pin generation.
This means that the port which was earlier addressed
as PA0 is now P0, and PA31 is P31.

Also, this patch removes the gpio member which earlier
pointed to the perihperal GPIO base address. This is not
needed anymore, hence removed.
2018-07-18 17:12:26 +10:00
Ayke van Laethem 2de65dda22 nrf: Make linker scripts more modular.
With all the variation in chips and boards it's tedious to copy and
redefine linker scripts for every option. Making linker scripts more
modular also opens up more possibilities, like enabling/disabling the
flash file system from the Makefile - or even defining it's size from a
Makefile argument (FS_SIZE=12 for a 12kB filesystem if tight on space).
2018-07-18 17:12:26 +10:00
Ayke van Laethem 375bc31f4b nrf: Enable -g flag by default.
This does not affect binary output, but makes debugging a whole lot
easier.
2018-07-18 17:12:26 +10:00
Ayke van Laethem 1949719e1d nrf/Makefile: Fix .PHONY target.
It must be in uppercase.
2018-07-18 17:12:26 +10:00
Ayke van Laethem 57ca1ecf01 nrf: Fix NUS console when using boot.py or main.py. 2018-07-18 17:12:26 +10:00
glennrub 002f7d1ad7 nrf: Replace custom-HAL with nrfx-HAL
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
2018-07-18 17:12:26 +10:00
Glenn Ruben Bakke 62931398d7 nrf/boards/microbit/modules: Initialize variable in microbit_sleep.
When compiling for microbit with LTO=0, a compiler error occurs due to
'ms' variable in the microbit_sleep function has not been initialized.

This patch initialize the variable to 0.
2018-07-18 17:12:25 +10:00
Ayke van Laethem 3cdecf90e6 nrf: Make LTO configurable via Makefile flag.
LTO messes up debuggability and may cause some other issues.
Additionally, it does not always result in reduced code size.
2018-07-18 17:12:25 +10:00
Glenn Ruben Bakke c486127378 nrf: Improve include of boardmodules.mk
Removing shell commands for checking if boardmodules.mk exists
under boards/<BOARD>/modules folder before including it.

This patch does the equivalent to previous test without using
shell commands. Hence, including the .mk if it exists.

Reference:
https://stackoverflow.com/questions/8346118/check-if-a-makefile-exists-before-including-it
2018-07-18 17:12:25 +10:00
Ayke van Laethem 4231d4311f nrf: Fix stack size in ld script and enable MICROPY_STACK_CHECK.
The nrf51x22_256k_16k_s110_8.0.0.ld had a stack size of only 1kB, which
is way too low. Additionally, the indicated _minimum_stack_size (set at
2kB for that chip) isn't respected.

This commit sets the heap end based on the stack size (heap end = RAM
end - stack size) making it much easier to configure.

Additionally, the stack/heap size of nrf52 chips has been set to a more
sane value of 8kB.
2018-07-18 17:12:25 +10:00
Ayke van Laethem 987381dfa0 nrf: Make machine.UART optional.
Leave it enabled by default on all targets.

This is only possible when using UART-over-BLE (NUS) instead of the
default hardware peripheral. The flash area saved is quite substantial
(about 2.2KB) so this is useful for custom builds that do not need UART.
2018-07-18 17:12:25 +10:00
Glenn Ruben Bakke f679ee2092 nrf/drivers/ble_drv: Fixing sd_ble_enable bug for SD s132 v.2.0.1
Feather52 target which is using SD s132 v.2.0.1 cannot compile
due to variable containing RAM start address is not used.

This patch enables the correct sd_ble_enable variant for this SD.
2018-07-18 17:12:25 +10:00
Ayke van Laethem f907139fab nrf/boards/common.ld: Avoid overflowing the .text region.
Similar commit to this one:
6e56e6269f

When .text + .data oveflow available flash, the linker may not show an
error. This change makes sure .data is included in the size calculation.
2018-07-18 17:12:25 +10:00