Commit Graph

381 Commits

Author SHA1 Message Date
Damien George 98b05e3614 esp32: Add support for and enable uos.dupterm(). 2018-04-27 23:51:45 +10:00
Damien George 04dc4a5034 esp32/mphalport: Improve mp_hal_stdout_tx_XXX functions.
This makes way for enabling uos.dupterm().
2018-04-27 23:49:21 +10:00
Damien George c0dd9be606 stm32/boards/NUCLEO_H743ZI: Use priority 0 for SysTick IRQ.
This follows how all other boards are configured.
2018-04-27 15:16:45 +10:00
Damien George 527ba0426c stm32/system_stm32: Reconfigure SysTick IRQ priority for L4 MCUs.
After calling HAL_SYSTICK_Config the SysTick IRQ priority is set to 15, the
lowest priority.  This commit reconfigures the IRQ priority to the desired
TICK_INT_PRIORITY value.
2018-04-27 12:54:35 +10:00
Damien George 4ed5865280 esp32/mphalport: Improve mp_hal_delay_us so it handles pending events.
Thanks to @bboser for the initial idea and implementation.
2018-04-26 20:21:33 +10:00
Damien George e1fe3abd09 esp32/mphalport: Use esp_timer_get_time instead of gettimeofday.
It's more efficient and improves accuracy.
2018-04-26 20:19:31 +10:00
Damien George 9254f365d6 stm32/machine_i2c: Provide hardware I2C for machine.I2C on F7 MCUs. 2018-04-24 23:48:04 +10:00
Damien George 19778d0a3c stm32/i2c: Add low-level I2C driver for F7 MCUs. 2018-04-24 23:48:04 +10:00
Damien George 0c54d0c288 stm32: Rename legacy pyb.I2C helper functions to start with pyb_i2c_. 2018-04-24 17:32:16 +10:00
Damien George b73adcc3d9 stm32: Rename i2c.c to pyb_i2c.c.
i2c.c implements the legacy pyb.I2C class so rename the file to make this
explicit, and also to make room for an improved I2C driver.
2018-04-24 16:23:36 +10:00
Damien George 8b91260169 stm32/dac: Support MCUs that don't have TIM4/5 and use new HAL macro. 2018-04-24 12:07:59 +10:00
Damien George 8a949ba599 stm32: Introduce MICROPY_PY_STM config to include or not the stm module.
By default the stm module is included in the build, but a board can now
define MICROPY_PY_STM to 0 to not include this module.  This reduces the
firmware by about 7k.
2018-04-24 12:01:49 +10:00
Damien George a60efa8202 stm32/uart: Allow ctrl-C to work with UARTs put on REPL via os.dupterm. 2018-04-23 20:44:30 +10:00
Damien George 513e537215 stm32/uart: Allow ctrl-C to issue keyboard intr when REPL is over UART. 2018-04-23 17:06:40 +10:00
iabdalkader d870a4e835 stm32/boards/NUCLEO_H743ZI: Enable RNG for this board. 2018-04-23 16:43:16 +10:00
iabdalkader 70a6a15f8c stm32/rng: Set RNG clock source for STM32H7. 2018-04-23 16:43:05 +10:00
Shanee Vanstone b5ee3b2f21 esp32/README.md: Fix typo readme. 2018-04-20 16:23:55 +10:00
Peter D. Gray 9adfd14644 stm32/sdcard: Implement BP_IOCTL_SEC_COUNT to get size of SD card. 2018-04-20 16:09:03 +10:00
Damien George 3d5d76fb73 stm32/main: Allow a board to configure the label of the flash FS.
To change the default label a board should define:

    #define MICROPY_HW_FLASH_FS_LABEL "label"
2018-04-11 16:52:22 +10:00
Damien George cf9fc7346d stm32: Allow a board to configure the HSE in bypass mode.
To use HSE bypass mode the board should define:

    #define MICROPY_HW_CLK_USE_BYPASS (1)

