Commit Graph

1142 Commits

Author SHA1 Message Date
Pavol Rusnak 8f3cf6e6a8 stmhal/usb: Use correct ClassData structure for HID receive. 2016-10-04 15:38:32 +11:00
Philip Potter eb239b8398 stmhal/usb: Add support to receive USB HID messages from host. 2016-10-04 15:38:01 +11:00
Philip Potter 03de5a13cf stmhal/usbdev: Add OUT endpoint to HID interface. 2016-10-04 15:20:11 +11:00
Dave Hylands 1f433c719b stmhal: Fix linker map for STM32L476 chips.
In particular, this makes the L4 .isr_vector section 16K in size so it's
the same as the F4/F7 MCUs.  The patch also moves the L4 filesystem to
the end of flash, which allows for 512K filesystem on the 1Mb devices
like the STM32L476DISC.
2016-10-04 14:31:19 +11:00
Damien George bd925b59c3 stmhal/spi: Enable use of fast software SPI. 2016-10-04 13:51:30 +11:00
Damien George b932b2dd1f extmod/machine_spi: Use delay_half, not baudrate, for internal timing.
The delay_half parameter must be specified by the port to set up the
timing of the software SPI.  This allows the port to adjust the timing
value to better suit its timing characteristics, as well as provide a
more accurate printing of the baudrate.
2016-10-04 13:43:02 +11:00
Damien George 9f1e395c16 stmhal/spi: Use software SPI if no periph id given, even if pins given.
It's simpler to just default to always using software SPI if no specific
peripheral id/name is given.  To use hardware SPI users must specify a
hardware peripheral id as the first parameter to the SPI constructor.
2016-10-04 13:38:11 +11:00
Damien George 5deedd6685 stmhal/mphalport: Fix mp_hal_pin_write to use correct pin_mask. 2016-10-03 18:06:58 +11:00
Damien George d4a5ca5056 stmhal/spi: Make machine.SPI class conform to correct API.
Includes both software and hardware SPI implementations.
2016-10-03 17:12:43 +11:00
Damien George 077dbf4a86 stmhal/mphalport: Implement mp_hal_pin_{input,output,write}. 2016-10-03 16:44:34 +11:00
Damien George a22a67661a stmhal/spi: Simplify spi_transfer function to take only one buf len arg. 2016-10-03 12:47:56 +11:00
Damien George 5bb28c7f10 extmod/machine_spi: Simplify SPI xfer function to only take one buf len.
There is no need to take src_len and dest_len arguments.  The case of
reading-only with a single output byte (originally src_len=1, dest_len>1)
is now handled by using the output buffer as the input buffer, and using
memset to fill the output byte into this buffer.  This simplifies the
implementations of the spi_transfer protocol function.
2016-10-03 12:39:31 +11:00
Krzysztof Blazewicz 6aea34ad89 lib/cmsis: move CMSIS headers to lib/
Files in lib/cmsis are generic for all Cortex-M MCU's
files left in stmhal/cmsis are all STM32 specific.
2016-09-30 16:19:03 +10:00
Damien George 53bfcc9e84 stmhal: Remove CMSIS STM32F2xx files, they are unused/unsupported. 2016-09-28 15:09:03 +10:00
Nicholas Graumann 7165fbd8f4 stmhal: Add virtual com port support for STM32L476DISC. 2016-09-27 22:08:55 -05:00
Damien George 88ca7ff565 stmhal/modmachine: Fix clearing of reset-cause flags.
To reset the flags we should write to the single bit only, not the entire
register (otherwise all other settings in the register are cleared).

Fixes #2457.
2016-09-27 15:49:35 +10:00
Krzysztof Blazewicz 1f69b16d3f stmhal: Remove STM32CubeF2 HAL files, they are unused/unsupported. 2016-09-22 12:11:01 +10:00
Krzysztof Blazewicz 9310dad15d stmhal: Put common definitions from linker files to common.ld. 2016-09-22 12:03:12 +10:00
Damien George 93c4a6a3f7 all: Remove 'name' member from mp_obj_module_t struct.
One can instead lookup __name__ in the modules dict to get the value.
2016-09-22 00:23:16 +10:00
Stefan Agner b0a46900de stmhal: Use attribute to avoid inlining.
Use MP_NOINLINE macro to avoid inlining of init_flash_fs. This helps
to keep stack usage of main() low.
2016-09-20 20:41:11 -07:00
Damien George 4874bde104 stmhal/boards: For OLIMEX_E407, enable UART1 and fix I2C1 mapping.
UART1 can be used even if the switch is enabled.  The schematics for this
board make I2C1 available on PB8/PB9, even though it can also be mapped
to PB6/PB7.

See #2396 and #2427.
2016-09-19 13:00:15 +10:00
Damien George 0fd3d8d19f stmhal/boards: Add pllvalues.py script to compute PLL values for sysclk.
The algorithm here should mirror that in the machine.freq() function.
2016-09-14 13:00:27 +10:00
Krzysztof Blazewicz 1ba516f475 stmhal/extint: Force 0 to 1 transition on swint().
If a user tries to call `swint()` while interrupt is disabled the flag in
SWIER is set but the interrupt is not triggered and therefore the SWIER bit
is not cleared.  When the interrupt is again enabled the next call to
`swint()` won't trigger the IRQ because a 0 to 1 transition will not occur.
2016-09-09 19:35:21 +10:00
Krzysztof Blazewicz 06a1194300 stmhal/{accel,lcd}: use GPIO_{set,clear}_pin
different HAL versions implement GPIO differently (BSRR vs BSRRH+BSRRL),
this way both drivers are portable between different HAL's
2016-09-09 10:38:08 +02:00
Tom Soulanille d89de18f40 stmhal/lcd: De-assert chip select after completing SPI transmission.
The LCD interface library fails to deassert the chip select of the LCD
after an SPI transmission.  Consequently using the SPI with other
peripherals disturbs the state of the LCD.  This patch changes
lcd.lcd_out() to deassert CS after each transmission to the LCD.
2016-09-09 14:51:00 +10:00
Damien George f3b5480be7 stmhal,cc3200,esp8266: Consistently use PWRON_RESET constant.
machine.POWER_ON is renamed to machine.PWRON_RESET to match other
reset-cause constants that all end in _RESET.  The cc3200 port keeps a
legacy definition of POWER_ON for backwards compatibility.
2016-09-08 12:50:38 +10:00
Damien George 9103cbe366 stmhal/modmachine: Implement machine.reset_cause() function, and consts. 2016-09-06 14:20:19 +10:00
Damien George b88bf6c76b stmhal/wdt: Implement keyword args to WDT constructor. 2016-09-06 14:19:40 +10:00
Peter Hinch ef47a67cf4 stmhal/dac: Fix DAC (re-)initialisation by resetting DMA.
Fixes issue #2176.
2016-09-05 15:07:23 +10:00
Damien George 9526e24234 unix,stmhal,esp8266: When find'ing frozen files follow symbolic links.
It's useful to be able to use symbolic links to add files and directories
to the set of scripts to be frozen.
2016-09-05 12:35:05 +10:00
Delio Brignoli e2ac8bb3f1 py: Add MICROPY_USE_INTERNAL_PRINTF option, defaults to enabled.
This new config option allows to control whether MicroPython uses its own
internal printf or not (if not, an external one should be linked in).
Accompanying this new option is the inclusion of lib/utils/printf.c in the
core list of source files, so that ports no longer need to include it
themselves.
2016-09-05 12:18:53 +10:00
Dave Hylands fedab995ee stmhal: Set STM32F7DISC CPU Frequency to 216 MHz
This set the CPU frequency to 216 MHz (the max) and
leaves the USB Frequency at 48 MHz.

