Commit Graph

454 Commits

Author SHA1 Message Date
Damien George
f996d8854f drivers, cc3k: Move cc3000 driver from stmhal to drivers directory. 2014-09-26 00:56:45 +01:00
Damien George
ac04a8a56a stmhal: Enable 8-byte stack alignment for IRQ handlers. 2014-09-25 15:47:53 +01:00
Damien George
e8ea0724da stmhal, timer: Factor code to compute PWM percent; improve 32bit case.
Also do the same for teensy timer code.
2014-09-25 15:44:10 +01:00
Damien George
3fafe730d3 Merge pull request #868 from dhylands/fix-teensy-float
Add pulse_width_percent to teensy.
2014-09-25 14:51:44 +01:00
Dave Hylands
53d5fa641f Add pulse_width_percent to teensy.
Fix stmhal and teensy print routines to report actual prescaler an period.
Fix teensy build to use soft-float
Add USE_ARDUINO_TOOLCHAIN option to teensy build
2014-09-23 23:19:36 -07:00
Damien George
52b5d76a6b py: Free non-interned strings in the parser when not needed.
mp_parse_node_free now frees the memory associated with non-interned
strings.  And the parser calls mp_parse_node_free when discarding a
non-used node (such as a doc string).

Also, the compiler now frees the parse tree explicitly just before it
exits (as opposed to relying on the caller to do this).

Addresses issue #708 as best we can.
2014-09-23 15:31:56 +00:00
Damien George
eaaebf3291 stmhal: Initialise stack pointer correctly.
Stack is full descending and must be 8-byte aligned.  It must start off
pointing to just above the last byte of RAM.

Previously, stack started pointed to last byte of RAM (eg 0x2001ffff)
and so was not 8-byte aligned.  This caused a bug in combination with
alloca.

This patch also updates some debug printing code.

Addresses issue #872 (among many other undiscovered issues).
2014-09-23 10:59:05 +01:00
Damien George
0e58c5810d stmhal: Add pulse_width_ratio to timer channel object.
This allows to set the pulse width (for PWM mode) as a ratio relative to
the period of the timer.  Eg, 0.5 is a 50% duty cycle.  You can set the
ratio in the channel init, or using channel.pulse_width_ratio; the
latter can also read the pulse width as a ratio.
2014-09-21 22:54:02 +01:00
Dave Hylands
becbc87fd7 Add Timer support (PWM, OC, IC) for stmhal and teensy 2014-09-19 09:26:13 -07:00
Damien George
2842945e76 stmhal: Fix bugs in documentation so it compiles. 2014-09-17 23:27:42 +00:00
Damien George
612045f53f py: Add native json printing using existing print framework.
Also add start of ujson module with dumps implemented.  Enabled in unix
and stmhal ports.  Test passes on both.
2014-09-17 22:56:34 +01:00
Damien George
1d7fb82f0a stmhal: Change 64-bit arithmetic to 32-bit for SD card block addressing.
By measuring SD card addresses in blocks and not bytes, one can get away
with using 32-bit numbers.

This patch also uses proper atomic lock/unlock around SD card
read/write, adds SD.info() function, and gives error code for failed
read/writes.
2014-09-15 23:49:57 +01:00
Felix Domke
6ff42c54bb stmhal/sdcard.c: add pyb.SD.write 2014-09-15 22:34:16 +01:00
Felix Domke
09de030651 stmhal/hal/src/stm32f4xx_hal_sd.c: fix SDHC card capacity 2014-09-15 22:34:07 +01:00
Damien George
b92cbe6129 py: Move definition of mp_sys_exit to core.
sys.exit always raises SystemExit so doesn't need a special
implementation for each port.  If C exit() is really needed, use the
standard os._exit function.

Also initialise mp_sys_path and mp_sys_argv in teensy port.
2014-09-15 15:53:09 +01:00
Damien George
8594ce2280 py: Implement divmod, % and proper // for floating point.
Tested and working on unix and pyboard.
2014-09-13 18:43:09 +01:00
Damien George
32781cce6d stmhal: Slightly improved memcpy; memset uses word store when aligned. 2014-09-13 00:12:41 +01:00
Damien George
5792500ccc Merge branch 'memcpy' of github.com:iabdalkader/micropython into iabdalkader-memcpy 2014-09-12 23:23:49 +01:00
Damien George
89ab3be0b1 Merge branch 'master' of github.com:micropython/micropython 2014-09-11 22:28:58 +01:00
Damien George
20beff9ae3 py and libm: Add asinf,acosf; print higher precision for float.
Also use less stack space when printing single precision float.