If this is not defined, or is defined to 0, then HSE oscillator mode is
used.
2018-04-11 16:46:47 +10:00
Damien George 68b70fac5c stm32/stm32_it: Add IRQ handler for I2C4. 2018-04-11 16:37:45 +10:00
Damien George a7ebac2eae stm32/can: Allow CAN pins to be configured per board.
This patch allows a given board to configure which pins are used for the
CAN peripherals, in a similar way to all the other bus peripherals (I2C,
UART, SPI).  To enable CAN on a board the mpconfigboard.h file should
define (for example):

    #define MICROPY_HW_CAN1_TX (pin_B9)
    #define MICROPY_HW_CAN1_RX (pin_B8)
    #define MICROPY_HW_CAN2_TX (pin_B13)
    #define MICROPY_HW_CAN2_RX (pin_B12)

And the board config file should no longer define MICROPY_HW_ENABLE_CAN.
2018-04-11 16:35:24 +10:00
Damien George 0041396f05 stm32/pin: In pin AF object, remove union of periph ptr types.
The individual union members (like SPI, I2C) are never used, only the
generic "reg" entry is.  And the union names can clash with macro
definitions in the HAL so better to remove them.
2018-04-11 16:14:58 +10:00
Damien George f1073e747d stm32/adc: Factor common ADC init code into adcx_init_periph().
The only configuration that changes with this patch is that on L4 MCUs the
clock prescaler changed from ADC_CLOCK_ASYNC_DIV2 to ADC_CLOCK_ASYNC_DIV1
for the ADCAll object.  This should be ok.
2018-04-11 14:46:13 +10:00
Damien George 1d6c155d6a stm32/adc: Fix config of EOC selection and Ext-Trig for ADC periph.
A value of DISABLE for EOCSelection is invalid.  This would have been
interpreted instead as ADC_EOC_SEQ_CONV, but really it should be
ADC_EOC_SINGLE_CONV for the uses in this code.  So this has been fixed.

ExternalTrigConv should be ADC_SOFTWARE_START because all ADC
conversions are started by software.  This is now fixed.
2018-04-11 14:29:37 +10:00
Damien George 06807c1bde stm32/adc: Factor code to optimise adc_read_channel and adc_read.
Saves 200 bytes of code space.
2018-04-11 14:28:06 +10:00
Damien George b30e0d2f26 stm32/dac: Add buffering argument to constructor and init() method.
This can be used to select the output buffer behaviour of the DAC.  The
default values are chosen to retain backwards compatibility with existing
behaviour.

Thanks to @peterhinch for the initial idea to add this feature.
2018-04-11 14:22:21 +10:00
Damien George aebd9701a7 stm32/adc: Optimise read_timed_multi() by caching buffer pointers. 2018-04-11 14:09:09 +10:00
Peter Hinch 4f40fa5cf4 stm32/adc: Add read_timed_multi() static method, with docs and tests. 2018-04-11 13:36:17 +10:00
Damien George de9528d12c stm32/adc: Fix verification of ADC channel 16 for F411 MCUs. 2018-04-11 13:16:54 +10:00
Peter D. Gray 59dda71038 stm32/main: Guard usb_mode lines in default boot.py by relevant #if. 2018-04-10 23:52:51 +10:00
Damien George 4ff05ae4e9 esp32/machine_uart: Remove UART event queue object.
This event queue has UART events posted to it and they need to be drained
for it to operate without error.  The queue is not used by the uPy UART
class so it should be removed to prevent the IDF emitting errors.

Fixes #3704.
2018-04-10 15:24:10 +10:00
Damien George 22f1414abb stm32/i2c: Fully support peripheral I2C4. 2018-04-10 14:33:18 +10:00
Damien George 69bf23c9cf stm32/i2c: Update HAL macros to use new __HAL_RCC prefix. 2018-04-10 14:28:39 +10:00
iabdalkader e1e49adb86 stm32/boards/NUCLEO_H743ZI: Enable DAC peripheral. 2018-04-10 14:21:26 +10:00
iabdalkader 90bb98e83d stm32/dac: Add support for H7 MCUs.
Includes a fix for H7 DAC DMA requests.
2018-04-10 14:21:26 +10:00
Damien George cf31d384f1 py/stream: Switch stream close operation from method to ioctl.
This patch moves the implementation of stream closure from a dedicated
method to the ioctl of the stream protocol, for each type that implements
closing.  The benefits of this are:

