Commit Graph

250 Commits

Author SHA1 Message Date
Paul Sokolovsky 9b71b16a94 unix,stmhal: Make "mpconfig.h" be first included, as other headers depend on it. 2014-05-02 18:08:16 +03:00
Damien George ba742ed639 Add shell script to automatically build stmhal/ for all pyboards. 2014-05-02 13:49:44 +00:00
Damien George f2021ffe0f Merge pull request #542 from dhylands/fix-pin
Fix pin initialization when a mode argument is provided
2014-05-01 23:26:28 +01:00
Dave Hylands e911cfdb22 Fix pin initialization when a mode argument is provided 2014-05-01 12:15:37 -07:00
Andrew Scheller ed9d8d6354 Add flashboard target to the stmhal Makefile to run dfu-util
Which allows you to run "make -C stmhal flashboard" from the top-level directory.
Also ties in nicely with my configurable BUILD directory from #506
2014-05-01 02:51:29 +01:00
Damien George f4b7e9bd2e stmhal, docs: Small changes to URL links; adds list of files if none given.
This documentation is now available at micropython.org/doc/
2014-04-30 23:33:30 +01:00
Damien George 4ae52d454c stmhal: Reinstate CC3000 driver from old stm/ port.
It's not enabled by default because it doesn't fully work.  It can
connect to an AP, get an IP address and do a host-lookup, but not yet do
send or recv on a socket.
2014-04-30 20:47:50 +01:00
Damien George cab23051d9 stmhal: Make LED.intensity return the same value it was set to.
Also give proper error message when trying to construct a non-existent
LED.

Addresses issue #530.
2014-04-30 19:23:21 +01:00
Damien George da9f27103d stmhal: Oops, typo. 2014-04-29 23:00:48 +01:00
Damien George 8d09640b22 stmhal: Add documentation in comments, and script to generate HTML.
Decided to write own script to pull documentation from comments in C code.
Style for writing auto generated documentation is: start line with ///
and then use standard markdown to write the comment.  Keywords
recognised by the scraper begin with backslash.  See code for examples.

Running: python gendoc.py modpyb.c accel.c adc.c dac.c extint.c i2c.c
led.c pin.c rng.c servo.c spi.c uart.c usrsw.c, will generate a HTML
structure in gendoc-out/.

gendoc.py is crude but functional.  Needed something quick, and this was
it.
2014-04-29 22:55:34 +01:00
Damien George dbc81df5d4 Simplify names for argcheck.c / arg parsing. 2014-04-26 11:19:17 +01:00
Damien George 6d3c5e4301 Add ARRAY_SIZE macro, and use it where possible. 2014-04-26 10:47:29 +01:00
Damien George 5ea69859c9 stmhal: Update help text. 2014-04-21 20:18:22 +01:00
Damien George 350cb6bf20 stmhal: Fix bug with pin GPIO reading. 2014-04-21 20:18:06 +01:00
Damien George ef255e47c1 stmhal, usrsw: Wrap usrsw.c in #if, for when switch is not available. 2014-04-21 18:31:40 +01:00
Damien George b97c2f4c14 stmhal, accel: Add TODO comment. 2014-04-21 18:30:38 +01:00
Damien George 46e1f26615 stmhal, usrsw: Update comments for new switch API. 2014-04-21 18:28:23 +01:00
Damien George 6125ba4a7f stmhal: Make switch a class, to follow suit of all other modules.
Instead of pyb.switch() as a function, it's more consistent (with
respect to all the other modules and peripherals) to have
pyb.Switch() create a switch object.  This then generalises to having
multiple switches.  Call the object to get its state.  Use sw.callback
to set the callback function for when the switch is pressed.
2014-04-21 18:23:50 +01:00
Damien George af797f476f stmhal, servo: Rename calibrate method to calibration.
It should be a noun, since it supports getting and setting depending on
the number of arguments given.
2014-04-21 18:21:07 +01:00
Damien George 6691c9e655 stmhal, timer: Remove obsolete global variable. 2014-04-21 18:19:50 +01:00
Damien George 7fdfa93700 stmhal: Add Timer class: simple TIM control, incl callback on IRQ.
Simple but functional timer control.  More sophistication will
eventually be added, or for now just use direct register access :)