These settings were copied from one of the HAL examples.
2016-09-04 18:14:41 +10:00
Damien George 76c366df56 stmhal: Add machine.WDT class.
Usage:

    import machine
    wdt = machine.WDT(0, 5000) # 5 second timeout
    wdt.feed()

Thanks to Moritz for the initial implementation.
2016-09-04 00:12:48 +10:00
Damien George 49406b0ac6 stmhal/spi: Support new machine SPI methods in legacy SPI object. 2016-09-01 16:40:35 +10:00
Damien George 9b64d1966b stmhal/spi: Factor out SPI transfer code to a single function. 2016-09-01 16:40:32 +10:00
Damien George 9c04ef2a67 unix,stmhal,esp8266: When find'ing frozen files don't use extra slash.
This extra forward slash for the starting-point directory is unnecessary
and leads to additional slashes on Max OS X which mean that the frozen
files cannot be imported.

Fixes #2374.
2016-08-31 15:12:57 +10:00
Philip Potter c777b6950e stmhal: Update boot.py files to use VCP instead of CDC. 2016-08-29 15:17:34 +10:00
Krzysztof Blazewicz fc73c9b4b2 stmhal/modusocket: set self->nic to MP_OBJ_NULL after socket close
This patch makes second and next calls to <socket>.close() a no-op.
It prevents GC from closing the underlying resource after user
already used <socket>.close() explicitly.

fixes #2355
2016-08-26 10:57:32 +02:00
Dave Hylands a589fa3e0b stmhal: Update pin print to print new constants
This updates the print function for machine.Pin to
print out the new constants from the Hardware API defintion
rather than the legacy definitions.
2016-08-25 16:11:42 +10:00
Matt Brejza 5af6184e72 stmhal: Make ADC channel 16 available on L4 MCUs. 2016-08-25 13:49:51 +10: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
Damien George 675d1c9c60 ports: Remove typedef of machine_ptr_t, it's no longer needed.
This type was used only for the typedef of mp_obj_t, which is now defined
by the object representation.  So we can now remove this unused typedef,
to simplify the mpconfigport.h file.
2016-08-15 11:02:59 +10:00
Tobias Badertscher af9889f99a stmhal/adc.c: Get ADC working on STM32L4 MCUs.
Fixing Issue #2243. Main problems were:

- HAL_ADC_GetState(adcHandle) may return other bits set (not only
  HAL_ADC_STATE_EOC_REG) when called - so I AND-ed it out as proposed by
  mattbrejza in Issue #2243.
- ADC Pin has to be configured as GPIO_MODE_ANALOG_ADC_CONTROL not only
  GPIO_MODE_ANALOG.
- Resolved ADC resolution L4 specific (Use L4 define ADC_RESOLUTION_12B).
- Changed setting of Init.EOCSelection toADC_EOC_SINGLE_CONV for L4.
- Added call to ADC_MultiModeTypeDef as this is done on a STM32Cube
  generated project too.
- Clean up: Configuration of ADC is done only in ONE function not the same
  is done in two functions.

Test is done on PA5 pin of STM32L4Discovery-Kit which is connected to the
DOWN button.

Thanks to mattbrejza for discovering the bug.
2016-08-11 13:01:57 +10:00
Damien George dfb8144037 stmhal/boards: Update STM32L476 pin defs to include ADC channels.
This patch introduces proper ADC Pin definitions in stm32l476_af.csv.
Originally provided by @tobbad.
2016-08-11 13:01:57 +10:00
David Siorpaes b67eb20ed0 stmhal: Fix I2C mappings for STM32F429DISC board. 2016-08-04 22:51:53 +10:00
Dave Hylands 460bceca39 stmhal: Make SPI NSS pin definition optional.
Some boards (like the GHI Electronics G30 Dev Board) don't use
NSS at all and rather just use GPIO chip selects.
2016-07-30 22:08:20 +03:00
Matt Brejza afd4909a0f stmhal: fixing malloc when used with external libraries 2016-07-30 21:24:35 +03:00
dpslwk f3636a7b46 stmhal: Enable SD card on L4 MCUs. 2016-06-29 14:29:01 +01:00
dpslwk b03df60f32 stmhal: Correct DMA to allow SD card on L4 MCUs. 2016-06-29 14:28:49 +01:00
dpslwk 14b7c3e59c stmhal: Update HALCOMMITS due to change to hal 2016-06-29 14:28:49 +01:00
dpslwk daa279a3a1 stmhal: Port of f4 hal commit 1d7fb82 to l4 hal 2016-06-29 14:27:55 +01:00
Paul Sokolovsky 07209f8592 all: Rename mp_obj_type_t::stream_p to protocol.
It's now used for more than just stream protocol (e.g. pin protocol), so
don't use false names.
2016-06-18 18:44:57 +03:00
Stefan Hölzl c8332a5463 stmhal: Add board definition files for Olimex STM32-E407. 2016-06-06 10:21:02 +01:00
Tobias Badertscher 1191ec6a14 stmhal/uart.c: Fix wrong baudrate calculation for stm32l4 series. 2016-06-03 14:24:59 +01:00
Peter Hinch 641300dccb stmhal/dac: DAC deinit() method added. 2016-05-31 13:10:35 +03:00
Paul Sokolovsky 2503b59592 stmhal/moduos: getcwd(): Use mp_obj_new_exception_arg1().
Argument types were converted, but old function call of
mp_obj_new_exception_msg_varg() remained.
2016-05-29 20:04:32 +03:00
Damien George 4b37e775ea extmod/machine_i2c: Redo mp_hal_pin macros to use open_drain and od_low.
mp_hal_pin_config_od is renamed mp_hal_pin_open_drain, and mp_hal_pin_low
is mp_hal_pin_od_low.
2016-05-26 17:06:40 +01:00
Damien George 3e03d1b87e stmhal: Support frozen packages using .mpy files.
See issue #1814.
2016-05-23 13:29:56 +01:00
Damien George 87981fc517 stmhal/sdcard: Allow to do unaligned read-from/write-to SD card.
For example, the following code now works with a file on the SD card:

    f = open('test', 'rb') # test must be 1024 bytes or more in size
    f.seek(511)
    f.read(513)

Also works for writing.

Fixes issue #1863.
2016-05-13 14:45:40 +01:00
Damien George 1e388079f9 stmhal/i2c: Expose I2CHandle3 for use by custom C code.
If custom C code uses the I2C busses then it needs access to these
structures for i2c_init().
2016-05-13 11:23:32 +01:00
Damien George 1dc2862a83 stmhal/led: Allow LEDs to be in PWM mode with TIM1 and channels 1-4.
This allows PYBv3 to use PWM for LED(1) and LED(2).
2016-05-13 11:01:21 +01:00
Damien George 79a38a7a43 stmhal: For network drivers, convert to use MP_Exxx errno symbols. 2016-05-10 23:45:33 +01:00
Damien George 5ab98d5c41 stmhal: Convert to use internal errno symbols; enable uerrno module. 2016-05-10 23:30:39 +01:00
Tobias Badertscher b924f649cd stmhal: Fix clock configuration for STM32L476-discovery; also add I2C2. 2016-05-10 09:20:30 +01:00
Henrik Sölver c4587e2426 stmhal/can: Allow to get existing CAN obj if constructed without args.
Initialisation of CAN objects should now behave as other peripheral
objects.

