Commit Graph

243 Commits

Author SHA1 Message Date
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
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
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
iabdalkader
0989e0cdff stm32/timer: Add Timer support for H7 MCUs. 2018-03-09 15:10:46 +11:00
iabdalkader
b982b95c18 stm32/uart: Add UART support for H7 MCUs. 2018-03-09 15:10:39 +11:00
iabdalkader
a863c60439 stm32/wdt: Add WDT support for H7 MCUs. 2018-03-09 15:10:31 +11:00
iabdalkader
3f86fbcb07 stm32/mphalport: Use GPIO BSRRL/BSRRH registers for H7 MCUs. 2018-03-09 15:10:10 +11:00
iabdalkader
2e93d4167d stm32/system_stm32: Add H7 MCU system initialisation. 2018-03-09 15:09:56 +11:00
iabdalkader
81f8f5f163 stm32/flash: Add flash support for H7 MCUs. 2018-03-09 15:09:49 +11:00
iabdalkader
b8d09b9bef stm32/Makefile: Add settings to support H7 MCUs. 2018-03-09 15:09:29 +11:00
iabdalkader
fabfacf3d7 stm32/boards: Add new NUCLEO_H743ZI board configuration files.
USB serial and mass storage works, and the REPL is also available via the
UART through the on-board ST-LINK.
2018-03-09 15:08:11 +11:00
Damien George
8522874167 stm32/boards: Add stm32h743.ld linker script. 2018-03-09 15:08:11 +11:00
Damien George
a3c721772e stm32/boards: Add stm32h743_af.csv file describing H7 GPIO alt funcs. 2018-03-09 14:06:34 +11:00
sec2
250b24fe36 stm32/boards/NUCLEO_F767ZI: Update pins list to include 3 extra pins. 2018-03-07 18:53:02 +11:00
sec2
bda3620616 stm32/boards/stm32f767_af.csv: Add ADC column to pin capability list. 2018-03-07 18:40:06 +11:00
Damien George
024edafea0 stm32/i2c: On F4 MCUs report the actual I2C SCL frequency. 2018-03-07 14:59:03 +11:00
Damien George
adda38cf76 stm32/qspi: Add hardware QSPI driver, with memory-map capability.
It supports the abstract QSPI protocol defined in drivers/bus/qspi.h.
2018-03-03 00:17:08 +11:00
Damien George
8bd0a51ca9 stm32/spibdev: Convert to use multiple block read/write interface.
The spiflash driver now supports read/write of multiple blocks at a time.
2018-03-03 00:13:15 +11:00
Damien George
861080aa3d stm32/storage: Add option for bdev to supply readblock/writeblocks.
If the underlying block device supports it, it's more efficient to
read/write multiple blocks at once.
2018-03-02 23:57:53 +11:00
Damien George
0210383da5 stm32/spibdev: Add option to configure SPI block dev to use QSPI flash.
To use QSPI (in software QSPI mode) the configuration needed is:

    #define MICROPY_HW_SPIFLASH_SIZE_BITS (n * 1024 * 1024)
    #define MICROPY_HW_SPIFLASH_CS      (pin_x1)
    #define MICROPY_HW_SPIFLASH_SCK     (pin_x2)
    #define MICROPY_HW_SPIFLASH_IO0     (pin_x3)
    #define MICROPY_HW_SPIFLASH_IO1     (pin_x4)
    #define MICROPY_HW_SPIFLASH_IO2     (pin_x5)
    #define MICROPY_HW_SPIFLASH_IO3     (pin_x6)
2018-03-02 23:55:45 +11:00
Damien George
a0dfc38641 stm32/spibdev: Update to work with new spiflash driver. 2018-03-02 23:55:40 +11:00
Damien George
989fc16162 stm32: Move MCU-specific cfg from mphalport.h to mpconfigboard_common.h.
It's cleaner to have all the MCU-specific configuration in one location,
not least to help with adding support for a new MCU series.
2018-02-23 16:54:07 +11:00
Damien George
ea05b400df stm32/flash: Use FLASH_TYPEPROGRAM_WORD to support newer HALs. 2018-02-23 16:30:47 +11:00
Damien George
e6220618ce stm32: Use "GEN" for describing files generated in the build.
Instead of "Create", to match the build output from the py/ core.
2018-02-23 16:27:30 +11:00
Damien George
60b0982bb2 stm32: Add board config option to enable/disable the ADC.
The new option is MICROPY_HW_ENABLE_ADC and is enabled by default.
2018-02-22 14:22:45 +11:00
Damien George
82828340a0 ports: Enable ucollections.deque on relevant ports.
These ports are all capable of running uasyncio.
2018-02-21 22:55:13 +11:00
Damien George
d966a33486 stm32: Change header include guards from STMHAL to STM32 to match dir. 2018-02-15 15:47:04 +11:00
Damien George
fa13e0d35b stm32: Factor out flash and SPI block-device code to separate files.
Prior to this patch, storage.c was a combination of code that handled
either internal flash or external SPI flash and exposed one of them as a
block device for the local storage.  It was also exposed to the USB MSC.

This patch splits out the flash and SPI code to separate files, which each
provide a general block-device interface (at the C level).  Then storage.c
just picks one of them to use as the local storage medium.  The aim of this
factoring is to allow to add new block devices in the future and allow for
easier configurability.
2018-02-13 22:21:46 +11:00
Damien George
34911f1a57 stm32/boards: Update all boards to work with new USB configuration. 2018-02-13 18:57:01 +11:00