Commit Graph

185 Commits

Author SHA1 Message Date
Damien George
ad7213d3c3 py: Add mp_raise_msg_varg helper and use it where appropriate.
This commit adds mp_raise_msg_varg(type, fmt, ...) as a helper for
nlr_raise(mp_obj_new_exception_msg_varg(type, fmt, ...)).  It makes the
C-level API for raising exceptions more consistent, and reduces code size
on most ports:

   bare-arm:   +28 +0.042%
minimal x86:  +100 +0.067%
   unix x64:   -56 -0.011%
unix nanbox:  -300 -0.068%
      stm32:  -204 -0.054% PYBV10
     cc3200:    +0 +0.000%
    esp8266:   -64 -0.010% GENERIC
      esp32:  -104 -0.007% GENERIC
        nrf:  -136 -0.094% pca10040
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
2020-02-13 11:52:40 +11:00
Damien George
97eca38c4f py: Add mp_raise_type helper macro and use it where appropriate.
This provides a more consistent C-level API to raise exceptions, ie moving
away from nlr_raise towards mp_raise_XXX.  It also reduces code size by a
small amount on some ports.
2020-02-13 11:03:37 +11:00
Damien George
580fd636c0 nrf/drivers: Use mp_raise_msg where appropriate, and shorten exc msgs.
If the exception doesn't need printf-style formatting then calling
mp_raise_msg is more efficient.  Also shorten exception messages to match
style in core and other ports.
2020-02-11 11:45:14 +11:00
caochaowu
61f64c78a6 nrf/boards/common.ld: Add ENTRY(Reset_Handler) in linker script.
It's not strictly needed but can be helpful when using a debugger.
2020-02-01 00:09:44 +11:00
Memiks
4ab4bf3ec6 ports: Modify mp_hal_pin_write macro so it can be used as a function.
Even though it doesn't return anything it could still be used like a
function.  Addresses issue #5501.
2020-01-14 23:48:42 +11:00
Tim Gates
007a704d82 nrf/examples: Fix typo in mountsd.py, wireing -> wiring. 2019-12-28 12:07:30 +11:00
Yonatan Goldschmidt
b2e4a57289 nrf/main: Remove unnecessary repl_info(0) call.
It's statically initialized to 0.
2019-12-28 00:08:31 +11:00
Yonatan Goldschmidt
61d2b40ad5 lib/utils/pyexec: Introduce MICROPY_REPL_INFO, wrap debug prints in it.
For the 3 ports that already make use of this feature (stm32, nrf and
teensy) this doesn't make any difference, it just allows to disable it from
now on.