Fixes issue #2001.
2016-05-08 12:47:33 +01:00
Damien George 88153dc56a stmhal/sdcard: Fix initialisation of DMA TX so that writes work.
Addresses issue #2034.
2016-05-06 10:53:25 +01:00
Dave Hylands cbbeb786d7 stmhal/dma: Fix builds for boards with an F4 or F7 but no DAC. 2016-05-06 09:57:33 +01:00
Damien George 08d3d5d9ab stmhal: For LIMIFROG board, add early-init function to get to DFU mode. 2016-05-05 17:00:30 +01:00
Tobias Badertscher 770f169e63 stmhal: Add board files for LIMIFROG board. 2016-05-05 17:00:16 +01:00
Damien George 05d1664981 stmhal/dma: Make DAC DMA descriptors conditional on having a DAC. 2016-05-05 15:34:01 +01:00
Tobias Badertscher 0f846e563c stmhal: L4: Add support for machine.sleep on STM32L4 MCUs.
Also raise an exception for machine.freq and machine.deepsleep on this
MCU, since they are not yet implemented.
2016-05-05 15:28:55 +01:00
Tobias Badertscher 7441ba7749 stmhal: L4: Make CCM/DTCM RAM start-up conditional on MCU type. 2016-05-05 15:19:33 +01:00
Tobias Badertscher adaaf439b0 stmhal: L4: Adapt startup code, clock configuration and interrupts. 2016-05-05 15:14:42 +01:00
Tobias Badertscher e64032d6fd stmhal: L4: Adapt DMA to be able to support STM32L4 MCU series.
The main thing is to change the DMA code in a way that the structure
DMA_Stream_TypeDef (which is similar to DMA_Channel_TypeDef on stm32l4)
is no longer used outside of dma.c, as this structure only exists for the
F4 series.  Therefore I introduced a new structure (dma_descr_t) which
handles all DMA specific stuff for configuration.  Further the periphery
(spi, i2c, sdcard, dac) does not need to know the internals of the dma.
2016-05-05 14:51:20 +01:00
Damien George 70ff7350e7 stmhal, cc3200: Change i2c.scan() method to scan addresses 0x08-0x77.
A standard I2C address is 7 bits but addresses 0b0000xxx and 0b1111xxx
are reserved.  The scan() method is changed to reflect this, along with
the docs.
2016-05-02 11:15:36 +01:00
Damien George 12c61ddddd stmhal/accel: Raise an exception if the accel couldn't be initialised.
On PYBLITEv1.0 there is no accelerometer and in this case the Accel()
constructor should not silently succeed.
2016-04-29 15:43:15 +01:00
Damien George a63542387d extmod, stmhal: Fix typo of macro that detects if float is enabled. 2016-04-26 12:47:24 +01:00
Colin Hogben 104aa26271 cc3200, stmhal, teensy: Use pyhelp_print_obj function.
Update the help() implementations in the cc3200, stmhal and teensy
ports to use the pyhelp_print_obj function.
2016-04-25 18:54:59 +03:00
Damien George 624738ca64 extmod/machine_i2c: Allow mp_hal_pin_obj_t to be any type, not a ptr. 2016-04-22 09:56:02 +01:00
Tobias Badertscher 495da15611 stmhal: L4: Add support for external interrupts/events.
The L4 MCU supports 40 Events/IRQs lines of the type configurable and
direct.  But this L4 port only supports configurable line types which are
already supported by uPy.  For details see page 330 of RM0351, Rev 1.

The USB_FS_WAKUP event is a direct type and there is no support for it.
2016-04-21 13:11:37 +01:00
Tobias Badertscher 067fb2da14 stmhal: L4: Modify flash.c and storage.c to support L4 MCU.
The way to lookup the flash sector now uses a much simpler table for
all MCUs.
2016-04-21 13:03:38 +01:00
Tobias Badertscher dda1a41205 stmhal: L4: Modify mphalport to support L4 MCU.
__GPIOI_CLK_ENABLE is defined in hal/l4/inc/Legacy/stm32_hal_legacy.h
as __HAL_RCC_GPIOI_CLK_ENABLE, and that latter macro is not defined
anywhere else (because the L4 does not have port GPIOI).  So the test
for GPIOI is needed, along with the test for the CLK_ENABLE macro.
2016-04-21 12:23:28 +01:00
Paul Sokolovsky 098f3e2862 stmhal: Update Makefile dependencies. 2016-04-19 11:54:07 +03:00
Damien George 5e247a5192 stmhal: Fix machine.unique_id() function to work for all MCUs. 2016-04-17 12:18:50 +01:00
Tobias Badertscher 31f5dc065a stmhal: L4: Modify timer.c to support L4 MCU. 2016-04-17 12:16:13 +01:00
Tobias Badertscher 432465b167 stmhal: L4: Modify rtc.c to support L4 MCU. 2016-04-17 12:08:07 +01:00
Damien George aed1da913b stmhal: L4: Modify usbd_conf.c to support L4 MCU.
Original patch was authored by Tobias Badertscher / @tobbad, but it was
reworked to split UART edits from USB edits.
2016-04-17 12:02:26 +01:00
Damien George 53521152a8 stmhal: L4: Modify uart.c to support L4 MCU.
L4 does not have UART6, and has similar registers to the F7.

Original patch was authored by Tobias Badertscher / @tobbad, but it was
reworked to split UART edits from USB edits.
2016-04-17 12:01:05 +01:00
Tobias Badertscher d49a547064 stmhal: L4: Modify adc.c to add support for STM32L4 series. 2016-04-16 23:02:36 +01:00
Tobias Badertscher 69f26c68c9 stmhal: L4: Add line to Makefile for building L4 series. 2016-04-16 22:14:12 +01:00
Tobias Badertscher 0b6e28c999 stmhal: L4: Add board definition files for STM32L476DISC. 2016-04-16 22:11:02 +01:00
Damien George e943a407f2 stmhal: Update HALCOMMITS due to change to hal. 2016-04-16 22:00:49 +01:00
Tobias Badertscher d4c3349957 stmhal: L4: Adapt UART HAL to avoid 64-bit integer division.
64-bit integer division brings a dependency on library functions. It is
avoided here by dividing fck and baud by a common divisior.  The error
is the better (1/(2*0x300)) as with 64 bit division (1/(0x300)).
2016-04-16 21:54:19 +01:00
Tobias Badertscher f4942db044 stmhal: L4: Add basic STM32L4xx HAL files.
These files come from STM32Cube_FW_L4_V1.3.0, with Windows line endings
converted to unix.  Only basic HAL files are added.  In addition the QSPI
support is included to support later external QSPI flash as mass storage.
2016-04-16 21:51:40 +01:00
Tobias Badertscher 2ba6677775 stmhal: L4: Add CMSIS files to support STM32L476. 2016-04-16 21:41:52 +01:00
Damien George 040373e4c4 stmhal: For frozen bytecode generation, add dependency of qstr file. 2016-04-16 13:20:02 +01:00
Jan Čapek d76c65f599 py: Add rules for automated extraction of qstrs from sources.
- add template rule that converts a specified source file into a qstring file