Also added pyb.freq() function to get MCU clock frequencies.
2014-04-21 16:48:16 +01:00
Damien George 764af4b7c5 stmhal: Make DAC dynamically allocate instances; rename dma->write_timed. 2014-04-21 13:06:19 +01:00
Damien George 83407ad082 stmhal: Clean up rtc.c a bit. 2014-04-21 12:45:59 +01:00
Damien George 7533700393 stmhal: Rename USART to UART.
It's really a UART because there is no external clock line (and hence no
synchronous ability, at least in the implementation of this module).
USART should be reserved for a module that has "S"ynchronous capabilities.

Also, UART is shorter and easier to type :)
2014-04-21 12:03:09 +01:00
Damien George 34f01c2ca1 stmhal: Add some documentation to I2C, SPI and USART modules. 2014-04-21 01:59:43 +01:00
Damien George 3771a097da stmhal: Improve USART class, to be more like SPI and I2C.
The three classes I2C, SPI and USART now have a fairly uniform (Python)
API.  All are constructed, initialised and deinitialised in the same
way.  They can have most of their parameters set, using keyword arguments.
All have send and recv (although slightly different with I2C requiring an
address in master mode).  recv can do inplace receiving (ie store the
data in a previously-created bytearray).

It's just polling mode at the moment, but interrupt and DMA would be
nice to add.
2014-04-21 01:14:14 +01:00
Damien George eb8bdf4df3 stmhal, SPI and I2C: Improvements to functionality and consistency. 2014-04-21 00:10:04 +01:00
Damien George ff91156d34 stmhal: Improved configurability for I2C and SPI busses.
The HAL handles for the I2C/SPI objects are rather large, so we don't
want to unnecessarily include them.
2014-04-20 19:06:15 +01:00
Dave Hylands f70630c58f Fix i2c and spi to compile for Netduino Plus 2 2014-04-20 00:06:03 -07:00
Damien George fd6925b4b9 stmhal: Small bug fixes and simplifications. 2014-04-20 01:25:58 +01:00
Damien George 13c19c57a0 stmhal: Only init RNG if it's used. 2014-04-20 00:45:59 +01:00
Damien George 0a6e9f562f stmhal: Update ExtInt to allow keyword arguments in constructor. 2014-04-20 00:38:50 +01:00
Damien George 57e415859a stmhal: Tidy up and improve consistency across modules. 2014-04-20 00:30:09 +01:00
Damien George d689430e79 stmhal: Add SPI class.
Also some updates to compile with latest changes to core py.
2014-04-20 00:16:30 +01:00
Damien George 27dd471098 Merge branch 'master' of github.com:micropython/micropython 2014-04-19 02:18:19 +01:00
Damien George 3d19137442 stmhal: Add pyb.Pin.init method to re-init GPIO pin mode. 2014-04-19 02:17:57 +01:00
Damien George 6e44381cce stmhal: Improve RTC class; make fatfs use RTC for time stamping files. 2014-04-19 02:17:30 +01:00
Damien George ed5117f6a8 stmhal: Add pyb.unique_id, to get unique id of MCU. 2014-04-19 01:28:18 +01:00
Paul Sokolovsky 206dd2a905 stmhal: Update for mp_binary_get_size() refactor. 2014-04-19 03:27:37 +03:00
Damien George 44ee42de50 stmhal: Rename pyb.Led to pyb.LED to conform to naming rules.
It's Light Emitting Diode, so should be LED.
2014-04-19 00:54:33 +01:00
Damien George 8cf08a58a1 stmhal: Remove pyb.input (use sys.stdio.read(1) instead). 2014-04-19 00:50:50 +01:00
Damien George f20e093b9b stmhal: Add lots of constants to stm module. 2014-04-19 00:32:25 +01:00
Damien George 38ae014e42 stmhal: Update ADC, DAC and I2C objects to use new buffer protocol.
Main reason for expanding buffer protocol API was to support writes to a
buffer in ADC module (see read_timed).  With this change you can now
create an array of arbitrary type and ADC.read_timed will store into
that array in the correct format (byte, int, float).  I wonder though if
all these changes were really worth it to support just this function.
Hopefully this enhanced buffer protocol API (with typecode specified)
will be used elsewhere.
2014-04-18 23:28:56 +01:00
Damien George a8f5d15fc6 stmhal: Update help and comments re gpio changing to Pin. 2014-04-18 22:48:59 +01:00
Damien George c66d86c5ce stmhal: Big cleanup; merge gpio into Pin; make names consistent.
This is an attempt to clean up the Micro Python API on the pyboard.
Gpio functionality is now in the Pin object, which seems more natural.
Constants for MODE and PULL are now in pyb.Pin.  Names of some
classes have been adjusted to conform to CamelCase.  Other
miscellaneous changes and clean up here and there.
2014-04-18 22:38:09 +01:00
Damien George 906d383850 stmhal: Remove non-ascii character from include file. 2014-04-18 16:17:40 +01:00
Damien George 5b65f0c7d3 py: Rename USE_COMPUTED_GOTOS to USE_COMPUTED_GOTO and enable on stmhal.
On stmhal, computed gotos make the binary about 1k bigger, but makes it
run faster, and we have the room, so why not.  All tests pass on
pyboard using computed gotos.
2014-04-17 23:24:13 +01:00
Damien George d0f9f6cd3f py: Fix pfenv_print_strn to return correct number of chars printed.
With this fix, all tests in tests/basics pass on pyboard.
2014-04-17 18:58:09 +01:00
Damien George d553be5982 build: Simplify build directory layout by putting all headers in genhdr.
Any generated headers go in $(BUILD)/genhdr/, and are #included as
'genhdr/xxx.h'.
2014-04-17 18:03:27 +01:00
Damien George 2d1f865d16 Merge branch 'relocatable-build-dir' of github.com:lurch/micropython into lurch-relocatable-build-dir 2014-04-17 17:44:52 +01:00
Damien George 5f82b50324 Merge branch 'master' of github.com:micropython/micropython 2014-04-17 17:11:58 +01:00
Damien George fb06bfc11c stmhal: Clean up fatality indications; remove long-obsolete malloc0.c. 2014-04-17 17:04:15 +01:00
Damien George d7a4b69039 stmhal: Change VID to 0xf055=FOSS, and PID to a random number.
Needs a better solution.
2014-04-17 01:09:32 +01:00
Damien George b08f9212e2 Merge pull request #500 from dhylands/fix-sdcard-removed
Fix to allow usbd_msc_storage.c to compile when MICROPY_HW_HAS_SDCARD is...
2014-04-17 00:23:43 +01:00
Damien George 89831d0289 stmhal: Add more math functions.
Taken straight from musl and newlib.  License seems compatible with MIT.
2014-04-17 00:13:13 +01:00
Damien George efc22e376f stmhal: Fix 64-byte USB packet bug properly.
A 64-byte packet is now followed by a 0-byte packet if there is nothing
more to send.  This flushes the USB endpoint.
2014-04-17 00:12:07 +01:00
Damien George 28817725fc stmhal: Replace magic number 3 with CDC_IN_EP define. 2014-04-16 23:17:29 +01:00
Damien George 6d983539bc stmhal: Improve flash storage cache management.
Internal flash used for the filesystem is now written (from the cache)
only after a 5s delay, or when a file is closed, or when the drive is
unmounted from the host.  This delay means that multiple writes can
accumulate in the cache, and leads to less writes to the flash, making
it last longer.

