Commit Graph

202 Commits

Author SHA1 Message Date
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
Damien George 5c320bd0b0 stm32: Introduce MICROPY_HW_ENABLE_USB and clean up USB config.
This patch allows to completely compile-out support for USB, and no-USB is
now the default.  If a board wants to enable USB it should define:

    #define MICROPY_HW_ENABLE_USB (1)

And then one or more of the following to select the USB PHY:

    #define MICROPY_HW_USB_FS (1)
    #define MICROPY_HW_USB_HS (1)
    #define MICROPY_HW_USB_HS_IN_FS (1)
2018-02-13 18:51:08 +11:00
Damien George 8aad22fdca stm32/timer: Support MCUs that don't have TIM4 and/or TIM5. 2018-02-13 15:53:39 +11:00
Damien George 6e91ab5806 stm32/spi: Further updates to use newer versions of HAL names. 2018-02-13 15:53:08 +11:00
Damien George 3eb0694b97 stm32: Update HAL macro and constant names to use newer versions.
Newer versions of the HAL use names which are cleaner and more
self-consistent amongst the HAL itself.  This patch switches to use those
names in most places so it is easier to update the HAL in the future.
2018-02-13 15:37:35 +11:00
Damien George 8e1cb58a23 stm32/usbdev: Fix USBD setup request handler to use correct recipient.
Prior to this patch the USBD driver did not handle the recipient correctly
for setup requests.  It was not interpreting the req->wIndex field in the
right way: in some cases this field indicates the endpoint number but the
code was assuming it always indicated the interface number.

This patch fixes this.  The only noticeable change is to the MSC
interface, which should now correctly respond to the USB_REQ_CLEAR_FEATURE
request and hence unmount properly from the host when requested.
2018-02-12 17:22:59 +11:00
Damien George 02f88cb2df stm32/boards: Remove all config options that are set to defaults.
mpconfigboard_common.h now sets the defaults so there is no longer a need
to explicitly list all configuration options in a board's mpconfigboard.h
file.
2018-02-09 18:40:40 +11:00
Damien George 2d5bab46be stm32: Add mpconfigboard_common.h with common/default board settings.
This file mirrors py/mpconfig.h but for board-level config options.  It
provides a default configuration, to be overridden by a specific
mpconfigboard.h file, as well as setting up certain macros to automatically
configure a board.
2018-02-09 18:40:13 +11:00
Damien George cc92c0572e stm32/main: Remove need for first_soft_reset variable. 2018-02-05 16:13:05 +11:00
Damien George 4607be3768 stm32/main: Reorder some init calls to put them before soft-reset loop.
The calls to rtc_init_start(), sdcard_init() and storage_init() are all
guarded by a check for first_soft_reset, so it's simpler to just put them
all before the soft-reset loop, without the check.

The call to machine_init() can also go before the soft-reset loop because
it is only needed to check the reset cause which can happen once at the
first boot.  To allow this to work, the reset cause must be set to SOFT
upon a soft-reset, which is the role of the new function machine_deinit().
2018-02-05 15:52:36 +11:00
Damien George 12464f1bd2 stm32/rtc: Add compile-time option to set RTC source as LSE bypass.
To use the LSE bypass feature (where an external source provides the RTC
clock) a board must set the config variable MICROPY_HW_RTC_USE_BYPASS.
2018-02-05 15:22:15 +11:00
Damien George 011d1555cb stm32/rtc: Fix RTC init to use LSI if LSI is already selected on boot.
Upon boot the RTC early-init function should detect if LSE or LSI is
already selected/running and, if so, use it.  When the LSI has previously
(in the previous reset cycle) been selected as the clock source the only
way to reliably tell is if the RTCSEL bits of the RCC_BDCR are set to the
correct LSI value.  In particular the RCC_CSR bits for LSI control do not
indicate if the LSI is ready even if it is selected.