- add special rule for generating a central header that contains all
  extracted/autogenerated strings - defined by QSTR_DEFS_COLLECTED
  variable. Each platform appends a list of sources that may contain
  qstrings into a new build variable: SRC_QSTR. Any autogenerated
  prerequisities are should be appened to SRC_QSTR_AUTO_DEPS variable.

- remove most qstrings from py/qstrdefs, keep only qstrings that
  contain special characters - these cannot be easily detected in the
  sources without additional annotations

- remove most manual qstrdefs, use qstrdef autogen for: py, cc3200,
  stmhal, teensy, unix, windows, pic16bit:

   - remove all micropython generic qstrdefs except for the special strings that contain special characters (e.g. /,+,<,> etc.)
   - remove all port specific qstrdefs except for special strings
   - append sources for qstr generation in platform makefiles (SRC_QSTR)
2016-04-16 13:18:09 +01:00
Paul Sokolovsky 9b0714b24c py: Declare help, input, open builtins in core.
These are *defined* per-port, but why redeclare them again and again.
2016-04-15 00:07:56 +03:00
Damien George 733db525e2 stmhal: Add Makefile option FROZEN_MPY_DIR to support frozen bytecode. 2016-04-13 16:07:47 +01:00
Damien George 0a2e9650f5 py: Add ability to have frozen persistent bytecode from .mpy files.
The config variable MICROPY_MODULE_FROZEN is now made of two separate
parts: MICROPY_MODULE_FROZEN_STR and MICROPY_MODULE_FROZEN_MPY.  This
allows to have none, either or both of frozen strings and frozen mpy
files (aka frozen bytecode).
2016-04-13 16:07:47 +01:00
Peter Hinch 22cbcd55f0 stmhal: Properly handle RTS/CTS flow control for buf/unbuf transfers.
Fixes issues #1912 and #1913.  UART documentation is also updated.
2016-04-13 08:42:32 +01:00
Damien George 67a327cb9b stmhal: Enable framebuf module. 2016-04-12 14:06:54 +01:00
Damien George e4f963a351 stmhal: Use new generic I2C object in machine module. 2016-04-12 14:06:54 +01:00
Damien George 69a1aaf654 stmhal: Implement basic C-level pin HAL. 2016-04-12 14:06:54 +01:00
Damien George 53ad681ed1 extmod: Add initial framebuf module. 2016-04-12 14:06:53 +01:00
Martin Fischer 8a8e775035 stmhal: Consistently enable USB SOF Irqs for all USB modes (FS and HS).
SOF irqs are now standard for rx/tx USB transfers, so enable them for both
FS and HS modes.  Fixes #1944.
2016-04-07 09:23:33 +01:00
Dave Hylands 99fc0d120a stmhal: NUCELO_F401RE cleanup
Added definitions for SPI1, SPI2, and SPI3
Removed USB stuff (that could be removed)
Updated BOARD name defintion
2016-03-13 12:36:39 +00:00
Dave Hylands 00f921ce02 stmhal: Rename STM32F401NUCLEO to NUCLEO_F401RE
This makes the board match the name printed on the board (and
agree with the documentation)
2016-03-13 12:36:39 +00:00
Dave Hylands 031fadd10e stmhal: Add board definition files for NUCLEO_F411RE 2016-03-12 16:16:15 -08:00
Christopher Arndt 9b5e05a7c7 stmhal: Add makefile target and configuration to deploy via OpenOCD. 2016-03-09 23:00:17 +00:00
Ryan Shaw ad725a6661 stmhal: Add support for generic STM32F439 board (non DISCO). 2016-03-09 22:46:41 +00:00
Christopher Arndt 07554486ee stmhal: Add makefile target to deploy stmhal build via ST-LINK. 2016-03-09 13:26:23 +00:00
Damien George bb293e6bcf stmhal: Add stmhal-specific README.md with extra details for this port. 2016-03-08 12:00:38 +00:00
Damien George 2c72ae5c29 stmhal: Switch from dfu-util to tools/pydfu.py for deflt deploy method.
tools/pydfu.py is now the recommended way of deploying a DFU file.  Old
behaviour of dfu-util can be obtained by passing USE_PYDFU=0 when invoking
make.