1. Rounds out the stream ioctl function, which already includes flush,
   seek and poll (among other things).

2. Makes calling mp_stream_close() on an object slightly more efficient
   because it now no longer needs to lookup the close method and call it,
   rather it just delegates straight to the ioctl function (if it exists).

3. Reduces code size and allows future types that implement the stream
   protocol to be smaller because they don't need a dedicated close method.

Code size reduction is around 200 bytes smaller for x86 archs and around
30 bytes smaller for the bare-metal archs.
2018-04-10 13:41:32 +10:00
Damien George bc3a5f1917 stm32/mphalport: Use MCU regs to detect if cycle counter is started.
Instead of using a dedicated variable in RAM it's simpler to use the
relevant bits in the DWT register.
2018-03-29 16:23:52 +11:00
Damien George b833f170c3 stm32/main: Only update reset_mode if board doesn't use a bootloader.
If the board is configured to use a bootloader then that bootloader will
pass through the reset_mode.
2018-03-29 16:16:58 +11:00
Damien George 7856a416bd stm32/main: Rename main to stm32_main and pass through first argument.
The main() function has a predefined type in C which is not so useful for
embedded contexts.  This patch renames main() to stm32_main() so we can
define our own type signature for this function.  The type signature is
defined to have a single argument which is the "reset_mode" and is passed
through as r0 from Reset_Handler.  This allows, for example, a bootloader
to pass through information into the main application.
2018-03-29 16:15:57 +11:00
Damien George d9e69681f5 stm32: Add custom, optimised Reset_Handler code.
The Reset_Handler needs to copy the data section and zero the BSS, and
these operations should be as optimised as possible to reduce start up
time.  The versions provided in this patch are about 2x faster (on a Cortex
M4) than the previous implementations.
2018-03-29 15:29:23 +11:00
Damien George 7e28212352 stm32/boards/STM32L476DISC: Update to not take the address of pin objs. 2018-03-28 16:29:55 +11:00
Damien George 2dca693c24 stm32: Change pin_X and pyb_pin_X identifiers to be pointers to objects.
Rather than pin objects themselves.  The actual object is now pin_X_obj and
defines are provided so that pin_X is &pin_X_obj.  This makes it so that
code that uses pin objects doesn't need to know if they are literals or
objects (that need pointers taken) or something else.  They are just
entities that can be passed to the map_hal_pin_xxx functions.  This mirrors
how the core handles constant objects (eg mp_const_none which is
&mp_const_none_obj) and allows for the possibility of different
implementations of the pin layer.

For example, prior to this patch there was the following:

    extern const pin_obj_t pin_A0;
    #define pyb_pin_X1 pin_A0
    ...
    mp_hal_pin_high(&pin_A0);

and now there is:

    extern const pin_obj_t pin_A0_obj;
    #define pin_A0 (&pin_A0_obj)
    #define pyb_pin_X1 pin_A0
    ...
    mp_hal_pin_high(pin_A0);