This patch removes the check on the RCC_CSR bits for the LSI being on and
ready and only uses the check on the RCC_BDCR to see if the LSI should be
used straightaway.  This was tested on a PYBLITEv1.0 and with the patch the
LSI persists correctly as the RTC source as long as the backup domain
remains powered.
2018-02-05 15:12:22 +11:00
Damien George 5a62f0faa6 stm32/rtc: Fix rtc_info flags when LSE fails and falls back to LSI.
Previously, if LSE is selected but fails and the RTC falls back to LSI,
then the rtc_info flags would incorrectly state that LSE is used.  This
patch fixes that by setting the bit in rtc_info only after the clock is
ready.
2018-02-05 14:40:06 +11:00
Damien George 20f5de9b39 stm32/spi: Accept machine.SPI object in spi_from_mp_obj() function.
Also, change ValueError to TypeError if the argument to this function is
not of an SPI type.
2018-02-05 14:32:56 +11:00
Damien George f8922627d3 stm32: Update LCD and network drivers to work with new SPI API. 2018-02-05 14:32:56 +11:00
Damien George 4ad3ede21a stm32/spi: Provide better separation between SPI driver and uPy objs.
There is an underlying hardware SPI driver (built on top of the STM HAL)
and then on top of this sits the legacy pyb.SPI class as well as the
machine.SPI class.  This patch improves the separation between these
layers, in particular decoupling machine.SPI from pyb.SPI.
2018-02-05 14:30:32 +11:00
Damien George 4b8e58756b stm32/i2c: Allow I2C peripheral state to persist across a soft reset.
The I2C sub-system is independent from the uPy state (eg the heap) and so
can safely persist across a soft reset.
2018-02-02 19:04:36 +11:00
Damien George 5ddd1488bd stm32/spi: Allow SPI peripheral state to persist across a soft reset.
The SPI sub-system is independent from the uPy state (eg the heap) and so
can safely persist across a soft reset.  And this is actually necessary for
drivers that rely on SPI and that also need to persist across soft reset
(eg external SPI flash memory).
2018-02-02 19:01:11 +11:00
Damien George 57d2ac1300 stm32/rng: Simplify RNG implementation by accessing raw peripheral regs.
It saves code size and RAM, and is more efficient to execute.
2018-02-02 18:22:57 +11:00
Damien George 762db9ad2f stm32/spi: Add support for a board naming SPI peripherals 4, 5 and 6. 2018-02-02 17:44:05 +11:00
liamkinne 618aaa4a53 stm32/i2c: Use macros instead of magic numbers for I2C speed grades. 2018-02-02 12:15:05 +11:00
Damien George db702ba722 stm32/usbdev: Add support for high-speed USB device mode.
This patch adds support in the USBD configuration and CDC-MSC-HID class for
high-speed USB mode.  To enable it the board configuration must define
USE_USB_HS, and either not define USE_USB_HS_IN_FS, or be an STM32F723 or
STM32F733 MCU which have a built-in HS PHY.  High-speed mode is then
selected dynamically by passing "high_speed=True" to the pyb.usb_mode()
function, otherwise it defaults to full-speed mode.