The main README.md file has been updated to reflect this change.
2016-03-08 11:58:39 +00:00
Dave Hylands 484a471f9b stmhal: Fix some typos in stm32f411 files, regarding FS layout and CSV. 2016-03-07 12:42:30 +00:00
Dave Hylands 367c084c4b stmhal: Fix typo in stm32f401.ld file, regarding flash size. 2016-03-07 12:38:57 +00:00
Dave Hylands 0edfb7a115 stmhal: Make spi use mp_hal_gpio_set_af 2016-03-07 12:24:53 +00:00
Pavol Rusnak ce3beb1672 stmhal: Unify comments in stm32f4xx_hal_conf.h across all boards.
To make it easier to spot differences.
2016-03-07 11:28:36 +00:00
Paul Sokolovsky 453a2a3d7c extmod/vfs_fat: Add lexer, move from stmhal port for reuse. 2016-03-03 13:25:44 +02:00
Paul Sokolovsky 6ef65e70af extmod/vfs_fat: Add fat_vfs_import_stat(), reusable import stat routine.
Moved from stmhal.
2016-02-29 00:44:32 +02:00
Paul Sokolovsky cd6d189f48 extmod/vfs_fat: Move listdir() method from stmhal for reuse. 2016-02-28 17:17:24 +02:00
Damien George 476c15290d stmhal: Enabled importing of persistent bytecode (.mpy files). 2016-02-25 10:12:30 +00:00
Dave Hylands ec37239e53 stmhal: Improvements to the STM32F4DISC UART config settings. 2016-02-15 10:11:29 +00:00
Dave Hylands 4b2938a4b0 stmhal: Some NETDUINO_PLUS_2 cleanup
- Put the I2C bus on the corect pins
- Add the appropriate board_init to power the shield
2016-02-15 10:07:27 +00:00
Paul Sokolovsky 46a0ac02c5 extmod/vfs_fat_ffconf: Reusable FatFs module, move from stmhal/ffconf.
TODO: Probably merge into vfs_fat_diskio.
2016-02-15 00:19:27 +02:00
Paul Sokolovsky 6b0c88256b extmod/vfs_fat_file: Reusable FatFs module, move from stmhal/file. 2016-02-15 00:16:46 +02:00
Paul Sokolovsky 8cb78e0e53 extmod/vfs_fat_diskio: Reusable FatFs module, move from stmhal/diskio. 2016-02-15 00:08:37 +02:00
Paul Sokolovsky 72085a669b py/mpstate.h: fs_user_mount is now standard, reusable uPy functionality. 2016-02-15 00:02:03 +02:00
Paul Sokolovsky 9e0478a902 stmhal/diskio: Add provision for default returns for ioctl INIT/SEC_SIZE.
If None was returned for such requests (which likely means that user simply
didn't handle them), it means successful init and default sector size of 512
bytes respectively. This makes only BP_IOCTL_SEC_COUNT a mandatory request,
and thus re-establishes parity with old interface, where only .count() is
mandatory().
2016-02-14 20:34:30 +02:00
Paul Sokolovsky e3c66a5a67 stmhal/file: Paranoid compiler warnings cleanness. 2016-02-14 19:15:22 +02:00
Paul Sokolovsky baf47c84c4 stmhal/diskio,file: Nanbox cleanness. 2016-02-14 19:15:22 +02:00
Dave Hylands 32b7e93535 stmhal: NUCLEO 401 - Add definitions for I2C2 and I2C3 2016-02-10 21:26:14 -08:00
Dave Hylands f791e14750 stmhal: CERB40 - Add pins defines for I2C3 2016-02-10 21:25:30 -08:00
Dave Hylands 38ac23c942 stmhal: NUCLEO 401 - Add a bunch of missing pins and reorder the pins
This groups the pins for a port together and puts them in numerical
order. It also adds ARDUINO pin names.
2016-02-10 21:23:45 -08:00
Dave Hylands 7bb501ef9f stmhal: Add a function for setting the pin alternate function
mp_hal_gpio_set_af will search for a given function and unit
and set the alternate function to the alternate function index
found.
2016-02-10 21:20:14 -08:00
Damien George e372e83b30 extmod/fsusermount: Move BP_IOCTL_xxx constants to fsusermount.h. 2016-02-10 23:40:35 +00:00
Damien George b33a770596 extmod/fsusermount: Support mounting of multiple block devices.
This patch adds support to fsusermount for multiple block devices
(instead of just one).  The maximum allowed is fixed at compile time by
the size of the fs_user_mount array accessed via MP_STATE_PORT, which
in turn is set by MICROPY_FATFS_VOLUMES.

With this patch, stmhal (which is still tightly coupled to fsusermount)
is also modified to support mounting multiple devices   And the flash and
SD card are now just two block devices that are mounted at start up if
they exist (and they have special native code to make them more
efficient).
2016-02-10 23:40:10 +00:00
Damien George 34023eb673 stmhal: Add mount/umount/mkfs to os module. 2016-02-10 23:40:10 +00:00
Damien George 3770cd2e70 stmhal: Expose flash and SD card as proper objects with block protocol.
You can now create (singleton) objects representing the flash and SD
card, using:

    flash = pyb.Flash()
    sdcard = pyb.SDCard()

These objects provide the block protocol.
2016-02-10 23:40:10 +00:00
Dave Hylands a888d5ab91 stmhal: Improve NUCLEO-F401RE build, with UART2 as REPL.
This enables MICROPY_HW_HAS_FLASH which got missed.

The HW has UART2 on the 401 connected to the STLINK procesor
which exposes it as USB serial. This connects that up so that
you can get a REPL using the USB serial.
2016-02-10 16:50:05 +00:00
Damien George 13a4c120ce lib/fatfs: Add support for sector sizes larger than 512 bytes.
If MICROPY_FATFS_MAX_SS is defined to power of 2 value between 1024 and
4096, support for dynamic sector size in FatFs will be enabled.  Note
that FatFs reserves static buffer of MICROPY_FATFS_MAX_SS size for each
filesystem in use, so that value should be set sparingly.

Initial patch provided by @pfalcon.
2016-02-10 08:59:58 +00:00
Damien George c33ad60a67 extmod/fsusermount: Change block protocol to support ioctl method.
The new block protocol is:
- readblocks(self, n, buf)
- writeblocks(self, n, buf)
- ioctl(self, cmd, arg)

The new ioctl method handles the old sync and count methods, as well as
a new "get sector size" method.

The old protocol is still supported, and used if the device doesn't have
the ioctl method.
2016-02-10 08:59:31 +00:00
Paul Sokolovsky 5b85a86ce3 extmod/fsusermount: Introduce separate mkfs() function.
Per the previously discussed plan. mount() still stays backward-compatible,
and new mkfs() is rought and takes more args than needed. But is a step
in a forward direction.
2016-02-10 00:50:07 +02:00
Paul Sokolovsky ab0e36b3da stmhal/file: For self-contained usecase, don't define global types.
If MICROPY_VFS_FAT is defined, mp_type_fileio & mp_type_textio won't be
defined, as these may be alredy defined elsewhere. The idea is to have
compartmentalized VFS FatFs class, which can work in parallel with some
other "main" filesystem. E.g., for unix port, mp_type_fileio, etc. will
be defined for the main POSIX filesystem, while stmhal/file.c will be
a self-contained VFS file class.
2016-02-07 01:25:28 +02:00
Paul Sokolovsky 350ab0f570 stmhal/file: Recast as "FatFs file" class, to support other VFS types.
Move definition of mp_builtin_open_obj to a separate module, then file.c
becomes more or less compartmentalized FatFs file class, which can be used
together with file class implementations for other (V)FSes.
2016-02-07 01:25:28 +02:00
Paul Sokolovsky 71206f02c3 stmhal: Move stmhal-specific FatFs routines/structs to fatfs_port.c. 2016-02-06 15:31:00 +02:00
Paul Sokolovsky 97a0846af9 stmhal/diskio: Introduce MICROPY_HW_HAS_FLASH setting.
To allow to reuse stmhal/diskio for ports which don't have flash but have
other storage devices.
2016-02-06 15:07:01 +02:00
Doug Currie 2e2e15cec2 py/mpz: Complete implementation of mpz_{and,or,xor} for negative args.
For these 3 bitwise operations there are now fast functions for
positive-only arguments, and general functions for arbitrary sign
arguments (the fast functions are the existing implementation).

By default the fast functions are not used (to save space) and instead
the general functions are used for all operations.

Enable MICROPY_OPT_MPZ_BITWISE to use the fast functions for positive
arguments.
2016-02-03 22:13:39 +00:00
Damien George db573082b5 stmhal: Update HALCOMMITS due to change to hal. 2016-01-30 00:05:46 +00:00
Damien George ea040a4f9a stmhal: In HAL I2C driver, move DMA setup to after sending I2C address.
Previous to this patch the DMA was setup and then the I2C address sent.
If the I2C address sending failed (eg no I2C device on the bus) then the
DMA was left in an inconsistent state.

This patch moves the DMA setup to after a successful sending of the I2C
address(es).

See issue #1765.
2016-01-30 00:02:21 +00: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
Paul Sokolovsky d3b1f0b627 py/runtime: mp_stack_ctrl_init() should be called immediately on startup.
Calling it from mp_init() is too late for some ports (like Unix), and leads
to incomplete stack frame being captured, with following GC issues. So, now
each port should call mp_stack_ctrl_init() on its own, ASAP after startup,
and taking special precautions so it really was called before stack variables
get allocated (because if such variable with a pointer is missed, it may lead
to over-collecting (typical symptom is segfaulting)).
2016-01-29 02:13:42 +02:00
Carmine Noviello 3d42aa07dd stmhal: Add support for the STM32F401NUCLEO board.
Includes full version of pins.csv file with correct mapping of the Nucleo
STM32F401RE chip (LQFP64 package).
2016-01-27 12:30:36 +00:00
Damien George a53af6c875 extmod/modurandom: Add some extra random functions.
Functions added are:
- randint
- randrange
- choice
- random
- uniform

They are enabled with configuration variable
MICROPY_PY_URANDOM_EXTRA_FUNCS, which is disabled by default.  It is
enabled for unix coverage build and stmhal.
2016-01-26 15:27:00 +00:00
Dave Hylands 42a6364a31 stmhal: Add support for building frozen files.
This allows FROZEN_DIR=some-directory to be specified on the make
command line, which will then add all of the files contained within
the indicated frozen directory as frozen files in the image.

There is no change in flash/ram usage if not using the feature.

This is especially useful on smaller MCUs (like the 401) which only
has 64K flash file system.
2016-01-23 21:53:04 +00:00
Dave Hylands f22844b4e5 stmhal: Add os.statvfs
Implement enough of statvfs to determine the amount of free
space on a volume.
2016-01-19 12:29:47 +00:00
Paul Sokolovsky a58a91eb04 extmod/modurandom: Add "urandom" module.
Seedable and reproducible pseudo-random number generator. Implemented
functions are getrandbits(n) (n <= 32) and seed().

The algorithm used is Yasmarang by Ilya Levin:
http://www.literatecode.com/yasmarang
2016-01-17 12:13:01 +02: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 daa1a455c6 stmhal: Remove custom mod_machine_mem_get_{read,write}_addr functions.
They are no longer needed because stm constants can now be 32 bits wide.
2016-01-07 16:34:11 +00:00
Damien George 2621f8a340 stmhal: Make stm constants big ints when they don't fit in a small int.
Adds 924 bytes of code, but means that no more hacks and work-arounds are
needed due to large constants becoming negative.
2016-01-07 16:34:11 +00:00
Dave Hylands 8c936edeb2 stmhal: Fix USB on the STM32F429DISC board
The USB REPL has been broken since commit 1be0fde45c
This patch allows the STM32F429DISC board (which uses the USB_HS PHY)
2015-12-30 23:36:41 -08:00
Paul Sokolovsky b4c65c253f extmod/fsusermount: Move module qstrs to global pool from stmhal port. 2015-12-25 19:22:16 +02:00
Damien George 401af50dc0 stmhal: Add pyb.irq_stats() to get statistics about IRQ calls.
Adds a lot of code, makes IRQs a bit less efficient, but is very useful
for debugging.  Usage: pyb.irq_stats() returns a memory view that can be
read and written, eg:

    list(pyb.irq_stats())
    pyb.irq_stats()[0]
    pyb.irq_stats()[0] = 0

The patch provides general IRQ_ENTER() and IRQ_EXIT() macros that can be
modified to provide further IRQ statistics if desired.
2015-12-22 21:00:20 +00:00
Dave Hylands b61336483b stmhal: Add mem8/mem16/mem32 operations to machine module.
This uses the newly factored machine_mem functions.
2015-12-19 01:05:44 +00:00
Fabian d0f31ccf33 stmhal: Change PLL configuration for STM32F7DISC.
Changes USB clock from 50MHz to 48MHz which improves USB communication.
2015-12-18 22:16:49 +00:00
Paul Sokolovsky 0e1b5faad5 stmhal, cc3200: Actually implement machine -> umachine module weak link. 2015-12-18 22:22:43 +02:00
Paul Sokolovsky 2eb844e0b4 ports: Rename "machine" module to "umachine".
To let unix port implement "machine" functionality on Python level, and
keep consistent naming in other ports (baremetal ports will use magic
module "symlinking" to still load it on "import machine").

Fixes #1701.
2015-12-18 02:39:52 +02:00
Paul Sokolovsky be3ae9d13c stmhal/moduselect: Implement "oneshot polling" flag.
Similar to recently added feature in unix port: if event triggers for an
objects, its polling flags are automatically reset, so it won't be polled
until they are set again explicitly.
2015-12-16 11:07:58 +00:00
Tobias Badertscher c5d8ffef58 stmhal: Extend SPI support to fully support all SPI devices on STM32F429.
This includes SPI4, SPI5 and SPI6.
2015-12-16 00:38:36 +00:00
Damien George 36ccdc952c stmhal: Make uart init use struct instead of array for parsing args.
This makes it much easier to understand which arg is which, less error
prone, and simpler to add a new arg.
2015-12-12 15:55:51 +00:00
Damien George f7c4f9a640 stmhal: For SPI config, use HW_SPIx_SCK instead of HW_ENABLE_SPIx.
Previously, SPI was configured by a board defining MICROPY_HW_ENABLE_SPIx
to 0 or 1.  Now, the board should define MICROPY_HW_SPIx_SCK, MISO, MOSI
and NSS.  This makes it the same as how I2C is configured.
2015-12-12 15:02:02 +00:00
Sven Wegener 4651c4381e stmhal: add order-only dependency on build directory
Signed-off-by: Sven Wegener <sven.wegener@stealer.net>
2015-12-10 22:25:36 +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
neilh10 1be0fde45c stmhal: Enable two USB phys to be supported together.
This is refactoring to enable support for the two USB PHYs available on
some STM32F4 processors to be used at the same time. The F405/7 & F429
have two USB PHYs, others such as the F411 only have one PHY.

This has been tested separately on a pyb10 (USB_FS PHY) and F429DISC
(USB_HS PHY) to be able to invoke a REPL/USB.  I have modified a PYBV10
to support two PHYs.

The long term objective is to support a 2nd USB PHY to be brought up as a
USB HOST, and possibly a single USB PHY to be OTG.
2015-12-09 09:56:36 +00:00
Dave Hylands f380904bd9 stmhal: Print exception information in nlr_jump_failed
Currently nlr_jump_fail prints that there was an uncaught exception
but nothing about the exception.
This patch causes nlr_jump_failed to try to print the exception.
Given that printf was called on the line above, I think that
the call to mp_obj_print_exception has about as much likelyhood
of succeeding as the printf does.
2015-12-07 17:21:51 +00:00
Dave Hylands acc208418b stmhal: Execute boot.py and main.py when formatting the file system.
When you use the USER button to perform a filesystem reset
at boot time then it wipes out the filesystem and creates
a new boot.py and main.py.  With this patch these files are
executed after formatting, ensuring that pyb and machine modules
get imported.
2015-12-07 15:11:42 +00:00
Ryan Shaw c03dd3b2f9 stmhal: Fix uart off by 1 circular buffer size. 2015-12-04 22:20:47 +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 dd7d2e0810 stmhal: Only use BASEPRI irq stuff if Cortex is M3 or higher. 2015-12-04 12:13:12 +00:00
Damien George f7697ff393 stmhal: Add rtc.init() method to force RTC to re-initialise. 2015-12-04 12:05:05 +00:00
Damien George f4c17378b3 stmhal: Protect SD card DMA transactions against USB MSC contention.
Consider the following scenario: SD card is being read by pyboard; USB
irq comes in for MSC read request; SD card needs to be read from within
USB irq while SD read is already ongoing.  Such contention needs to be
avoided.

This patch provides a simple solution, to raise the irq priority above
that of the USB irq during SD DMA transfers.  Pyboard and PC can now
read from the SD card at the same time (well, reads are interleaved).
2015-12-04 11:39:21 +00:00
Damien George 95c9cc8114 stmhal: Add raise_irq_pri and restore_irq_pri functions.
These can be used to disable only certain interrupts, ones at or above
the given priority value.
2015-12-04 11:38:23 +00:00
Dave Hylands 0077958ad0 stmhal: Put all DMA channel & stream definitions in dma.h 2015-12-02 22:55:57 +00:00
Damien George e9a684d741 stmhal: Add board config files for PYBv1.1 and PYBLITEv1.0. 2015-12-02 12:47:09 +00:00
Damien George 0d9b450701 stmhal: Make uart.write() function correctly for timeout=0.
In non-blocking mode (timeout=0), uart.write() can now transmit all of its
data without raising an exception.  uart.read() also works correctly in
this mode.

As part of this patch, timout_char now has a minimum value which is long
enough to transfer 1 character.

Addresses issue #1533.
2015-11-30 17:29:52 +00:00
Ryan Shaw f99491cbf7 stmhal: uart.any() function now returns number of bytes available. 2015-11-30 13:07:20 +00:00
Dave Hylands 3048433809 stmhal: Make stm.mem* support large integers.
With these you can now do things like:

stm.mem32[0x20000000] = 0x80000000

and read 32-bit values. You can also read all the way to the end
of memory using either stm.mem32[0xfffffffc] or stm.mem32[-4].

IRQs shouldn't use mem32 at all since they'd fail if the top 2 bits
weren't equal, so IRQs should be using 16-bit I/O.
2015-11-26 22:19:42 +00:00
Dave Hylands 061eb6fa6b stmahl: Fix usbd_conf.c for devices which don't have USB_HS at all.
The STMCube examples define both USE_USB_HS and USE_USB_HS_IN_FS when they
use the HS in FS mode.

The STM32F401 doesn't have a USB_HS at all, so the USB_OTG_HS instance
doesn't even exist.
2015-11-26 16:17:26 +00:00
Dave Hylands 364bb61df3 stmhal: Allow make DEBUG=1 to build 2015-11-26 00:04:34 +00:00
Tobias Badertscher 8844d031e4 stmhal: Add support for the STM32F429I-DISCO kit by STMicro. 2015-11-25 23:53:26 +00:00
Paul Sokolovsky f0fbab7ca7 extmod/fsusermount: Make configurable with MICROPY_FSUSERMOUNT. 2015-11-25 13:19:36 +02:00
Paul Sokolovsky 3a1bbcc2ef extmod: Move fsusermount.c from stmhal for cross-port reuse. 2015-11-25 13:19:36 +02:00
Dave Hylands c8437f97ae stmhal: Increase the priority of UART IRQ.
The UARTs have no FIFOs, so if interrupts are disabled
for more than a character time (10 usec at 1 Mbit/sec)
then characters get dropped.

The overhead for handling a UART ISR is about 0.5 usec,
so even at baud rates of 1 Mbit/sec this only corresponds
to about 5% of the CPU. Lower baud rates will have less
of an impact.
2015-11-25 08:03:44 +00:00
Damien George 65888e2006 stmhal: Process storage idle tick handler in different slot to DMA. 2015-11-24 16:57:13 +00:00
Damien George 36bd10779c stmhal: In SysTick IRQ handler, make uwTick variable non-volatile.
uwTick can only change in the SysTick IRQ so this IRQ function does not
need to take special care with this variable.  It's important to make
this IRQ function as efficient as possible.
2015-11-24 16:23:54 +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
Damien George 3cfb02f166 stmhal/irq: Set all IRQ subpriorities to 0, since they aren't used. 2015-11-24 15:56:33 +00:00
Damien George 18820471ae stmhal/irq: Add comment about SDIO priority being higher than DMA. 2015-11-24 15:51:07 +00:00
Damien George 22bd23114a stmhal: On SysTick IRQ, only process one DMA channel at a time.
This can be generalised if/when more processing is needed by SysTick.

Thanks to @chuckbook for the idea.
2015-11-24 15:44:16 +00:00
Damien George 9936aa3f87 stmhal: Save RAM and ROM by making SD DMA init structure const for tx/rx. 2015-11-24 15:44:16 +00:00
Damien George 522d454e34 stmhal: Small simplification of code to tickle DMA idle counter. 2015-11-24 15:44:16 +00:00
Dave Hylands 6edffd0df5 stmhal: Add dma support for sdcard.
This started out using IgorLektorovEpam work in PR #1389
and reworked it.
2015-11-24 09:37:25 +00:00
Dave Hylands b677f03407 stmhal: Turn off DMA clocks when idle for 100 msec
Turning on each DMA block increases the current consumption
by about 8 mA. This code adds an idle timer for each DMA
block and turns off the clocks when no streams are in use
for 128 msec. Having a small timeout allows for improved
performance when back-to-back transfers are being performed.

The 128 msec is basically a guess.
2015-11-24 09:37:25 +00:00
Dave Hylands 9f5486c7e2 stmhal: Put IRQs into priority order.
- added some comments to explain the priority/sub-priority.
- adds an entry for SDIO (to be used in a later patch)
- increases DMA priority above USB so that DMA can be used
  for sdcard I/O when using USB Mass Storage.
2015-11-24 09:37:25 +00:00
Damien George 056abbcf31 stmhal: Fix unused variables when HW_CLK_LAST_FREQ not defined. 2015-11-23 23:52:09 +00:00
T S 86aa16bea6 stmhal: Implement delayed RTC initialization with LSI fallback.
If RTC is already running at boot then it's left alone.  Otherwise, RTC is
started at boot but startup function returns straight away.  RTC startup
is then finished the first time it is used.  Fallback to LSI if LSE fails
to start in a certain time.

Also included:
 MICROPY_HW_CLK_LAST_FREQ
        hold pyb.freq() parameters in RTC backup reg
 MICROPY_HW_RTC_USE_US
        option to present datetime sub-seconds in microseconds
 MICROPY_HW_RTC_USE_CALOUT
        option to enable RTC calibration output

CLK_LAST_FREQ and RTC_USE_CALOUT are enabled for PYBv1.0.
2015-11-23 23:23:07 +00:00
Paul Sokolovsky 16d42368a6 stmhal/modmachine: Initial attempt to add I2C & SPI classes.
In new hardware API, these classes implement master modes of interfaces,
and "mode" parameter is not accepted. Trying to implement new HW API
in terms of older pyb module leaves variuos corner cases:

In new HW API, I2C(1) means "I2C #1 in master mode" (? depends on
interpretation), while in old API, it means "I2C #1, with no settings
changes".

For I2C class, it's easy to make mode optional, because that's last
positional param, but for SPI, there's "baudrate" after it (which
is inconsistent with I2C, which requires "baudrate" to be kwonly-arg).
2015-11-14 16:14:08 +02:00
Paul Sokolovsky 73ff0687f2 lib/utils/printf: Move from stmhal/ .
This file contains various MicroPython-specific helper functions, so isn't
good fit for lib/libc/.
2015-11-10 18:58:58 +02:00
Paul Sokolovsky 746b752b8e stmhal/moduselect: Expose POLLIN/OUT/ERR/HUP constants.
This makes select.poll() interface fully compatible with CpYthon. Also, make
their numeric values of these options compatible with Linux (and by extension,
with iBCS2 standard, which jopefully means compatibility with other Unices too).
2015-11-09 22:10:31 +02:00
Damien George 40274fec9c lib/pyexec: Move header pyexec.h from stmhal directory. 2015-11-09 13:13:09 +00:00
Alex March 748509a93c stmhal: FatFS configuration moved to the library folder.
Port specific settings defined in mpconfigport.
2015-11-08 22:21:17 +00:00
Dave Hylands 57e00ef262 stmhal: Fix RTC code to work on the F7 2015-11-07 09:42:26 -08:00
Dave Hylands 41b688e25f stmhal: Print more information at HardFault time. 2015-11-07 13:59:00 +00:00
Tony Abboud ae58035573 stmhal: Add missing regex property for parsing header comments 2015-11-06 23:32:55 +00:00
T S 8f7ff854b0 stmhal/rtc: LSx oscillator is only initialized upon initial power up.
Initial power up also includes VBAT.