This patch should have minimal effect on board configuration files.  The
only change that may be needed is if a board has .c files that configure
pins.
2018-03-28 16:29:50 +11:00
iabdalkader cf1d6df05a stm32/boards/NUCLEO_H743ZI: Enable SD card support. 2018-03-28 13:25:00 +11:00
iabdalkader b4f814c9b7 stm32/sdcard: Add H7 SD card support. 2018-03-28 13:25:00 +11:00
iabdalkader 9b9896b44d stm32/dma: Remove H7 SDMMC DMA descriptors.
The H7 SD peripheral has direct connection to MDMA instead.
2018-03-28 13:23:40 +11:00
Damien George 1efe6a0316 stm32/boards/NUCLEO_H743ZI: Update to build with new linker management. 2018-03-28 13:20:48 +11:00
Damien George b121c9515d stm32/boards/stm32h743.ld: Remove include of common.ld.
The relevant common.ld file should now be included explicitly by a
particular board.
2018-03-28 13:20:07 +11:00
Damien George 4d409b8e32 stm32/boards/stm32f767.ld: Add definition of FLASH_APP.
This allows F767 MCUs to support a bootloader in the first sector.
2018-03-27 21:35:03 +11:00
Damien George 04de9e33bc stm32/system_stm32: Set VTOR pointer from TEXT0_ADDR. 2018-03-27 21:32:39 +11:00
Damien George dcf4eb8134 stm32/boards: Add common_bl.ld for boards that need a bootloader. 2018-03-27 21:30:45 +11:00
Damien George ddb3b84c70 stm32/boards: Add common_basic.ld for a board to have a single section. 2018-03-27 21:29:45 +11:00
Damien George ed75b2655f stm32/Makefile: Allow a board to config either 1 or 2 firmware sections.
This patch forces a board to explicitly define TEXT1_ADDR in order to
split the firmware into two separate pieces.  Otherwise the default is now
to produce only a single continuous firmware image with all ISR, text and
data together.
2018-03-27 21:24:15 +11:00
Damien George 95b2cb008e stm32/Makefile: Rename FLASH_ADDR/TEXT_ADDR to TEXT0_ADDR/TEXT1_ADDR.
To make it clearer that these addresses are both for firmware text and that
they have a prescribed ordering.
2018-03-27 21:20:04 +11:00
Damien George 7aec06ca9a stm32/boards: Allow boards to have finer control over the linker script.
This patch allows a particular board to independently specify the linker
scripts for 1) the MCU memory layout; 2) how the different firmware
sections are arranged in memory.  Right now all boards follow the same
layout with two separate firmware section, one for the ISR and one for the
text and data.  This leaves room for storage (filesystem data) to live
between the firmware sections.

