Commit Graph

93 Commits

Author SHA1 Message Date
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
Damien George
3f6d3ccc11 stm32/usbdev: Pass thru correct val for SCSI PreventAllowMediumRemoval.
This value is "1" when the medium should not be removed, "0" otherwise.
2017-12-13 18:33:39 +11:00
Damien George
971699abe7 stm32: Add support for using the Python stack. 2017-12-11 13:49:09 +11:00
Damien George
6515acca70 stm32/boards/*_af.csv: Make consistent use of JTMS, JTCK, SWDIO, SWCLK.
5-pin JTAG and 2-pin SWD are logically separate interfaces so encode them
in the AF tables as separate entries (separated by /, not -).
2017-12-01 14:51:36 +11:00
Damien George
8f20231909 stm32/boards/stm32f767_af.csv: Update AF table based on datasheet.
Based on ST datasheet, DocID029041 Rev 3, DM00273119.pdf.
2017-12-01 14:48:17 +11:00
Damien George
811ddcc65f stm32/led: Remove unused LED enum constants. 2017-11-20 15:28:04 +11:00
Damien George
6906255dcd stm32/boards: Remove obsolete and unused board-specific defines.
These board-level macros have been completely replaced by feature-level
config options.
2017-11-20 15:25:28 +11:00
Jaroslav Sykora
3e9e9b07ba stm32/boards: Add support for NUCLEO-F746ZG evaluation board.
This is a low-cost evaluation kit board from ST based on the STM32
Nucleo-144 form factor.  It uses the STM32F746ZG MCU in the LQFP144
package.  The MCU has 1MB of flash and 320kB of System RAM.
Cortex-M7 runs at up to 216MHz.
2017-11-20 14:42:05 +11:00
Damien George
bbac2df0cf stm32/boards/stm32f746_af.csv: Fix typos in AF table. 2017-11-20 14:19:12 +11:00
Damien George
4601759bf5 py/objstr: Remove "make_qstr_if_not_already" arg from mp_obj_new_str.
This patch simplifies the str creation API to favour the common case of
creating a str object that is not forced to be interned.  To force
interning of a new str the new mp_obj_new_str_via_qstr function is added,
and should only be used if warranted.

Apart from simplifying the mp_obj_new_str function (and making it have the
same signature as mp_obj_new_bytes), this patch also reduces code size by a
bit (-16 bytes for bare-arm and roughly -40 bytes on the bare-metal archs).
2017-11-16 13:17:51 +11:00