If LSE is configured but fails to start, LSI is used until next full power
cycle.  Also handles STM32F7xx variant.
2015-11-06 22:00:34 +00:00
Henrik Sölver 35e7d9c0f1 stmhal/can: Fix a bug in filter handling.
Reported here: http://forum.micropython.org/viewtopic.php?f=2&t=845
2015-11-02 23:09:49 +00:00
Dave Curtis 32b3549cce stmhal: Add symbolic #defines for interrupt levels in irq.h. 2015-11-01 23:23:39 +00:00
Paul Sokolovsky 0ec51441de stmhal: pyexec.c is common module, move to lib/utils/ . 2015-10-31 19:35:10 +03: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
Damien George f705cb5f7a stmhal: Update PYBv3 and PYBv4 pin defs to include MMA pins, and others. 2015-10-31 11:14:15 +00:00
Dave Hylands 165734522e stmhal: f7: Fix recent RTC change to build on F7. 2015-10-30 23:40:00 +00:00
Peter Hinch 3819634469 stmhal: Make RTC init skip startup if LTE is already enabled and ready.
This prevents the loss of RTC time when exiting from standby mode, since
the RTC is paused while it is being re-inited and this loses about 120ms.

Thanks to @chuckbook for the patch.
2015-10-30 13:13:42 +00:00
Dave Hylands b83d0b35e9 stmhal: Add define for UNIQUE_ID address (differs per MCU) 2015-10-30 12:53:14 +00:00
Dave Hylands 823a961ecc stmhal: Enable sdcard on STM32F7DISC board. 2015-10-30 12:05:14 +00:00
Damien George 6f70283909 stmhal: Make accel AVDD pin configurable via mpconfigboard.h. 2015-10-29 22:40:42 +00:00
Paul Sokolovsky 19b671c5cd stmhal/moduselect: Use mp_hal_ticks_ms(). 2015-10-29 20:42:12 +03:00
Paul Sokolovsky 04fa999cfe stmhal/pyexec: Use mp_hal_ticks_ms().
This file is actually port-generic and should be moved out of stmhal/ .
Other ports already use it, and thus it should use mp_hal_ticks_ms()
right away.
2015-10-29 19:35:27 +03:00
Paul Sokolovsky 404dae80a9 unix, stmhal: Introduce mp_hal_delay_ms(), mp_hal_ticks_ms().
These MPHAL functions are intended to replace previously used HAL_Delay(),
HAL_GetTick() to provide better naming and MPHAL separation (they are
fully equivalent otherwise).