It's implemented by a high-priority interrupt that takes care of flash
erase and write, and flushing the cache.

This is still only an interim solution for the flash filesystem.  It
eventually needs to be replaced with something that uses less RAM for
the cache, something that can use more of the flash, and something that
does proper wear levelling.
2014-04-16 23:08:36 +01:00
Andrew Scheller 70a7d7a943 build directory can now be renamed
The autogenerated header files have been moved about, and an extra
include dir has been added, which means you can give a custom
BUILD=newbuilddir option to make, and everything "just works"

Also tidied up the way the different Makefiles build their include-
directory flags
2014-04-16 22:16:28 +01:00
Dave Hylands e553ff2f75 Fix to allow usbd_msc_storage.c to compile when MICROPY_HW_HAS_SDCARD isn't defined. 2014-04-16 10:01:17 -07:00
Damien George f6be480bda stmhal: Add pyb.have_cdc function to check if USB CDC device is enabled. 2014-04-16 15:52:50 +01:00
Damien George 9388a90842 stmhal: Fix USB CDC buffer overrun error.
Need to wait for the low-level USB driver to send the data over the USB
in-endpoint before the buffer can be used again.  This patch adds a
check for this.
2014-04-16 15:51:27 +01:00
Damien George bda2f70964 Merge pull request #498 from lurch/create-headers-from-files
Auto-generate the stmhal/pybcdc_inf header file from static files
2014-04-16 10:54:16 +01:00
Damien George 1381146382 stmhal: Fix C bindings of I2C.read/write. 2014-04-16 10:43:03 +01:00
Andrew Scheller 1452221aca Auto-generate the stmhal/pybcdc_inf header file from static files
The USB VID&PID are automatically extracted from usbd_desc_cdc_msc.c
and inserted into pybcdc_inf.template, ensuring that the same USB
IDs get used everywhere
2014-04-16 02:41:26 +01:00
Damien George 2822d4e6ce stmhal: Add I2C functions for pure master read/write. 2014-04-16 00:27:14 +01:00
Damien George d5323f07ff Merge pull request #496 from dhylands/fix-debug-usart
Fix call to enable pyb_usart_global_debug.
2014-04-15 21:25:27 +01:00
Dave Hylands 00adf67179 Fix call to enable pyb_usart_global_debug. 2014-04-15 12:20:31 -07:00
Damien George 9699ea6a2f stmhal: Fix USB MSC so that it unmounts correctly on Mac OS X.
Mac OS X sends a SCSI command to remove the medium when it unmounts a
drive.  If this command is not honoured, then OS X will automatically
remount the drive, making it impossible to eject.  This patch disables
the USB MSC when the right SCSI command is sent.
2014-04-15 19:56:32 +01:00
Damien George 4d7f4eb6a9 stmhal: Add ADC function to read data at a given frequency.
Reads ADC values into a bytearray (or similar) at a fixed rate.  Needs a
better name and improved API.  Also fix up DAC dma function (which also
needs a better name and API).
2014-04-15 19:52:56 +01:00
Damien George e95da5b784 stmhal: Add I2C.scan method, to scan all devices on the bus.
Simple way to find the address of an attached I2C device.
2014-04-15 19:24:13 +01:00
Damien George f6d25ecf7b stmhal: Add simple README.txt to freshly-created filesystem. 2014-04-15 19:20:25 +01:00
Damien George c13d0b3304 stmhal: Wrap skin-named-usarts in PYBV10 #if. 2014-04-15 11:52:47 +01:00
Damien George cce7119a2b stmhal: Work around crazy bug in USB CDC.
Packets of 64 bytes length are not send to the host until the following
packet is sent.  Fixed by never sending packets of 64 bytes length.
2014-04-14 01:46:25 +01:00
Damien George 7e5be0b1b4 stmhal: Improved usart module a bit. 2014-04-14 01:45:58 +01:00
Damien George 6dba016a56 stmhal: Add pyb.wfi() function (calls __WFI). 2014-04-14 01:45:24 +01:00
Damien George 86a03044e3 stmhal: Add stdin/stdout/stderr objects.
Available via sys.std{in,out,err}.  Basic reading and writing supported.
Even sys.stdin.readline!
2014-04-13 19:00:56 +01:00
Damien George 212f89e61a stmhal: Improve USB CDC write function (increase timeout). 2014-04-13 16:39:04 +01:00
Damien George 73496fbbe4 py: Fix up source-line calculation.
Should address issue #475.
2014-04-13 14:51:56 +01:00
Damien George cb861a5c6a stm[hal]: Init mp_sys_path and mp_sys_argv correctly. 2014-04-13 13:19:09 +01:00
Damien George 640e7e4779 Merge pull request #476 from pfalcon/static-sys
Convert sys module to static allocation
2014-04-13 12:52:39 +01:00
Damien George 8a1cab952f py: Fix mp_get_buffer, and use it in more places.
Must use mp_obj_get_type to get the type of an object.  Can't assume
mp_obj_t is castable to mp_obj_base_t.
2014-04-13 12:08:52 +01:00
Damien George 0aab675108 stmhal: Little hack to dump GC allocation table using pyb.info().
Pass a single parameter (doesn't matter what): pyb.info(1), will dump
the GC alloc table.
2014-04-13 11:10:58 +01:00
Paul Sokolovsky 4165cd1c0c stmhal: Update for static mod sys. 2014-04-13 07:02:57 +03:00
Damien George 82c7b1b1d5 stmhal: Put a USB structure in ROM; GC doesn't scan the data segment. 2014-04-12 18:50:20 +01:00
Damien George b96c7c03ca stmhal: Move fatfs volume/partition lookup table to ROM. 2014-04-12 00:51:57 +01:00
Damien George 60427864b1 stmhal: Move I2C objects to ROM. 2014-04-12 00:51:41 +01:00
Damien George 037b3e0e21 Merge pull request #458 from lurch/patch-1
Tweak pybcdc.inf to match recent changes to pybcdc.h
2014-04-10 22:51:48 +01:00
Damien George 3f4898456b stmhal: Add stm module, which contains some constants for the MCU.
Also contains raw memory read/write functions, read8, read16, read32,
write8, write16, write32.  Can now do:

stm.write16(stm.GPIOA + stm.GPIO_BSRRL, 1 << 13)

This turns on the red LED.

With the new constant folding, the above constants for the GPIO address
are actually compiled to constants (and the addition done) at compile
time.  For viper code and inline assembler, this optimisation will make
a big difference.  In the inline assembler, using these constants would
not be possible without this constant folding.
2014-04-10 22:46:40 +01:00
Andrew Scheller fec6f018ee Tweak pybcdc.inf to match recent changes to pybcdc.h 2014-04-10 02:07:55 +01:00
Damien George 7a5f9e94ad stmhal: Make /src/main.py just /main.py; allow SD to be used as root device. 2014-04-09 23:30:34 +01:00
Damien George a5c18f3285 stmhal: Update windows driver; \r\n newlines and addition USB id. 2014-04-09 02:23:24 +01:00
Damien George b99ca2cdde stmhal: Add windows cdc .inf driver to flash filesystem. 2014-04-09 01:16:49 +01:00
Damien George 8e6f98b166 stmhal: Improve help() function. 2014-04-09 01:16:29 +01:00
Damien George 229347139b stmhal: Add functionality to Servo object.
Can now calibrate, set pulse width, angle and speed.
2014-04-09 00:45:45 +01:00
Dave Hylands 3bbceeaaf7 Fix make-pins.py to support having multiple names for a pin.
SW and X17 now both map to PB3
2014-04-08 15:45:47 -07:00
Damien George b04488151e stmhal: Make USRSW re-register the EXTI callback each time it's set. 2014-04-08 22:35:42 +01:00
Damien George 2137bc7124 stmhal: in EXTI interrupt handler wrap uPy calls in gc_lock and nlr_buf. 2014-04-08 15:21:26 +01:00
Damien George 26cf55ae05 Add a check for NULL nlr_top in nlr_jump.
If no nlr_buf has been pushed, and an nlr_jump is called, then control
is transferred to nlr_jump_fail (which should bail out with a fatal
error).
2014-04-08 14:08:14 +00:00
Damien George 97790455fe Improve REPL detecting when input needs to continue.
Full CPython compatibility with this requires actually parsing the
input so far collected, and if it fails parsing due to lack of tokens,
then continue collecting input.  It's not worth doing it this way.  Not
having compatibility at this level does not hurt the goals of Micro
Python.
2014-04-08 11:04:29 +00:00