Wykres commitów

59 Commity (8e008449298d95addf6bd56f448b0d100b163399)

Autor SHA1 Wiadomość Data
Paul Sokolovsky eac22e29a5 all: Consistently update signatures of .make_new and .call methods.
Otherwise, they serve reoccurring source of copy-paste mistakes and
breaking nanbox build.
2017-01-04 16:10:42 +03:00
Damien George d2d9dfcd40 stmhal: Remove obsolete code for special handling of TIM3 irq settings.
TIM3 is no longer special, or at least does not have special IRQ settings.
2016-08-22 12:24:49 +10:00
Dave Hylands c6983e3ce0 stmhal: Fix timer capture/compare interrupt handling for TIM1 and TIM8.
It turns out that TIM1 and TIM8 have their own Capture/Compare
interrupt vector. For all of the other timers, the capture/compare
interrupt vector is the same as the update vector.

So we need to add handlers for these vectors and enable them
when using capture/compare callbacks.

During testing of this, I also found that passing a channel callback
into the channel constructor would not enable interrupts properly.

I tested using:
```
>>> pyb.Timer(1, freq=4).channel(1, pyb.Timer.OC_TOGGLE, callback=lambda t: print('.', end=''))
```
I tested the above with channels 1, 4, and 8
2016-08-22 12:18:04 +10:00
Tobias Badertscher 31f5dc065a stmhal: L4: Modify timer.c to support L4 MCU. 2016-04-17 12:16:13 +01:00
Damien George a8a4b01af6 stmhal: Add PWM capability for LED(3) and LED(4) on pyboards.
USB CDC no longer needs TIM3 (which was originally used for LED(4) PWM)
and so TIM3 has been freed for general purpose use by the user.  Hence
LED(4) lost its PWM capabilities.

This patch reinstates the PWM capabilities using a semi-generic piece
of code which allows to configure a timer and PWM channel to use for any
LED.  But the PWM capability is only configured if the LED is set to an
intensity between 1 and 254 (ie only when needed).  In that case the
relevant timer is configured for PWM.  It's up to the user to make sure
the timers are not used if PWM is active.

This patch also makes sure that PWM LEDs are turned off using standard
GPIO when calling led.off() or led.intensity(0), instead of just setting
the PWM counter to zero.
2016-01-29 22:44:43 +00:00
Damien George ea89b80ff4 stmhal: Make TIM3 available for use by the user.
TIM3 is no longer used by USB CDC for triggering outgoing data, so we
can now make it available to the user.

PWM fading on LED(4) is now gone, but will be reinstated in a new way.
2016-01-29 22:31:56 +00:00
Damien George d363133917 stmhal: Make USB CDC driver use SOF instead of TIM3 for outgoing data.
Previous to this patch the USB CDC driver used TIM3 to trigger the
sending of outgoing data over USB serial.  This patch changes the
behaviour so that the USB SOF interrupt is used to trigger the processing
of the sending.  This reduces latency and increases bandwidth of outgoing
data.

Thanks to Martin Fischer, aka @hoihu, for the idea and initial prototype.

See PR #1713.
2016-01-29 15:21:43 +00:00
Damien George 5b3f0b7f39 py: Change first arg of type.make_new from mp_obj_t to mp_obj_type_t*.
The first argument to the type.make_new method is naturally a uPy type,
and all uses of this argument cast it directly to a pointer to a type
structure.  So it makes sense to just have it a pointer to a type from
the very beginning (and a const pointer at that).  This patch makes
such a change, and removes all unnecessary casting to/from mp_obj_t.
2016-01-11 00:49:27 +00:00
Damien George f54a96d6a2 stmhal/timer: Use mp_float_t instead of float.
This way mp_float_t can be changed to, eg, double.
2015-12-09 17:39:34 +00:00
Damien George 66b96822fb stmhal: Add option to free up TIM3 from USB VCP polling.
This is a hack to free up TIM3 so that it can be used by the user.
Instead we use the PVD irq to call the USB VCP polling function, and
trigger it from SysTick (so SysTick itself does not do any processing).