This patch has been tested on an STM32F733.
2018-02-01 17:57:44 +11:00
Damien George 71312d0bd1 stm32/usb: Allow board to select which USBD is used as the main one.
By defining MICROPY_HW_USB_MAIN_DEV a given board can select to use either
USB_PHY_FS_ID or USB_PHY_HS_ID as the main USBD peripheral, on which the
REPL will appear.  If not defined this will be automatically configured.
2018-02-01 17:47:28 +11:00
Damien George 3130424b54 stm32/usbdev: Add support for MSC-only USB device class.
Select this mode in boot.py via: pyb.usb_mode('MSC')
2018-02-01 15:47:16 +11:00
Damien George 72ca049de7 stm32/sdcard: Use maximum speed SDMMC clock on F7 MCUs.
This will get the SDMMC clock up to 48MHz.
2018-02-01 15:17:18 +11:00
Damien George 467a5926bc stm32/sdcard: Only define IRQ handler if using SDMMC1 peripheral.
So that the IRQ can be used by other peripheral drivers if needed.
2018-02-01 15:02:04 +11:00
Damien George 9e7d2c7abb stm32/modmachine: In freq(), select flash latency value based on freq. 2018-02-01 14:06:18 +11:00
Damien George e8a8fa77ca stm32: Improve support for STM32F722, F723, F732, F733 MCUs. 2018-02-01 13:11:32 +11:00
Damien George 4e35d10829 stm32/can: Support MCUs without a CAN2 peripheral. 2018-02-01 13:11:02 +11:00
Damien George 583472e068 stm32/usbdev: Combine all str descriptor accessor funcs into one func.
There's no need to have these as separate functions, they just take up
unnecessary code space and combining them allows to factor common code, and
also allows to support arbitrary string descriptor indices.
2018-02-01 12:46:37 +11:00
Damien George 1d4246a2e8 stm32/usbdev: Reduce dependency on py header files. 2018-02-01 12:44:16 +11:00
Damien George fed1b4fb56 stm32/sdcard: Make SD wait routine more power efficient by using WFI.
Using WFI allows the CPU to sleep while it is waiting, reducing power
consumption.
2018-02-01 12:20:45 +11:00
Damien George c0496fd44d stm32/spi: Make SPI DMA wait routine more power efficient by using WFI.
The routine waits for the DMA to finish, which is signalled from a DMA IRQ
handler.  Using WFI makes the CPU sleep while waiting for the IRQ to arrive
which decreases power consumption.  To make it work correctly the check for
the change in state must be atomic and so IRQs must be disabled during the
check.  The key feature of the Cortex MCU that makes this possible is that
WFI will exit when an IRQ arrives even if IRQs are disabled.
2018-02-01 11:45:29 +11:00
Damien George efdda2c62d stm32: Add support for DHT11/DHT22 sensors. 2018-01-31 18:12:53 +11:00
Peter D. Gray 1ed2c23efb stm32/modmachine: Handle case of no MICROPY_PY_MACHINE_I2C. 2018-01-31 15:59:04 +11:00
Peter D. Gray dfe8980acf stm32/spi: If MICROPY_HW_SPIn_MISO undefined, do not claim pin on init.
This permits output-only SPI use.
2017-12-28 18:00:20 +11:00
Damien George b806889512 stm32/i2c: Support more I2C baudrates for F746, and more F7 MCUs. 2017-12-23 19:24:24 +11:00
Damien George 008e1788e8 stm32/i2c: Fix bug with I2C4 initialisation. 2017-12-23 19:22:52 +11:00
Damien George d32417c096 stm32/uart: Support board configs with CTS/RTS on UART6. 2017-12-23 19:03:16 +11:00
Peter D. Gray 7a46d9ae73 stm32/uart: Add support for 7-bit modes: 7N1 and 7N2. 2017-12-22 15:37:17 +11:00
Damien George c73360bfdb stm32: Allow to build a board without any hardware I2C ports defined.
This patch adds in internal config value MICROPY_HW_ENABLE_HW_I2C that is
automatically configured, and enabled only if one or more hardware I2C
ports are defined in the mpconfigboard.h file.  If none are defined then
the pyb.I2C class is excluded from the build, along with all supporting
code.  The machine.I2C class will still be available for software I2C.

Disabling all hardware I2C on an F4 board saves around 10,000 bytes of code
and 200 bytes of RAM.
2017-12-22 15:20:42 +11:00
Peter D. Gray 82dc5c1d8c stm32: Use corrected capitalization of HAL_SD_CardStateTypedef.
It was originally TypeDef.  STM32L4 only supports Typedef and F4/F7 have
legacy macros in stm32_hal_legacy.h to support both.
2017-12-22 14:49:31 +11:00