For other ports that use pyexec, this decreases code size because the debug
printing code is dead (it can't be enabled) but the compiler can't deduce
that, so code is still emitted.
2019-12-28 00:05:39 +11:00
David Lechner
e79424d672 ports: Allow overriding CROSS_COMPILE in a custom makefile.
Many ports already allow overriding CROSS_COMPILE.  This modifies the
remaining ports to allow it as well.
2019-12-27 23:53:16 +11:00
Daniel Mizyrycki
2df6a0436d nrf/boards/particle_xenon: Enable USB CDC on Particle Xenon board. 2019-12-09 14:10:24 +11:00
Andrej Krejcir
210d053286 nrf/main: Execute boot.py/main.py frozen modules without a file system.
When the file system is not enabled, the boot.py and main.py modules will
still be executed, if they are frozen.
2019-12-05 23:11:12 +11:00
Damien George
799b6d1e0c extmod: Consolidate FAT FS config to MICROPY_VFS_FAT across all ports.
This commit removes the Makefile-level MICROPY_FATFS config and moves the
MICROPY_VFS_FAT config to the Makefile level to replace it.  It also moves
the include of the oofatfs source files in the build from each port to a
central place in extmod/extmod.mk.

For a port to enabled VFS FAT support it should now set MICROPY_VFS_FAT=1
at the level of the Makefile.  This will include the relevant oofatfs files
in the build and set MICROPY_VFS_FAT=1 at the C (preprocessor) level.
2019-11-11 11:37:38 +11:00
Damien George
c13f9f209d all: Convert nlr_raise(mp_obj_new_exception_msg(x)) to mp_raise_msg(x).
This helper function was added a while ago and these are the remaining
cases to convert, to save a bit of code size.
2019-11-05 11:35:45 +11:00
Damien George
9aabb6c01b extmod: Factor out block-device struct to make independent of fatfs. 2019-10-29 12:12:37 +11:00
Damien George
d2384efa80 py: Automatically provide weak links from "foo" to "ufoo" module name.
This commit implements automatic module weak links for all built-in
modules, by searching for "ufoo" in the built-in module list if "foo"
cannot be found.  This means that all modules named "ufoo" are always
available as "foo".  Also, a port can no longer add any other weak links,
which makes strict the definition of a weak link.

It saves some code size (about 100-200 bytes) on ports that previously had
lots of weak links.

Some changes from the previous behaviour:
- It doesn't intern the non-u module names (eg "foo" is not interned),
  which saves code size, but will mean that "import foo" creates a new qstr
  (namely "foo") in RAM (unless the importing module is frozen).
- help('modules') no longer lists non-u module names, only the u-variants;
  this reduces duplication in the help listing.

Weak links are effectively the same as having a set of symbolic links on
the filesystem that is searched last.  So an "import foo" will search
built-in modules first, then all paths in sys.path, then weak links last,
importing "ufoo" if it exists.  Thus a file called "foo.py" somewhere in
sys.path will still have precedence over the weak link of "foo" to "ufoo".

See issues: #1740, #4449, #5229, #5241.
2019-10-22 15:30:52 +11:00
Damien George
d7a9388fe0 ports: Add new make target "submodules" which inits required modules. 2019-10-15 17:14:41 +11:00
Glenn Ruben Bakke
98c2eabaff nrf/boards: Add nrf9160 pca10090 board. 2019-10-10 21:36:20 +02:00
Glenn Ruben Bakke
82fe6b0526 nrf: Add nrf9160 base support.
This patch add basic building blocks for nrf9P60.

It also includes a secure bootloader which forwards all
possible peripherals that are user selectable to become
non-secure. After configuring Flash, RAM and peripherals
the secure bootloader will jump to the non-secure domain
where MicroPython is placed.

The minimum size of a secure boot has to be a flash
block of 32Kb, hence why the linker scripts are
offsetting the main application this much.

The RAM offset is set to 128K, to allow for later
integration of Nordic Semiconductor's BSD socket
library which reserves the range 0x20010000 - 0x2001FFFF.
2019-10-10 21:35:27 +02:00
Glenn Ruben Bakke
01a3110e36 nrf/boards: Add support for pca10059.
Add support for pca10059 with REPL over tinyusb USB CDC.

The board also includes a board specific module that will
recover UICR->REGOUT0 in case this has been erased.

This initial support does not preserve any existing bootloader
on the pca10090 in case this was present, and expects to use all
available flash on the device.
2019-10-10 20:21:07 +02:00
Glenn Ruben Bakke
60b0b69f20 nrf: Add tinyusb support for nrf52840.
Add nrf-port finyusb driver files. USB CDC can be activated
by board configuration files using the MICROPY_HW_USB_CDC.

Updating BLE driver, Makefile, nrfx-glue and main.c to plug
in the tinyusb stack.
2019-10-10 20:21:07 +02:00
Glenn Ruben Bakke
1571120dc2 nrf/device: Correct SPIM3 IRQ handler entry for nrf52840. 2019-10-10 20:21:07 +02:00
Damien George
2863dcdf4f nrf: Add support to activate MICROPY_PY_SYS_STDFILES.
Fixes issue #5162.
2019-10-08 16:38:04 +11:00
roland van straten
a069340c1e nrf/main: Update the way the LED is used on startup.
In case of LED1 being present, do a short blink during startup
instead of turning it on and leave it on.
2019-10-02 22:17:54 +02:00
roland van straten
226399bcef nrf/led: Expose public API for LED manipulation.
Aligned implementation with the STM32 port.
Added empty functions to be used when no LED is available.
2019-10-02 22:09:43 +02:00
Glenn Ruben Bakke
cf383412ef nrf/flash: Update flash driver to use nrfx_nvmc driver.
The the nrfx driver is aware of chip specific registers, while
the raw HAL abstraction is not. This driver enables use of NVMC
in non-secure domain for nrf9160.
2019-10-02 21:28:34 +02:00
Glenn Ruben Bakke
c561ae61a1 nrf/uart: Add support for UARTE (EasyDMA). 2019-10-02 21:20:56 +02:00
Glenn Ruben Bakke
02a8c31eef nrf/temp: Move module configuration guard.
This patch moves the check for MICROPY_PY_MACHINE_TEMP to come
before the inclusion of nrf_temp.h. The nrf_temp.h depends on
the NRF_TEMP_Type which might not be defined for all nRF devices.
2019-10-02 21:15:48 +02:00
Glenn Ruben Bakke
d2e730b727 nrf/i2c: Add support for TWIM (EasyDMA). 2019-10-02 20:42:06 +02:00
roland van straten
ac112f88d0 nrf/boards: Add board definition for uBlox Nina B1 series BLE modules. 2019-09-17 11:33:48 +10:00
Jim Mussared
1f52a6f8e4 nrf/boards: Add Particle Xenon board configuration (an nRF52840). 2019-09-05 22:56:05 +10:00
Jim Mussared
d36fc4682e nrf/Makefile: Add support for flashing with a Black Magic Probe.
Also rename "flash" target to "deploy" to match other ports (but provide
"flash" as an alias for backwards compatibility).
2019-09-05 22:56:05 +10:00
Jim Mussared
353ed7705f nrf/boards/make-pins.py: Fix gen of board pins to use correct index.
It was previously not taking into account that the list of pins was sparse,
so using the wrong index.  The boards/X/pins.csv was generating the wrong
data for machine.Pin.board.

As part of this fix rename the variables to make it more clear what the
list contains (only board pins).
2019-09-05 22:52:24 +10:00
Damien George
9e90e2528b nrf/machine/adc: Fix mapping of ADC channel to pin. 2019-09-05 22:13:04 +10:00
Damien George
c7fb93b844 nrf/machine/adc: Allow to pass a Pin object in to ADC constructor. 2019-09-05 22:13:04 +10:00
Damien George
b766a6971e nrf: Add ADC channel mapping to alt function table. 2019-09-05 22:13:04 +10:00
Damien George
9cad134a2f nrf/machine/adc: Add ADC.read_u16() method. 2019-09-05 22:13:04 +10:00
Damien George
1fe1ff935b nrf: Clean up source by removing tabs, trailing spaces, non-ASCII chars. 2019-08-28 13:34:45 +10:00
Damien George
af20c2ead3 py: Add global default_emit_opt variable to make emit kind persistent.
mp_compile no longer takes an emit_opt argument, rather this setting is now
provided by the global default_emit_opt variable.

Now, when -X emit=native is passed as a command-line option, the emitter
will be set for all compiled modules (included imports), not just the
top-level script.

In the future there could be a way to also set this variable from a script.

Fixes issue #4267.
2019-08-28 12:47:58 +10:00
Damien George
497683b315 gitignore: Put build-*/ pattern in top-level gitignore file. 2019-08-16 00:08:08 +10:00
Glenn Ruben Bakke
d889def06b nrf/led: Adjust how board LEDs are defined.
Change static LED functions to lowercase names, and trim down source code
lines for variants of MICROPY_HW_LED_COUNT.  Also rename configuration for
MICROPY_HW_LEDx_LEVEL to MICROPY_HW_LEDx_PULLUP to align with global PULLUP
configuration.
2019-06-25 16:02:31 +10:00
Damien George
9cf1cbb057 nrf/mphalport: Use wfi to save power while waiting at the UART REPL. 2019-05-22 12:47:48 +10:00
Damien George
456c89f749 nrf/uart: Make UART print output something, and add write method. 2019-05-22 12:47:48 +10:00
Damien George
50d5114fcd nrf/mpconfigport.h: Enable MICROPY_KBD_EXCEPTION by default. 2019-05-22 12:47:48 +10:00
Damien George
302ffdba7f nrf/uart: Change UART driver to be non-blocking and use IRQs.
As part of this, ctrl-C is now able to interrupt a running program.
2019-05-22 12:47:19 +10:00
Glenn Ruben Bakke
d80abd035e nrf/nrfx_glue: Adapt to nrfx v.1.7.1.
Defining NRFX_STATIC_ASSERT macro to be empty, but available
to nrfx.
2019-05-21 23:16:20 +02:00
Damien George
bb29bde102 nrf/machine/i2c: Update to support new C-level I2C API. 2019-05-20 15:04:29 +10:00
Damien George
7e21cf723a nrf: Change types to size_t for all uses of mp_obj_str_get_data. 2019-05-13 12:39:56 +10:00
Nguyen Hoan Hoang
9a6f6fd68d nrf/boards: Add support for BLYST Nano module based boards.
- IBK-BLYST-NANO: Breakout board
- IDK-BLYST-NANO: DevKit board with builtin IDAP-M CMSIS-DAP Debug JTAG,
  RGB led
- BLUEIO-TAG-EVIM: Sensor tag board (environmental sensor
  (T, H, P, Air quality) + 9 axis motion sensor)

Also, the LED module has been updated to support individual base level
configuration of each LED. If set, this will be used instead of the
common configuration, MICROPY_HW_LED_PULLUP. The new configuration,
MICROPY_HW_LEDX_LEVEL, where X is the LED number can be used to set
the base level of the specific LED.
2019-05-02 22:33:44 +02:00
Damien George
0646e607b5 ports: Convert to use pyexec_file_if_exists() to execute boot/main.py.
The stm32 and nrf ports already had the behaviour that they would first
check if the script exists before executing it, and this patch makes all
other ports work the same way.  This helps when developing apps because
it's hard to tell (when unconditionally trying to execute the scripts) if
the resulting OSError at boot up comes from missing boot.py or main.py, or
from some other error.  And it's not really an error if these scripts don't
exist.
2019-04-26 15:22:14 +10:00
Glenn Ruben Bakke
1f5d945afa nrf/Makefile: Update to match latest oofatfs version.
See corresponding commit b5f33ac2cb
2019-04-01 19:22:25 +02:00