Also, refactor extmod/modlwip to use them.
2015-10-27 23:31:42 +03:00
Damien George 79f404a287 stmhal: Fix USB_VCP.recv so that it returns actual amount of bytes read.
Addresses issue #1529.
2015-10-25 21:43:07 +00:00
Paul Sokolovsky 4a9c60cdfb stmhal: Typo fix in comment. 2015-10-24 21:58:58 +03:00
Paul Sokolovsky 81a1e17238 stmhal/ffconf.h: Include py/mpconfig.h.
mpconfigport.h is a private, partial header not providing correct settings
unless included by py/mpconfig.h.
2015-10-24 18:33:43 +03:00
Paul Sokolovsky 0dbd928cee Makefiles: Remove duplicate object files when linking.
Scenario: module1 depends on some common file from lib/, so specifies it
in its SRC_MOD, and the same situation with module2, then common file
from lib/ eventually ends up listed twice in $(OBJ), which leads to link
errors.

Make is equipped to deal with such situation easily, quoting the manual:
"The value of $^ omits duplicate prerequisites, while $+ retains them and
preserves their order." So, just use $^ consistently in all link targets.
2015-10-24 15:46:53 +03:00
Damien George 9d0192de4a stmhal: Enable "all special methods" configuration option. 2015-10-20 23:55:27 +01:00
Damien George 60401d461a stmhal/rtc: Fix indentation to use spaces rather than tabs. 2015-10-20 12:05:27 +01:00
Peter Hinch b106532b32 stmhal/rtc: Init uses YMD rather than backup register to detect powerup. 2015-10-20 12:05:16 +01:00
Damien George 2f96b1982a stmhal: Bring Pin class close to new machine module specification.
Looks like we can use the same Pin class for legacy pyb module and new
machine module.
2015-10-19 22:50:59 +01:00
Paul Sokolovsky bedab235f9 stmhal/uart: If char is not received within timeout, return EAGAIN error.
Instead of return 0, which means EOF. There's no good way to detect EOF on
continuously active bus like UART, and treat timeout as just temporary
unvailability of data. .read() method of UART object will return None in
this case (instead of 0, which again measn EOF). This is fully compliant
with unix port.
2015-10-20 00:27:07 +03:00
Damien George 83158e0e7f stmhal: Implement os.dupterm (was pyb.repl_uart).
pyb.repl_uart still exists but points to os.dupterm.
2015-10-19 21:57:41 +01:00
Damien George d8066e999d stmhal: Add sleep_{ms,us} and ticks_{ms,us,cpu,diff} to time module.
pyb module still has pyb.delay and pyb.udelay, but these now point to
time.sleep_ms and time.sleep_us respectively.
2015-10-19 21:45:51 +01:00
Dave Hylands 504420c51d stmhal: Early version of machine module for stmhal. 2015-10-19 21:12:42 +01:00
Paul Sokolovsky e0f5df579b all: Make netutils.h available to all ports by default.
Generally, ports should inherit INC from py.mk, append to it, not
overwrite it. TODO: Likely should do the same for other vars too.
2015-10-19 18:32:42 +03:00
Dave Hylands affcbe4139 stmhal: Make USB serial number actually be unique. 2015-10-17 22:02:57 +01:00
Damien George b5c43be135 stmhal: Allow to set bits resolution for DAC; 8 is default, can have 12.
This patch allows to configure the DAC resolution in the constructor and
in the init function, eg:

dac = DAC(1, bits=12).

The default resolution is 8 bits for backwards compatibility.  The bits
sets the maximum value accepted by write and write_timed methods, being
2**bits - 1.

When using write_timed with 12-bit resolution, the input buffer is
treated as an unsigned half-word array, typecode 'H'.

See PR #1130 for discussion.
2015-10-13 14:33:04 +01:00
Damien George 0334058fa4 Rename "Micro Python" to "MicroPython" in REPL, help, readme's and misc. 2015-10-12 00:06:25 +01:00
Damien George 6206f431cf stmhal: Enable REPL auto indent; document paste mode in help(). 2015-10-11 23:33:46 +01:00
Damien George 46a1102852 repl: Add paste mode to friendly REPL, entered via CTRL-E.
Use CTRL-E to enter paste mode.  Prompt starts with "===" and accepts
all characters verbatim, echoing them back.  Only control characters are
CTRL-C which cancels the input and returns to normal REPL, and CTRL-D
which ends the input and executes it.  The input is executed as though
it were a file.  The input is not added to the prompt history.
2015-10-11 23:30:22 +01:00
Paul Sokolovsky 1b586f3a73 py: Rename MP_BOOL() to mp_obj_new_bool() for consistency in naming. 2015-10-11 15:18:15 +03:00