Addition of asinf and acosf addresses issue #851.
2014-09-11 22:24:45 +01:00
iabdalkader
d60580eb5e Optimize memcpy more 2014-09-11 19:01:48 +02:00
Hirotaka Kawata
2b4af54992 Add LIS3DSH accelometer support to staccel.py 2014-09-11 16:40:53 +09:00
iabdalkader
81b2ddf5d1 Memcpy: copy words 2014-09-11 07:49:21 +02:00
Damien George
5c00757a5c stmhal: uart ioctl uses EINVAL, and checks TXE bit for write-ability. 2014-09-07 20:57:18 +01:00
Damien George
013d53c0b4 Remove skeletal modselect from extmod and just put it in stmhal. 2014-09-07 20:42:01 +01:00
Damien George
e2a618615d stmhal: Fix modselect so non-hashable objects can be polled. 2014-09-07 20:41:09 +01:00
Damien George
a2f55fe12b stmhal: Add polling ability to UART object. 2014-09-07 20:40:32 +01:00
Damien George
6c9c7bc75a stmhal: Implement generic select.select and select.poll. 2014-09-07 20:40:32 +01:00
Damien George
bad2df3e95 stmhal, modwiznet5k: Add very minimal documentation. 2014-09-01 22:58:22 +01:00
Damien George
bcf041f1a3 stmhal: Add wiznet5k module, to control WIZnet ethernet adaptor.
Allows to create socket objects that support TCP and UDP in server and
client mode.  Interface is very close to standard Python socket class,
except bind and accept do not work the same (due to hardware not
supporting them in the usual way).

Not compiled by default.  To compile this module, use:
make MICROPY_PY_WIZNET5K=1
2014-09-01 22:52:38 +01:00
Damien George
ecc88e949c Change some parts of the core API to use mp_uint_t instead of uint/int.
Addressing issue #50, still some way to go yet.
2014-08-30 00:35:11 +01:00
Damien George
8707ea3421 lib: Add lib and libm, moving current files from stmhal.
Top-level lib directory is for standard C libraries that we want to
provide our own versions of (for efficiency and stand-alone reasons).
It currently has libm in it for math functions.

Also add atanf and atan2f, which addresses issue #837.
2014-08-29 22:42:26 +01:00
Damien George
f05b87bd63 Merge pull request #824 from dhylands/sdcard-power
Fix sdcard_power_on to not do anything if the card is already powered on...
2014-08-26 22:58:54 +01:00
Damien George
3b72da674e stmhal, STM32F4DISC: Small changes to ST accel driver. 2014-08-26 22:41:27 +01:00
Damien George
e00fb08f99 stmhal, staccel.py: Style cleanup. 2014-08-26 17:30:48 +01:00
David Siorpaes
f4ce26de5c Added LIS302DL ID check 2014-08-26 18:23:00 +02:00
Damien George
3bb7efc943 stmhal: Hookup USB_VCP.any().
Thanks to Dave Hylands for this patch.
2014-08-26 14:18:22 +01:00
Damien George
cd021bfe56 stmhal: Fix build issues with (old) CC3000 driver.
Addresses issue #825.
2014-08-26 14:13:53 +01:00
Dave Hylands
994bb4a839 Fix sdcard_power_on to not do anything if the card is already powered on. 2014-08-25 10:16:52 -07:00
Damien George
34e43c7ee9 stmhal: Improve efficiency of SysTick IRQ and HAL_Delay.
SysTick IRQ now increases millisecond counter directly (ie without
calling HAL_IncTick).  Provide our own version of HAL_Delay that does a
wfi while waiting.  This more than halves power consumption when running
a loop containing a pyb.delay call.  It used to be like this, but new
version of HAL library regressed this feature.
2014-08-25 18:12:44 +01:00
Damien George
29c92a407c stmhal: Use MP_OBJ_NEW_SMALL_INT directly in pyb.micros/millis.
Also some whitespace cleanup.
2014-08-25 17:38:55 +01:00
Dave Hylands
2bf044442e Add support for pyb.micros() by using the systick timer.
I also removed trailing spaces from modpyb.c which affected a couple
of lines technically not part of this patch.

Tested using: https://github.com/dhylands/upy-examples/blob/master/micros_test.py

