Commit Graph

518 Commits

Author SHA1 Message Date
Damien George
3b51b3e90f stmhal: Collect all root pointers together in 1 place.
A GC in stmhal port now only scans true root pointers, not entire BSS.
This reduces base GC time from 1700ms to 900ms.
2015-01-07 23:38:50 +00:00
Damien George
7ee91cf861 py: Add option to cache map lookup results in bytecode.
This is a simple optimisation inspired by JITing technology: we cache in
the bytecode (using 1 byte) the offset of the last successful lookup in
a map. This allows us next time round to check in that location in the
hash table (mp_map_t) for the desired entry, and if it's there use that
entry straight away.  Otherwise fallback to a normal map lookup.

Works for LOAD_NAME, LOAD_GLOBAL, LOAD_ATTR and STORE_ATTR opcodes.

On a few tests it gives >90% cache hit and greatly improves speed of
code.

Disabled by default.  Enabled for unix and stmhal ports.
2015-01-07 21:07:23 +00:00
Damien George
b4b10fd350 py: Put all global state together in state structures.
This patch consolidates all global variables in py/ core into one place,
in a global structure.  Root pointers are all located together to make
GC tracing easier and more efficient.
2015-01-07 20:33:00 +00:00
Damien George
b68d98d61c teensy: Prefix includes with py/; remove need for -I../py. 2015-01-01 21:13:30 +00:00
Damien George
2cf6dfa280 stmhal: Prefix includes with py/; remove need for -I../py. 2015-01-01 21:06:20 +00:00
Damien George
9ddbe291c4 py: Add include guards to mpconfig,misc,qstr,obj,runtime,parsehelper. 2014-12-29 01:02:19 +00:00
Damien George
7690b13953 stmhal: Add ability to mount custom block device. 2014-12-27 20:20:51 +00:00
Damien George
20236a8a99 stmhal: Upgrade to latest fatfs driver. 2014-12-27 17:36:16 +00:00
Paul Sokolovsky
3b74c91684 Makefiles: Support py/*.h includes per #1022. 2014-12-27 16:32:52 +02:00
Damien George
f3a1d673de stmhal: Enable ubinascii module, weak link to binascii. 2014-12-24 16:24:42 +00:00
Paul Sokolovsky
4b60b45bfc stmhal: gccollect.h is superfluous in many places. 2014-12-21 00:58:06 +02:00
Paul Sokolovsky
6aaccc484c stmhal: Use gc_dump_info() function instead of adhoc code. 2014-12-21 00:26:10 +02:00
Paul Sokolovsky
bf19586c53 stmhal: Include MICROPY_HAL_H only if defined.
Helps other ports.
2014-12-20 20:47:35 +02:00
Damien George
2a3e2b9033 py: Add execfile function (from Python 2); enable in stmhal port.
Adds just 60 bytes to stmhal binary.  Addresses issue #362.
2014-12-19 13:36:17 +00:00
Damien George
f04329e93b lib/libm: Add acosh, asinh, atanh, tan; get working with stmhal.
acoshf, asinhf, atanhf were added from musl.  mathsincos.c was
split up into its original, separate files (from newlibe-nano-2).
tan was added.

All of the important missing float functions are now implemented,
and pyboard now passes tests/float/math_fun.py (finally!).
2014-12-18 14:44:02 +00:00
Damien George
78d702c300 py: Allow builtins to be overridden.
This patch adds a configuration option (MICROPY_CAN_OVERRIDE_BUILTINS)
which, when enabled, allows to override all names within the builtins
module.  A builtins override dict is created the first time the user
assigns to a name in the builtins model, and then that dict is searched
first on subsequent lookups.  Note that this implementation doesn't
allow deleting of names.

This patch also does some refactoring of builtins code, creating the
modbuiltins.c file.

Addresses issue #959.
2014-12-09 16:19:48 +00:00
Damien George
b66a31c42c stmhal: Allow SPI.init to specify prescaler directly; improve SPI docs. 2014-12-08 21:34:07 +00:00
Damien George
008251180d stmhal: Enhance pyb.freq to configure bus (AHB, APB1, APB2) freqs.
This is useful if you need precise control over the speed of
peripherals (eg SPI clock).
2014-12-08 21:32:55 +00:00
Paul Sokolovsky
46c3ab2004 modsys: Add sys.print_exception(exc, file=sys.stdout) function.
The function is modeled after traceback.print_exception(), but unbloated,
and put into existing module to save overhead on adding another module.
Compliant traceback.print_exception() is intended to be implemented in
micropython-lib in terms of sys.print_exception().

This change required refactoring mp_obj_print_exception() to take pfenv_t
interface arguments.

Addresses #751.
2014-12-08 20:25:49 +00:00
Damien George
d0caaadaee stmhal: Allow network, uselect, usocket mods to be used by other ports.
Remove include of stm32f4xx_hal.h, replace by include of MICROPY_HAL_H
where needed, and make it compile without float support.  This makes
these 3 modules much more generic and usable by other ports.
2014-12-07 17:03:47 +00:00
Damien George
9de6773237 stmhal: Make SPI bus use DMA for transfers.
Uses DMA if interrupts are enabled, polling if they are disabled.
2014-12-06 17:41:17 +00:00
Damien George
be6d8be91e py: Rename mp_obj_int_get to mp_obj_int_get_truncated; fix struct.pack.
mp_obj_int_get_truncated is used as a "fast path" int accessor that
doesn't check for overflow and returns the int truncated to the machine
word size, ie mp_int_t.

Use mp_obj_int_get_truncated to fix struct.pack when packing maximum word
sized values.

Addresses issues #779 and #998.
2014-12-05 23:13:52 +00:00
Damien George
a4c52c5a3d py: Optimise lexer by exposing lexer type.
mp_lexer_t type is exposed, mp_token_t type is removed, and simple lexer
functions (like checking current token kind) are now inlined.

This saves 784 bytes ROM on 32-bit unix, 348 bytes on stmhal, and 460
bytes on bare-arm.  It also saves a tiny bit of RAM since mp_lexer_t
is a bit smaller.  Also will run a bit more efficiently.
2014-12-05 19:35:18 +00:00
Damien George
29a1ec1bd6 stmhal: Overhaul network drivers; has generic network protocol in C.
This patch overhauls the network driver interface.  A generic NIC must
provide a set of C-level functions to implement low-level socket control
(eg socket, bind, connect, send, recv).  Doing this, the network and
usocket modules can then use such a NIC to implement proper socket
control at the Python level.

This patch also updates the CC3K and WIZNET5K drivers to conform to the
new interface, and fixes some bugs in the drivers.  They now work
reasonably well.
2014-12-04 18:57:57 +00:00
Damien George
57c70d6073 stmhal: Move RTC HAL init functions to rtc.c, where they belong.
So can remove unnecessary stm32f4xx_hal_msp.c file.
2014-12-02 12:40:37 +00:00
Damien George
1960475ed7 stmhal: Make pyb.[u]delay use systick with IRQs, busy loop otherwise.
pyb.delay and pyb.udelay now use systick if IRQs are enabled, otherwise
they use a busy loop.  Thus they work correctly when IRQs are disabled.
The busy loop is computed from the current CPU frequency, so works no
matter the CPU frequency.
2014-11-30 21:23:25 +00:00
Damien George
19fb1b4dd7 stmhal: Add USB_VCP.setinterrupt method, to disable CTRL-C. 2014-11-29 15:23:21 +00:00
Damien George
3b603f29ec Use MP_DEFINE_CONST_DICT macro to define module dicts.
This is just a clean-up of the code.  Generated code is exactly the
same.
2014-11-29 14:39:27 +00:00
Damien George
92f1ed8f40 stmhal: Enable uhashlib module; add heapq, hashlib weak links.
hashlib test passes on pyboard.
2014-11-27 17:54:37 +00:00
Damien George
317cf18486 stmhal: Remove unnecessary HAL_Delay in readline loop.
The reason for having this delay is to reduce power consumption at the
REPL (HAL_Delay calls __WFI to idle the CPU).  But stdin_rx_chr has a
__WFI in it anyway, so this delay call is not needed.

By removing this call, the readline input can consume characters much
more quickly (before was limited to 1000 chrs/s), and has much reduced
dependency on the specific port.
2014-11-27 17:04:09 +00:00
Damien George
5cbc9e0db0 stmhal: Reduce coupling between USB driver and readline.
This makes it easier to re-use readline.c and pyexec.c from stmhal in
other ports.
2014-11-27 16:58:31 +00:00
Henrik Sölver
acb92c186c Adding CAN filter management 2014-11-26 18:52:33 +00:00
Damien George
20d239cb28 stmhal: Enable DAC on STM32F4DISC.
Addresses issue #987.
2014-11-25 11:42:26 +00:00
Damien George
5694cc5490 py: Make stream seek correctly check for ioctl fn; add seek for textio. 2014-11-16 23:56:37 +00:00
Paul Sokolovsky
fa2edabc5c stmhal: Switch to file.seek() implementation using stream ioctl. 2014-11-17 00:16:14 +02:00
Paul Sokolovsky
f4a6a577ab stream: Convert .ioctl() to take fixed number of args.
This is more efficient, as allows to use register calling convention.
If needed, a structure pointer can be passed as argument to pass more
data.
2014-11-17 00:16:14 +02:00
Damien George
d1b42d7b51 stmhal: Improve CAN init so that it can take sjw, bs1, bs2 args.
Also update docs to explain how CAN baudrate is determined.
2014-11-15 21:28:14 +00:00
Damien George
224fee0e10 stmhal: Fix HAL error raising; make test for it.
Addresses issue #968.
2014-11-15 20:39:44 +00:00
Sven Wegener
0e0ae97975 stmhal: Declare variables extern in include files
Else we end up with several instances of the variable.

Signed-off-by: Sven Wegener <sven.wegener@stealer.net>
2014-11-05 22:52:51 +00:00
Damien George
7860c2a68a py: Fix some macros defines; cleanup some includes. 2014-11-05 21:16:41 +00:00
Damien George
38bd762121 stmhal: Improve pyb.freq to allow 8 and 16MHz (not usable with USB).
Also restrict higher frequencies to have a VCO_OUT frequency below
432MHz, as specified in the datasheet.

Docs improved to list allowed frequencies, and explain about USB
stability.
2014-11-02 15:10:15 +00:00
Damien George
4029f51842 stmhal: Fix UART so bits counts number of data bits, not incl parity.
Addresses issue #950.
2014-10-31 20:28:10 +00:00
Damien George
1559a97810 py: Add builtin round function.
Addresses issue #934.
2014-10-31 11:28:50 +00:00
Damien George
1a8573ed0e stmhal: Update some inlined docs for network and CAN. 2014-10-31 01:12:54 +00:00
Damien George
4ef67d30f1 stmhal: Implement support for RTS/CTS hardware flow control in UART.
This is experimental support.  API is subject to changes.  RTS/CTS
available on UART(2) and UART(3) only.  Use as:

    uart = pyb.UART(2, 9600, flow=pyb.UART.RTS | pyb.UART.CTS)
2014-10-31 00:40:57 +00:00
Damien George
9a41b32b3f stmhal: Add ioctl to USB_VCP object, so it works with select.
This patch also enables non-blocking streams on stmhal port.

One can now make a USB-UART pass-through function:

def pass_through(usb, uart):
    while True:
        select.select([usb, uart], [], [])
        if usb.any():
            uart.write(usb.read(256))
        if uart.any():
            usb.write(uart.read(256))

pass_through(pyb.USB_VCP(), pyb.UART(1, 9600))
2014-10-31 00:12:02 +00:00
Damien George
efc49c5591 stmhal: Improve CAN print function. 2014-10-30 23:16:05 +00:00
Henrik Sölver
504636815e stmhal: Added support for extended CAN frames. 2014-10-30 23:16:01 +00:00
Damien George
11aa91615e stmhal: Fix ptr arith in CC3000 code; enable network build in travis. 2014-10-30 15:28:15 +00:00
stijn
49c47da804 Fix errors after enabling -Wpointer-arith 2014-10-29 15:42:38 +00:00