The feature is enabled for pyboard lite only, since it lacks timers.
2015-12-04 14:07:15 +00:00
Damien George e99e6c883d stmhal: Move flash storage idle tick handler from TIM3 to SysTick.
Using SysTick to do the counting and dispatch of the flash storage idle
handler is more efficient than requiring a dedicated hardware timer.
No new counter is needed, just the existing uwTick variable.  The
processing is not actually done in the SysTick IRQ, it is deferred to
the flash IRQ (which runs at lower priority).
2015-11-24 16:18:07 +00:00
Dave Curtis 32b3549cce stmhal: Add symbolic #defines for interrupt levels in irq.h. 2015-11-01 23:23:39 +00:00
Damien George 731f359292 all: Add py/mphal.h and use it in all ports.
py/mphal.h contains declarations for generic mp_hal_XXX functions, such
as stdio and delay/ticks, which ports should provide definitions for.  A
port will also provide mphalport.h with further HAL declarations.
2015-10-31 19:14:30 +03:00
Dave Hylands ea8bf81058 stmhal: Replace #include "stm32f4xx_hal.h" with #include STM32_HAL_H. 2015-07-30 00:38:25 +01:00
Damien George 7693ef3bd6 stmhal: Allow ADC.read_timed to take Timer object in place of freq.
This allows a user-specified Timer for the triggering of the ADC read,
mirroring the new behaviour of DAC.write_timed.

Addresses issue #1129.
2015-07-22 19:41:13 +01:00
Damien George abc24c1876 stmhal: Allow DAC.write_timed to take Timer object in place of freq.
This allows the DAC to use a user-specified Timer for the triggering
(instead of the default Timer(6)), while still supporting original
behaviour.

Addresses issues #1129 and #1388.
2015-07-21 23:39:49 +01:00
Dave Hylands fdcb3b7ebb stmhal: Actually disable unhandled timer interrupts. 2015-04-28 00:17:05 -07:00
Dave Hylands fd787c5e4e stmhal: Reset the timer counter to zero after changing the auto reload.
Because if the counter is above the new value of the auto-reload register
then it may be a long time until the timer wraps around.
2015-04-22 23:31:56 +01:00
Damien George c92c7a69fd stmhal: Exclude code for those timers that don't exist in the hardware. 2015-04-18 21:40:58 +01:00
blmorris 4c45921349 stmhal: Use new %q format to print qstr's in a few more places.
Saves 68 bytes.
2015-04-16 22:30:00 +01:00
Damien George 7f9d1d6ab9 py: Overhaul and simplify printf/pfenv mechanism.
Previous to this patch the printing mechanism was a bit of a tangled
mess.  This patch attempts to consolidate printing into one interface.

All (non-debug) printing now uses the mp_print* family of functions,
mainly mp_printf.  All these functions take an mp_print_t structure as
their first argument, and this structure defines the printing backend
through the "print_strn" function of said structure.

Printing from the uPy core can reach the platform-defined print code via
two paths: either through mp_sys_stdout_obj (defined pert port) in
conjunction with mp_stream_write; or through the mp_plat_print structure
which uses the MP_PLAT_PRINT_STRN macro to define how string are printed
on the platform.  The former is only used when MICROPY_PY_IO is defined.

