Commit Graph

111 Commits

Author SHA1 Message Date
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
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
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
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