The idea with this patch is to accommodate boards that don't have internal
flash storage and only need to have one continuous firmware section.  Thus
the common.ld script is renamed to common_ifs.ld to make explicit that it
is used for cases where the board has internal flash storage.
2018-03-27 21:17:48 +11:00
Damien George a6009a9e35 stm32/*bdev.c: Eliminate dependency on sys_tick_has_passed.
Explicitly writing out the implementation of sys_tick_has_passed makes
these bdev files independent of systick.c and more reusable as a general
component.  It also reduces the code size slightly.

The irq.h header is added to spibdev.c because it uses declarations in that
file (irq.h is usually included implicitly via mphalport.h but not always).
2018-03-27 20:38:57 +11:00
Damien George 6f1e857624 stm32/qspi: Don't take the address of pin configuration identifiers.
Taking the address assumes that the pin is an object (eg a struct), but it
could be a literal (eg an int).  Not taking the address makes this driver
more general for other uses.
2018-03-27 20:34:55 +11:00
Damien George 6b51eb22c8 stm32: Consolidate include of genhdr/pins.h to single location in pin.h.
genhdr/pins.h is an internal header file that defines all of the pin
objects and it's cleaner to have pin.h include it (where the struct's for
these objects are defined) rather than an explicit include by every user.
2018-03-27 20:25:24 +11:00
Damien George b63cc1e9ef stm32/Makefile: Re-enable strict aliasing optimisation for ST HAL files.
The HAL requires strict aliasing optimisation to be turned on to function
correctly (at least for the SD card driver on F4 MCUs).  This optimisation
was recently disabled with the addition of H7 support due to the H7 HAL
having errors with the strict aliasing optimisation enabled.  But this is
now fixed in the latest stm32lib and so the optimisation can now be
re-enabled.

Thanks to @chuckbook for finding that there was a problem with the SD card
on F4 MCUs with the strict aliasing optimisation disabled.
2018-03-26 00:00:47 +11:00
iabdalkader 7b0a020a02 stm32/boards/NUCLEO_H743ZI: Disable uSD transceiver.
There's no uSD Transceiver on this NUCLEO board.
2018-03-20 23:26:03 +11:00
iabdalkader 1e0a67f290 stm32/boards/NUCLEO_H743ZI: Enable hardware I2C support. 2018-03-20 23:25:43 +11:00
iabdalkader 24a9facd89 stm32/i2c: Add H7 I2C timing configurations.
Found the timing for full (400 KHz) and FM+ (1MHz) in the HAL examples, and
used CubeMX to calculate the standard value (100KHz).
2018-03-20 23:25:01 +11:00
iabdalkader 2ebc538d63 stm32/dma: Enable H7 DMA descriptors. 2018-03-20 23:24:45 +11:00
Damien George 0abbafd424 stm32/can: Add "list" param to CAN.recv() to receive data inplace.
This API matches (as close as possible) how other pyb classes allow inplace
operations, such as pyb.SPI.recv(buf).
2018-03-19 15:12:24 +11:00
Damien George e37b8ba5a5 stm32: Use STM32xx macros instead of MCU_SERIES_xx to select MCU type.
The CMSIS files for the STM32 range provide macros to distinguish between
the different MCU series: STM32F4, STM32F7, STM32H7, STM32L4, etc.  Prefer
to use these instead of custom ones.
2018-03-17 10:42:50 +11:00
Damien George 06aa13c350 stm32/can: Use explicit byte extraction instead of casting to word ptr.
Casting the Data array to a uint32_t* leads to strict aliasing errors on
older gcc compilers.
2018-03-16 23:52:13 +11:00
Damien George a25e6c6b65 stm32/can: Add CAN.info() method to retrieve error and tx/rx buf info. 2018-03-16 18:28:35 +11:00
Damien George d7e67fb1b4 stm32/can: Add CAN.state() method to get the state of the controller.
This is useful for monitoring errors on the bus and knowing when a restart
is needed.
2018-03-16 17:10:41 +11:00
Damien George 1272c3c65d stm32/can: Add CAN.restart() method so controller can leave bus-off. 2018-03-15 17:29:30 +11:00
Damien George 823ca03008 stm32/can: Add "auto_restart" option to constructor and init() method. 2018-03-15 17:17:33 +11:00
Damien George 1608c4f5be stm32/can: Use enums to index keyword arguments, for clarity. 2018-03-15 17:15:41 +11:00
Damien George 2036196d71 stm32/can: Improve can.recv() so it checks for events, eg ctrl-C.
This patch provides a custom (and simple) function to receive data on the
CAN bus, instead of the HAL function.  This custom version calls
mp_handle_pending() while waiting for messages, which, among other things,
allows to interrupt the recv() method via KeyboardInterrupt.
2018-03-15 16:34:07 +11:00
Damien George 22a9158ced stm32/boards/STM32L476DISC: Enable CAN peripheral.
This board allows to test CAN support on the L4 series.
2018-03-15 16:32:11 +11:00
Damien George 34e224a4af esp32/machine_uart: Return None from UART read if no data is available.
This is instead of returning an empty bytes object, and matches how other
ports handle non-blocking UART read behaviour.
2018-03-14 13:18:43 +11:00
Damien George 033c32e694 esp8266/esp_mphal.h: Fix I2C glitching by using input mode for od_high.
Certain pins (eg 4 and 5) seem to behave differently at the hardware level
when in open-drain mode: they glitch when set "high" and drive the pin
active high for a brief period before disabling the output driver.  To work
around this make the pin an input to let it float high.
2018-03-12 12:45:09 +11:00
Damien George 1345093401 stm32/qspi: Do an explicit read instead of using memory-mapped mode.
Using an explicit read eliminates the need to invalidate the D-cache after
enabling the memory mapping mode, which takes additional time.
2018-03-11 18:28:48 +11:00
Damien George 0d5bccad11 stm32/storage: Provide support for a second block device. 2018-03-10 01:03:27 +11:00
Damien George bb3359f357 stm32/boards/STM32L476DISC: Provide SPI-flash bdev config.
This board shows how to configure external SPI flash as the main storage
medium.  It uses software SPI.
2018-03-10 00:59:43 +11:00
Damien George 626d6c9756 stm32/storage: Introduce MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE cfg.
This config variable controls whether to support storage on the internal
flash of the MCU.  It is enabled by default and should be explicitly
disabled by boards that don't want internal flash storage.
2018-03-10 00:59:43 +11:00
Damien George d1c4bd69df stm32/storage: Remove all SPI-flash bdev cfg, to be provided per board.
If a board wants to use SPI flash for storage then it must now provide the
configuration itself, using the MICROPY_HW_BDEV_xxx macros.
2018-03-10 00:59:43 +11:00
Damien George 1803e8ef22 stm32/storage: Make spi_bdev interface take a data pointer as first arg.
This allows a board to have multiple instances of the SPI block device.
2018-03-10 00:59:43 +11:00
Damien George 1e4caf0b1e stm32/storage: Merge all misc block-dev funcs into a single ioctl func.
It makes it cleaner, and simpler to support multiple different block
devices.  It also allows to easily extend a given block device with new
ioctl operations.
2018-03-10 00:59:43 +11:00
Damien George a739b35a96 drivers/memory/spiflash: Change to use low-level SPI object not uPy one.
This patch alters the SPI-flash memory driver so that it uses the new
low-level C SPI protocol (from drivers/bus/spi.h) instead of the uPy SPI
protocol (from extmod/machine_spi.h).  This allows the SPI-flash driver to
be used independently from the uPy runtime.
2018-03-10 00:59:43 +11:00
Damien George 58ebeca6a9 drivers/bus: Pull out software SPI implementation to dedicated driver.
This patch takes the software SPI implementation from extmod/machine_spi.c
and moves it to a dedicated file in drivers/bus/softspi.c.  This allows the
SPI driver to be used independently of the uPy runtime, making it a more
general component.
2018-03-10 00:59:43 +11:00
iabdalkader ad2a6e538c stm32/system_stm32: Fix CONFIG_RCC_CR_2ND value to use bitwise or. 2018-03-09 23:37:09 +11:00
Tom Collins 993f4345c0 stm32/usbd_conf.h: Add include of stdint.h to fix compilation issues. 2018-03-09 16:08:08 +11:00
Damien George eb56efb434 stm32: Remove startup_stm32.S, now provided in boards/ for each MCU. 2018-03-09 15:14:24 +11:00
iabdalkader 66748aaf60 stm32/Makefile: Use separate startup file for each MCU series. 2018-03-09 15:14:17 +11:00
iabdalkader 88157715db stm32/boards: Add startup_stm32l4.s for L4 series specific startup. 2018-03-09 15:14:10 +11:00
iabdalkader e3b81f5712 stm32/boards: Add startup_stm32f4.s for F4 series specific startup. 2018-03-09 15:14:03 +11:00
iabdalkader d84f1a90cc stm32/boards: Add startup_stm32f7.s for F7 series specific startup. 2018-03-09 15:13:56 +11:00
iabdalkader 0f5cce7753 stm32/boards: Add startup_stm32h7.s for H7 series specific startup. 2018-03-09 15:13:13 +11:00
iabdalkader bbf19bb64e stm32/main: Enable D2 SRAM1/2/3 clocks on H7 MCUs. 2018-03-09 15:12:58 +11:00
iabdalkader 61d463ad07 stm32/mpconfigboard_common: Add STM32H7 common configuration. 2018-03-09 15:12:44 +11:00
iabdalkader 6d3f42f713 stm32/extint: Add EXTI support for H7 MCUs. 2018-03-09 15:12:34 +11:00
iabdalkader 711f817c2a stm32/rtc: Add RTC support for H7 MCUs. 2018-03-09 15:12:29 +11:00
iabdalkader 0e51e4d139 stm32/dma: Add DMA support for H7 MCUs. 2018-03-09 15:12:19 +11:00
iabdalkader fe29419c10 stm32/stm32_it: Add support for H7 MCUs. 2018-03-09 15:12:01 +11:00
iabdalkader 2858e0aef8 stm32/usbd_conf: Add USB support for H7 MCUs. 2018-03-09 15:11:22 +11:00
iabdalkader d151adb791 stm32/modmachine: Support basic H7 MCU features. 2018-03-09 15:10:53 +11:00