With this new scheme printing is generally more efficient (less layers
to go through, less arguments to pass), and, given an mp_print_t*
structure, one can call mp_print_str for efficiency instead of
mp_printf("%s", ...).  Code size is also reduced by around 200 bytes on
Thumb2 archs.
2015-04-16 14:30:16 +00:00
Dave Hylands 49d8e5ebaa stmhal: Fix a bug related to unhandled channel interrupts.
This also cleans up spurious interrupts which happen at timer
initilaization time.
2015-03-20 23:40:50 +00:00
Dave Hylands b4c9a25eab stmhal: Add support for quadrature encoder mode to pyb.TimerChannel. 2015-03-09 13:23:14 +00:00
Damien George d38939e676 stmhal: Reset state of timer when deinit is called. 2015-02-23 13:18:14 +00:00
Dave Hylands caf5c40c19 stmhal: Fix problem when passing callback= to timer init function.
In particular, make sure that the globals are all initialized
before enabling the interrupt, and also make sure that the timer
interrupt has been initialied before enabling the NVIC.
2015-02-22 19:58:51 -08:00
Damien George 418ec8bbba stmhal: Properly deinit timer object.
Addresses issue #1113.
2015-02-13 11:57:29 +00:00
Damien George 7a53ac8ec2 stmhal: Allow to build without float support if wanted. 2015-01-08 17:55:55 +00:00
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 2cf6dfa280 stmhal: Prefix includes with py/; remove need for -I../py. 2015-01-01 21:06:20 +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
Dave Hylands 1c795445b3 Add support for complimentary channel output and deadtime.
This patch enables output on the complimentary channels (TIMx_CHyN).
For timers 1 and 8, deadtime can also be inserted when the channels
transition. For the pyboard, TIM8_CH1/CH1N and TIM8_CH2/CH2N can
take advantage of this.
2014-10-10 13:54:03 -07:00
Damien George d03c681608 stmhal: Use mp_uint_t where appropriate.
Found these by compiling stmhal with mp_uint_t of type uint32_t instead
of unsigned int.  This actually makes a difference to the code, but just
a curiosity.
2014-10-05 21:51:54 +01:00
Damien George ba0383a8c7 stmhal, timer: Fix timer.chanel so mode can be a keyword. 2014-10-05 17:52:45 +01:00
Damien George 55f68b3ce8 stmhal, timer: Improve accuracy of freq computation. 2014-10-05 17:52:45 +01:00
Damien George 97ef94df83 stmhal, timer: Set freq from float; get timer source freq.
Timers now have the following new features:
- can init freq using floating point; eg tim.init(freq=0.1)
- tim.source_freq() added to get freq of timer clock source
- tim.freq() added to get/set freq
- print(tim) now prints freq
2014-10-05 17:52:44 +01:00
Damien George 24119176e7 stmhal: Allow pyb.freq() function to change SYSCLK frequency.
Eg pyb.freq(120000000) sets the CPU to 120MHz.  The frequency can be set
at any point in the code, and can be changed as many times as you like.
Note that any active timers will need to be reconfigured after a freq
change.

Valid range is 24MHz to 168MHz (but not all freqs are supported).  The
code maintains a 48MHz clock for the USB at all times and it's possible
to change the frequency at a USB REPL and keep the REPL alive (well,
most of the time it stays, sometimes it resets the USB for some reason).
Note that USB does not work with pyb.freq of 24MHz.
2014-10-04 01:54:31 +01:00
Damien George f042d7a4d7 stmhal: Fix edge case for timer PWM of 100%.
Also improve precision of calculating PWM percent in integer mode.
Also update teensy with edge case fix.
2014-09-29 14:15:01 +01:00
Dave Hylands 39296b40d4 Fix timer overflow code.
Teensy doesn't need to worry about overflows since all of
its timers are only 16-bit.

For PWM, the pulse width needs to be able to vary from 0..period+1
(pulse-width == period+1 corresponds to 100% PWM)

I couldn't test the 0xffffffff cases since we can't currently get a
period that big in python. With a prescaler of 0, that corresponds
to a freq of 0.039 (i.e. cycle every 25.56 seconds), and we can't
set that using freq or period.

I also tested both stmhal and teensy with floats disabled, which
required a few other code changes to compile.
2014-09-27 19:40:37 -07: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
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 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 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 bf133f7737 stmhal: Resolve question in comment about timer clock. 2014-08-14 00:30:14 +01:00
Damien George 40f3c02682 Rename machine_(u)int_t to mp_(u)int_t.
See discussion in issue #50.
2014-07-03 13:25:24 +01:00
Damien George e70b5dbe58 stmhal: Some reordering of code/functions. 2014-07-02 14:09:44 +01:00
Dave Hylands 0d81c133b3 Add timer_deinit and call it just before doing a soft-restart
This fixes #733.
2014-06-30 08:07:38 -07:00
Emmanuel Blot f6932d6506 Prefix ARRAY_SIZE with micropython prefix MP_ 2014-06-19 18:54:34 +02:00
Damien George 04b9147e15 Add license header to (almost) all files.
Blanket wide to all .c and .h files.  Some files originating from ST are
difficult to deal with (license wise) so it was left out of those.

Also merged modpyb.h, modos.h, modstm.h and modtime.h in stmhal/.
2014-05-03 23:27:38 +01:00
Damien George 5874c1c92b stmhal: Remove #include <stdint.h> from mpconfigport.h.
Make include dependencies neater, and adheres to the coding convention
that headers should not include headers.
2014-05-03 13:24:21 +01:00