which eventually fails due to wraparound issues (I could fix the test to compensate
but didn't bother)
2014-08-25 17:38:55 +01:00
Damien George
e5cbb70328 stmhal: Make enable_irq and disable_irq inline functions.
These functions are generally 1 machine instruction, and are used in
critical code, so makes sense to have them inline.

Also leave these functions uninverted (ie 0 means enable, 1 means
disable) and provide macro constants if you really need to distinguish
the states.  This makes for smaller code as well (combined with
inlining).

Applied to teensy port as well.
2014-08-25 13:24:33 +01:00
Dave Hylands
9480138f0c Add save/restore_irq
Factored irq functions into a separate file.
2014-08-25 12:22:11 +01:00
Damien George
2c4e67e32d stmhal, pin: Update documentation. 2014-08-24 18:30:22 +01:00
Dave Hylands
3d945559d4 Added python script to map AF to a pin name
Added some functions to Pin class to query mode, pull, and af
2014-08-24 18:21:08 +01:00
Damien George
8ba832456e stmhal, modtime: Small changes, reduced code size by around 80 bytes.
Also added test for modtime.
2014-08-24 17:40:24 +01:00
Dave Hylands
6678595e7e Add time.mktime and enhance time.localtime (for stmhal)
Now you can use time.localtime on the timestamps presented by os.stat
2014-08-24 17:00:03 +01:00
Damien George
3c658a4e75 py: Fix bug where GC collected native/viper/asm function data.
Because (for Thumb) a function pointer has the LSB set, pointers to
dynamic functions in RAM (eg native, viper or asm functions) were not
being traced by the GC.  This patch is a comprehensive fix for this.

Addresses issue #820.
2014-08-24 16:28:17 +01:00
Dave Hylands
3688414d9d Put some code into the first 16K of flash
This basically shrinks the remaining size of flash in the portion
that goes after the internal flash drive.
2014-08-16 08:00:12 -07:00
Damien George
b63be37be1 stmhal: In safe mode, still mount SD card and present as MSD over USB.
It's still "safe" because no scripts are run.  Remove the SD card if you
want to access the internal flash filesystem.  Addresses issue #616.

Also: remove obsolete pyb.source_dir setting, and reset pyb.main and
pyb.usb_mode settings on soft-reset.
2014-08-16 14:23:22 +01:00
Damien George
b0accc8571 stmhal: Fix printing of pin name in error message. 2014-08-16 13:56:19 +01:00
Damien George
244476e3e6 stmhal: For non-debug compile, enable CC/LD opt to remove dead code.
Saves over 35k ROM due to elimination of unused HAL functions.  All
tests pass.

Addresses issue #702.
2014-08-16 13:37:05 +01:00
Damien George
bf133f7737 stmhal: Resolve question in comment about timer clock. 2014-08-14 00:30:14 +01:00
Damien George
1ddd844815 extmod: Finish rename of zlib to zlibd; enable zlibd on stmhal. 2014-08-12 23:23:53 +01:00
Damien George
105e32f1a5 stmhal: Enable moductypes by default.
Also fixes compiler error in moductypes when compiled without debugging.

Addresses issue #778.
2014-08-12 20:02:26 +01:00
Damien George
101d87da6a stmhal: Working STM32F4DISC accelerometer, via Python script.
Thanks to David Siorpaes.
2014-08-10 22:26:20 +01:00
Damien George
30dd23aa7f doc: Document gc, sys, math, cmath. 2014-08-10 17:50:28 +01:00
Damien George
0c64c634ca stmhal: Add sys.platform string to PYBv1.0 (it's "pyboard"). 2014-08-10 17:49:52 +01:00
Damien George
2605df3346 stmhal, pin: Save 140 bytes ROM by simplifying pin_print function. 2014-08-09 09:19:37 +01:00
Damien George
04019e365f stmhal, pin: Simplify default value for alternate function init. 2014-08-09 08:51:12 +01:00
Damien George
ea439e59d9 stmhal: Start of documentation for modos and modtime. 2014-08-08 23:30:01 +01:00
Damien George
284efa89ae stmhal/teensy: Use _ instead of - in source file names.
Trying to move towards consistency, let's use _ exclusively in names of
source files (eg .c, .h, .csv).
2014-08-08 22:34:06 +01:00
Damien George
4b67463be1 stmhal: Fix documentation; remove ability to specify af by str. 2014-08-08 22:26:53 +01:00
Damien George
5b7c0c437b stmhal: Comment out unused functions. 2014-08-08 22:25:46 +01:00
Dave Hylands
6f418fc1b0 Add support for selecting pin alternate functions from python.
Converts generted pins to use qstrs instead of string pointers.

This patch also adds the following functions:
pyb.Pin.names()
pyb.Pin.af_list()
pyb.Pin.gpio()

dir(pyb.Pin.board) and dir(pyb.Pin.cpu) also produce useful results.

pyb.Pin now takes kw args.

pyb.Pin.__str__ now prints more useful information about the pin
configuration.

I found the following functions in my boot.py to be useful:
```python
def pins():
    for pin_name in dir(pyb.Pin.board):
        pin = pyb.Pin(pin_name)
        print('{:10s} {:s}'.format(pin_name, str(pin)))

def af():
    for pin_name in dir(pyb.Pin.board):
        pin = pyb.Pin(pin_name)
        print('{:10s} {:s}'.format(pin_name, str(pin.af_list())))
```
2014-08-07 23:15:41 -07:00
Damien George
3ef911345c stmhal: Update STM32Cube F4 HAL driver to V1.3.0.
This patch updates ST's HAL to the latest version, V1.3.0, dated 19 June
2014.  Files were copied verbatim from the ST package.  Only change was
to suppress compiler warning of unused variables in 4 places.

A lot of the changes from ST are cosmetic: comments and white space.
Some small code changes here and there, and addition of F411 header.

Main code change is how SysTick interrupt is set: it now has a
configuration variable to set the priority, so we no longer need to work
around this (originall in system_stm32f4xx.c).
2014-08-06 22:33:31 +01:00
Damien George
8a11d693cf stmhal: Ability to stat /flash and /sd.
Addresses issue #780.
2014-08-06 19:02:34 +01:00
Damien George
2fe2a05f9f stmhal: Put #if guards around all GPIOx_CLK_ENABLE's.
Specifically, teensy port does not have these macros defined.
2014-08-06 16:40:20 +01:00
Damien George
95ea4f0c95 stmhal: Enable relevant GPIO clock when Pin obj is init'd. 2014-08-06 16:04:57 +01:00
Damien George
7cc20e7e99 stmhal: Wrap DAC module and os.urandom in relevant #if's. 2014-08-05 23:35:21 +01:00
Damien George
56da07dcfa stmhal, math: Define _M_LN2 if not already defined.
Addresses issue #790.
2014-08-05 14:13:05 +00:00
Damien George
ccacdf44b6 stmhal: Clean up reset/soft-reset code; fix bug init'ing VCP exc.
Make a clearer distinction between init functions that must be done
before any scripts can run (xxx_init0) and those that can be safely
deferred (xxx_init).

Fix bug initialising USB VCP exception.  Addresses issue #788.

Re-order some init function to improve reliability of
reset/soft-reset.
2014-08-04 11:09:51 +01:00
Damien George
8dbbbbc793 Put call to qstr_init and mp_init_emergency_exc_buf in mp_init.
qstr_init is always called exactly before mp_init, so makes sense to
just have mp_init call it.  Similarly with
mp_init_emergency_exception_buf.  Doing this makes the ports simpler and
less error prone (ie they can no longer forget to call these).
2014-08-04 10:05:16 +01:00
Damien George
8362bffb2e stmhal: Document behaviour of usb_vcp_recv_byte. 2014-08-03 17:30:26 +01:00
Damien George
2e41646eb7 stmhal: Add more documentation for USB_VCP. 2014-08-02 14:43:20 +01:00
Damien George
87bbb388db stmhal: Add documentation for LCD; update docs for USB_VCP. 2014-08-02 14:35:38 +01:00
Damien George
71bed1a9a7 stmhal: Add preliminary driver for ST32F4DISC accelerometer.
Written in Python, not currently working.  See issue #725.
2014-08-02 12:51:18 +01:00
Dave Hylands
f8f963a14a Fix modos.c to compile for the STM32F4Discovery board (which doesn't have an sdcard) 2014-08-01 08:10:41 -07:00
Damien George
65dd7bc13d stmhal: Change 0:/ and 1:/ to /flash and /sd; add CWD support.
Some important changes to the way the file system is structured on the
pyboard:

1. 0: and 1: drive names are now replaced with POSIX inspired
directories, namely /flash and /sd.

2. Filesystem now supports the notion of a current working directory.
Supports the standard Python way of manipulating it: os.chdir and
os.getcwd.

3. On boot up, current directory is /flash if no SD inserted, else /sd
if SD inserted.  Then runs boot.py and main.py from the current dir.
This is the same as the old behaviour, but is much more consistent and
flexible (eg you can os.chdir in boot.py to change where main.py is run
from).

4. sys.path (for import) is now set to '' (current dir), plus /flash
and /flash/lib, and then /sd and /sd/lib if SD inserted.  This, along
with CWD, means that import now works properly.  You can import a file
from the current directory.

5. os.listdir is fixed to return just the basename, not the full path.

See issue #537 for background and discussion.
2014-07-31 23:44:04 +01:00
Damien George
bb4c6f35c6 py: Make MP_OBJ_NEW_SMALL_INT cast arg to mp_int_t itself.
Addresses issue #724.
2014-07-31 10:49:14 +01:00
Damien George
fa1ecda3fd stmhal, accel: Increase start-up times to 30ms; add extra 30ms delay.
For accel to start-up reliably, need to wait 30ms between on/off, and
30ms for it to enter active mode.  With this fix the accel can be read
immediately after initialising it.

Addresses issue #763.
2014-07-31 10:39:52 +01:00
Damien George
3c4db9f91c stmhal: Add USB_VCP class/object, for direct USB VCP control.
Before, pyb.stdin/pyb.stdout allowed some kind of access to the USB VCP
device, but it was basic access.

This patch adds a proper USB_VCP class and object with much more control
over the USB VCP device.  Create an object with pyb.USB_VCP(), then use
this object as if it were a UART object.  It has send, recv, read,
write, and other methods.  send and recv allow a timeout to be specified.

Addresses issue 774.
2014-07-31 10:30:42 +01:00
Damien George
94fbe9711a py: Change lexer stream API to return bytes not chars.
Lexer is now 8-bit clean inside strings.
2014-07-30 11:46:05 +01:00
Damien George
07133415d2 Merge pull request #738 from dhylands/except-args
Add support for storing args during an exception raised by an irq.
2014-07-29 23:15:35 +01:00
Damien George
adf0f2ae1a py: Change stream protocol API: fns return uint; is_text for text. 2014-07-27 22:38:58 +01:00
Dave Hylands
5b7fd20fea Add support for storing args during an exception raised by an irq.
The user code should call micropython.alloc_emergency_exception_buf(size)
where size is the size of the buffer used to print the argument
passed to the exception.

With the test code from #732, and a call to
micropython.alloc_emergenncy_exception_buf(100) the following error is
now printed:
```python
>>> import heartbeat_irq
Uncaught exception in Timer(4) interrupt handler
Traceback (most recent call last):
  File "0://heartbeat_irq.py", line 14, in heartbeat_cb
NameError: name 'led' is not defined
```
2014-07-25 14:00:06 -07:00
Damien George
de993f4573 Merge pull request #766 from dhylands/allow-dfu-override
Allow DFU_UTIL to be overridden from the environment.
2014-07-22 11:02:59 +01:00
blmorris
7a03b5f56a remove Myriad2 board config files from master 2014-07-21 23:12:07 -04:00
blmorris
86f0b31bcf Change boolean 'use_16bit_addr' to int 'addr_size', can be either 8 or 16 bits, default value is 8
to maintain compatibility with existing code.
2014-07-21 22:45:04 -04:00
Dave Hylands
a2e7a1315d Allow DFU_UTIL to be overridden from the environment. 2014-07-21 16:28:07 -07:00
blmorris
721d6240c9 Merge https://github.com/blmorris/micropython into Myriad2 2014-07-21 12:50:10 -04:00
blmorris
4038f513ea Merge https://github.com/micropython/micropython 2014-07-21 12:47:57 -04:00
Damien George
951ed9d02f stmhal: Fix REPL printing by cooking output sent to stdout_obj.
Recent changes to builtin print meant that print was printing to the
mp_sys_stdout_obj, which was sending data raw to the USB CDC device.
The data should be cooked so that \n turns into \r\n.
2014-07-20 13:57:43 +01:00
Damien George
1163cb9cb5 stmhal: Change calls to pfenv_printf to pfenv_vprintf.
Fixes printing bugs introduced by
cb66f41ebc.
2014-07-20 13:10:18 +01:00
Paul Sokolovsky
cb66f41ebc py: Make print() accept "file" argument, and actually print to stream.
And not system printf(), like it was before. For this, move pfenv_printf()
from stmhal port to py/.
2014-07-19 21:27:22 +03:00
Damien George
1694bc733d py: Add stream reading of n unicode chars; unicode support by default.
With unicode enabled, this patch allows reading a fixed number of
characters from text-mode streams; eg file.read(5) will read 5 unicode
chars, which can made of more than 5 bytes.

For an ASCII stream (ie no chars > 127) it only needs to do 1 read.  If
there are lots of non-ASCII chars in a stream, then it needs multiple
reads of the underlying object.

Adds a new test for this case.  Enables unicode support by default on
unix and stmhal ports.
2014-07-19 18:34:04 +01:00
Damien George
02bc882c3d stmhal: Add file.flush and os.stat. 2014-07-19 16:39:13 +01:00
blmorris
ef204733d6 Initial commit of Myriad2 board-specific configuration files 2014-07-15 15:10:56 -04:00
blmorris
847a6b30b1 Incorporate stylistic changes suggested by @dhylands 2014-07-11 21:18:09 -04:00