Commit Graph

351 Commits

Author SHA1 Message Date
Damien George
5962c210c5 stm32/mboot: Define constants for reset mode cycling and timeout.
And fix timeout value so that it does actually finish with reset_mode=1.
2018-06-19 23:23:17 +10:00
Damien George
e49cd106b4 stm32/spi: Fix SPI driver so it can send/recv more than 65535 bytes.
The DMA peripheral is limited to transferring 65535 elements at a time so
in order to send more than that the SPI driver must split the transfers up.

The user must be aware of this limit if they are relying on precise timing
of the entire SPI transfer, because there might be a small delay between
the split transfers.

Fixes issue #3851, and thanks to @kwagyeman for the original fix.
2018-06-18 17:41:14 +10:00
Damien George
338af99a7f stm32/can: Use MP_OBJ_ARRAY_TYPECODE_FLAG_RW where appropriate. 2018-06-18 13:42:05 +10:00
rolandvs
ca2b1d6b36 stm32/boards/NUCLEO_F091RC: Add Arduino-named pins and rename CPU pins.
To match pin labels on other NUCLEO 64 boards.
2018-06-18 13:06:27 +10:00
rolandvs
0d3de68669 stm32/boards/stm32f091_af.csv: Split labels that are multiple funcs. 2018-06-18 13:05:24 +10:00
Damien George
ceff433fcc stm32/mboot: Adjust user-reset-mode timeout so it ends with mode=1.
If the user button is held down indefinitely (eg unintenionally, or because
the GPIO signal of the user button is connected to some external device)
then it makes sense to end the reset mode cycle with the default mode of
1, which executes code as normal.
2018-06-18 12:23:27 +10:00
Damien George
7be4a23c0c stm32/i2cslave: Fix ordering of event callbacks in slave IRQ handler.
It's possible (at least on F4 MCU's) to have RXNE and STOPF set at the same
time during a call to the slave IRQ handler.  In such cases RXNE should be
handled before STOPF so that all bytes are processed before
i2c_slave_process_rx_end() is called.
2018-06-15 14:15:31 +10:00
Damien George
bc5e8a2cb6 stm32/i2c: Fix num_acks calculation in i2c_write for F0 and F7 MCU's.
Due to buffering of outgoing bytes on the I2C bus, detection of a NACK
using the ISR_NACKF flag needs to account for the case where ISR_NACKF
corresponds to the previous-to-previous byte.
2018-06-15 14:10:53 +10:00
Damien George
37a7257aff stm32/timer: Support TIM1 on F0 MCUs. 2018-06-15 10:50:08 +10:00
Damien George
cc5a94044a drivers/memory/spiflash: Rename functions to indicate they use cache.
This patch renames the existing SPI flash API functions to reflect the fact
that the go through the cache:

    mp_spiflash_flush -> mp_spiflash_cache_flush
    mp_spiflash_read  -> mp_spiflash_cached_read
    mp_spiflash_write -> mp_spiflash_cached_write
2018-06-14 16:52:56 +10:00
Damien George
335d26b27d stm32/boards/STM32L476DISC: Update SPI flash config for cache change. 2018-06-14 16:52:56 +10:00
Damien George
5042d98514 stm32/Makefile: Rebuild all qstrs when any board configuration changes. 2018-06-12 13:53:43 +10:00
Damien George
565f590586 ports: Enable IOBase on unix, stm32, esp8266 and esp32.
It's a core feature, in particular required for user-streams with uasyncio.
2018-06-12 12:29:26 +10:00
Damien George
b2fa1b50ed ports: Call gc_sweep_all() when doing a soft reset.
This calls finalisers of things like files and sockets to cleanly close
them.
2018-06-12 11:56:25 +10:00
Damien George
24c416cc66 stm32/mboot: Increase USB rx_buf and DFU buf sizes to full 2048 bytes.
The DFU USB config descriptor returns 0x0800=2048 for the supported
transfer size, and this applies to both TX (IN) and RX (OUT).  So increase
the rx_buf to support this size without having a buffer overflow on
received data.

With this patch mboot in USB DFU mode now works with dfu-util.
2018-06-08 15:29:52 +10:00
Damien George
190c7dba89 stm32/mpconfigport.h: Enable DELATTR_SETATTR and BUILTINS_NOTIMPLEMENTED
MICROPY_PY_DELATTR_SETATTR can now be enabled without a performance hit for
classes that don't use this feature.

MICROPY_PY_BUILTINS_NOTIMPLEMENTED is a minor addition that improves
compatibility with CPython.
2018-06-08 12:55:18 +10:00
Damien George
93150a0d40 ports: Enable descriptors on stm32, esp8266, esp32 ports.
They are now efficient (in runtime performance) and provide a useful
feature that's hard to obtain without them enabled.

See issue #3644 and PR #3826 for background.
2018-06-08 12:23:08 +10:00
Damien George
f35aae366c extmod/vfs_fat: Rename FileIO/TextIO types to mp_type_vfs_fat_XXX.
So they don't clash with other VFS implementations.
2018-06-06 14:28:23 +10:00
Damien George
309fe39dbb stm32/modnetwork: Fix arg indexing in generic ifconfig method. 2018-06-03 21:50:49 +10:00
Damien George
7d86ac6c01 stm32: Add network driver for Wiznet5k using MACRAW mode and lwIP.
The Wiznet5k series of chips support a MACRAW mode which allows the host to
send and receive Ethernet frames directly.  This can be hooked into the
lwIP stack to provide a full "socket" implementation using this Wiznet
Ethernet device.  This patch adds support for this feature.

To enable the feature one must add the following to mpconfigboard.mk, or
mpconfigport.mk:

    MICROPY_PY_WIZNET5K = 5500

and the following to mpconfigboard.h, or mpconfigport.h:

    #define MICROPY_PY_LWIP (1)

After wiring up the module (X5=CS, X4=RST), usage on a pyboard is:

    import time, network
    nic = network.WIZNET5K(pyb.SPI(1), pyb.Pin.board.X5, pyb.Pin.board.X4)
    nic.active(1)
    while not nic.isconnected():
        time.sleep_ms(50) # needed to poll the NIC
    print(nic.ifconfig())

Then use the socket module as usual.

Compared to using the built-in TCP/IP stack on the Wiznet module, some
performance is lost in MACRAW mode: with a lot of memory allocated to lwIP
buffers, lwIP gives Around 750,000 bytes/sec max TCP download, compared
with 1M/sec when using the TCP/IP stack on the Wiznet module.
2018-06-01 14:21:38 +10:00
Damien George
d9f1ecece2 stm32/modnetwork: Provide generic implementation of ifconfig method.
All it needs is a lwIP netif to function.
2018-06-01 13:33:14 +10:00
Damien George
7437215ad7 stm32/modnetwork: Change base entry of NIC object from type to base.
mod_network_nic_type_t doesn't need to be an actual uPy type, it just needs
to be an object.
2018-06-01 13:31:28 +10:00
Damien George
6d87aa54d6 stm32/modnetwork: Don't take netif's down when network is deinited.
It should be up to the NIC itself to decide if the network interface is
removed upon soft reset.  Some NICs can keep the interface up over a soft
reset, which improves usability of the network.
2018-06-01 13:27:06 +10:00
Damien George
a1acbad27a stm32/flash: Increase H7 flash size to full 2MiB. 2018-05-30 09:54:51 +10:00
rolandvs
958fa74521 stm32/boards: Ensure USB OTG power is off for NUCLEO_F767ZI.
And update the GPIO init for NUCLEO_H743ZI to consistently use the mphal
functions.
2018-05-30 09:51:19 +10:00
rolandvs
50bc34d4a4 stm32/boards: Split combined alt-func labels and fix some other errors.
Pins with multiple alt-funcs for the same peripheral (eg USART_CTS_NSS)
need to be split into individual alt-funcs for make-pins.py to work
correctly.

This patch changes the following:
- Split `..._CTS_NSS` into `..._CTS/..._NSS`
- Split `..._RTS_DE` into `..._RTS/..._DE`
- Split `JTDO_SWO` into `JTDO/TRACESWO` for consistency
- Fixed `TRACECK` to `TRACECLK` for consistency
2018-05-29 21:37:49 +10:00
Damien George
98d1609358 stm32/README: Update to include STM32F0 in list of supported MCUs. 2018-05-28 22:04:08 +10:00
Damien George
e681372017 stm32/boards: Add NUCLEO_F091RC board configuration files. 2018-05-28 21:49:49 +10:00
Damien George
1163400039 stm32/boards: Add alt-func CSV list and linker script for STM32F091. 2018-05-28 21:49:49 +10:00
Damien George
ea7e747979 stm32: Add support for STM32F0 MCUs. 2018-05-28 21:49:49 +10:00
Damien George
4a7d157a5b stm32/boards: Add startup_stm32f0.s for STM32F0 MCUs.
Sourced from STM32Cube_FW_F0_V1.9.0.
2018-05-28 21:49:49 +10:00
Damien George
6d83468a30 stm32: Allow a board to disable MICROPY_VFS_FAT. 2018-05-28 21:46:20 +10:00
Damien George
5c0685912f stm32/timer: Make timer_get_source_freq more efficient by using regs.
Use direct register access to get the APB clock divider.  This reduces code
size and makes the code more efficient.
2018-05-28 21:46:20 +10:00
Damien George
070937fe93 stm32: Add support for Cortex-M0 CPUs. 2018-05-28 21:46:20 +10:00
Damien George
f497723802 stm32: Allow to have no storage support if there are no block devices.
If no block devices are defined by a board then storage support will be
disabled.  This means there is no filesystem provided by either the
internal flash or external SPI flash.  But the VFS system can still be
enabled and filesystems provided on external devices like an SD card.
2018-05-28 21:45:46 +10:00
Damien George
aa4a7a8732 stm32/usb: Guard USB device code with #if for whether USB is enabled.
With this change, all the USB source code can now be passed through the
compiler even if the MCU does not have a USB peripheral.
2018-05-28 21:45:46 +10:00
Damien George
15ddc20436 stm32: Add new component, the mboot bootloader.
Mboot is a custom bootloader for STM32 MCUs.  It can provide a USB DFU
interface on either the FS or HS peripherals, as well as a custom I2C
bootloader interface.
2018-05-24 23:21:19 +10:00
Damien George
f47eeab0ad stm32: Add low-level hardware I2C slave driver. 2018-05-24 23:11:13 +10:00
Damien George
4200018a05 stm32: Remove unneeded HTML release notes from usbdev and usbhost dirs.
These files provide no additional information, all the version and license
information is captured in the relevant files in these subdirectories.

Thanks to @JoeSc for the original patch.
2018-05-24 11:28:54 +10:00
Damien George
20b4b85f72 ports: Enable MICROPY_PY_BUILTINS_ROUND_INT on selected ports. 2018-05-22 14:18:16 +10:00
Damien George
e773a2cdba stm32/main: Use consistent indenting of macro #if's. 2018-05-22 13:17:03 +10:00
Damien George
f68e722005 stm32/rng: Use Yasmarang for rng_get() if MCU doesn't have HW RNG. 2018-05-22 10:36:03 +10:00
Damien George
cda964198a stm32: Integrate lwIP as implementation of usocket module.
This patch allows to use lwIP as the implementation of the usocket module,
instead of the existing socket-multiplexer that delegates the entire TCP/IP
layer to the NIC itself.

This is disabled by default, and enabled by defining MICROPY_PY_LWIP to 1.

When enabled, the lwIP TCP/IP stack will be included in the build with
default settings for memory usage and performance (see
lwip_inc/lwipopts.h).  It is then up to a particular NIC to register itself
with lwIP using the standard lwIP netif API.
2018-05-21 17:36:06 +10:00
Damien George
6c955932f3 stm32/rtc: Don't try to set SubSeconds value on RTC.
The hardware doesn't allow it, instead the value is reset to 255 upon
setting the other calendar/time values.
2018-05-21 14:08:37 +10:00
Tobias Badertscher
769e37b646 stm32/boards: Add config files for new board, STM32L496GDISC. 2018-05-18 22:39:49 +10:00
Tobias Badertscher
4005c63571 stm32/boards: Add board ld and af.csv files for STM32L496 MCU. 2018-05-18 22:39:44 +10:00
Tobias Badertscher
708cdb6276 stm32: Add support for STM32L496 MCU. 2018-05-18 22:37:30 +10:00
Ryan Shaw
b9ff46f1ed stm32: Enable UART7/8 on F4 series that have these peripherals. 2018-05-16 11:55:07 +10:00
Damien George
e6b66f1092 stm32/usb: Initialise cdc variable to prevent compiler warnings.
Some compilers cannot deduce that cdc will always be written before being
used.
2018-05-15 00:18:03 +10:00
Damien George
47ecbbbecb stm32/usb: Add ability to have 2x VCP interfaces on the one USB device.
This patch adds the configuration MICROPY_HW_USB_ENABLE_CDC2 which enables
a new USB device configuration at runtime: VCP+VCP+MSC.  It will give two
independent VCP interfaces available via pyb.USB_VCP(0) and pyb.USB_VCP(1).
The first one is the usual one and has the REPL on it.  The second one is
available for general use.

This configuration is disabled by default because if the mode is not used
then it takes up about 2200 bytes of RAM.  Also, F4 MCUs can't support this
mode on their USB FS peripheral (eg PYBv1.x) because they don't have enough
endpoints.  The USB HS peripheral of an F4 supports it, as well as both the
USB FS and USB HS peripherals of F7 MCUs.
2018-05-14 23:44:45 +10:00
Damien George
2e565cc0d4 stm32/usb: Change HID report funcs to take HID state, not usbdev state. 2018-05-14 17:04:43 +10:00
Damien George
91bca340ec stm32/usb: Change CDC tx/rx funcs to take CDC state, not usbdev state. 2018-05-14 16:55:04 +10:00
Damien George
68271a27e6 stm32/usb: Make CDC endpoint definitions private to core usbdev driver. 2018-05-14 16:53:45 +10:00
Damien George
ed92d62326 stm32/usb: Combine HID lower-layer and interface state into one struct. 2018-05-14 16:34:31 +10:00
Damien George
bf08a99ccd stm32/usb: Combine CDC lower-layer and interface state into one struct. 2018-05-14 16:15:58 +10:00
Damien George
ed32284b70 stm32/usb: Use usbd_cdc_itf_t pointer directly in USB_VCP class. 2018-05-14 15:24:44 +10:00
Damien George
fb25c81062 stm32/modpyb: Remove unused includes and clean up comments.
The documentation (including the examples) for elapsed_millis and
elapsed_micros can be found in docs/library/pyb.rst so doesn't need to be
written in full in the source code.
2018-05-14 14:01:50 +10:00
Damien George
88c26a48b4 stm32/pyb_i2c: Put pyb.I2C under MICROPY_PY_PYB_LEGACY setting.
When disabled, the pyb.I2C class saves around 8k of code space and 172
bytes of RAM.  The same functionality is now available in machine.I2C
(for F4 and F7 MCUs).

It is still enabled by default.
2018-05-14 13:53:46 +10:00
Damien George
92c5e2708d stm32/modpyb: Introduce MICROPY_PY_PYB_LEGACY config option for pyb mod.
This is enabled by default.  When it is disabled all legacy functions and
classes in the pyb module are excluded from the build.
2018-05-14 13:49:22 +10:00
Damien George
a0f7b4c678 stm32/accel: Switch pyb.Accel to use new C-level I2C API. 2018-05-14 13:23:18 +10:00
Damien George
ce824bb67e stm32/machine_i2c: Use new F4 hardware I2C driver for machine.I2C class.
And remove the old one based on ST code.
2018-05-14 13:22:12 +10:00
Damien George
b21415ed4f stm32/i2c: Add new hardware I2C driver for F4 MCUs.
This driver uses low-level register access to control the I2C peripheral
(ie it doesn't rely on the ST HAL) and provides the same C-level API as the
existing F7 hardware driver.
2018-05-14 13:19:03 +10:00
Peter D. Gray
ca36645410 stm32/usbd_hid_interface: Address possible race condition vs. interrupt.
The USB IRQ may fire once USBD_HID_ClearNAK() is called and then change the
last_read_len value.
2018-05-14 12:08:34 +10:00
Peter D. Gray
1f1623d3b7 stm32/usbdev: Be honest about data not being written to HID endpoint.
USB_HID.send() should now return 0 if it could not send the report to the
host.
2018-05-14 12:01:27 +10:00
Damien George
aeaace0737 stm32/usbdev: Remove unused RxState variable, and unused struct. 2018-05-11 23:20:59 +10:00
Damien George
abde0fa226 stm32/usbdev: Convert files to unix line endings.
Also remove trailing whitespace and convert tabs to spaces.
2018-05-11 23:03:52 +10:00
Damien George
56a273ebff stm32/usbd_conf: Changes files to unix line endings and apply styling.
This patch is only cosmetic and has no functional change.
2018-05-11 22:17:58 +10:00
Damien George
9f4eda542a stm32/usbd_conf.h: Remove unused macros and clean up header file. 2018-05-11 22:04:56 +10:00
Damien George
b208aa189e stm32/README: Update to reflect current MCU support. 2018-05-11 10:36:46 +10:00
Damien George
c1115d931f stm32/usb: Use correct type for USB HID object. 2018-05-09 16:00:19 +10:00
Damien George
e1bc85416a stm32/usb: Fix broken pyb.have_cdc() so it works again. 2018-05-09 15:59:48 +10:00
Damien George
e638defff4 stm32/i2c: Make sure stop condition is sent after receiving addr nack. 2018-05-09 15:53:09 +10:00
Damien George
aea71dbde0 stm32/Makefile: Use -O2 to optimise compilation of lib/libc/string0.c. 2018-05-04 15:53:51 +10:00
Damien George
cb3456ddfe stm32: Don't use %lu or %lx for formatting, use just %u or %x.
On this 32-bit arch there's no need to use the long version of the format
specifier.  It's only there to appease the compiler which checks the type
of the args passed to printf.  Removing the "l" saves a bit of code space.
2018-05-04 15:52:03 +10:00
Damien George
b614dc73b0 stm32/dma: Fix duplicate typedef of struct, it's typedef'd in dma.h. 2018-05-04 15:35:43 +10:00
Damien George
051686b0a8 stm32/main: Clean up and optimise initial start-up code of the MCU. 2018-05-02 15:20:24 +10:00
Damien George
a03e6c1e05 stm32/irq: Define IRQ priorities directly as encoded hardware values.
For a given IRQn (eg UART) there's no need to carry around both a PRI and
SUBPRI value (eg IRQ_PRI_UART, IRQ_SUBPRI_UART).  Instead, the IRQ_PRI_UART
value has been changed in this patch to be the encoded hardware value,
using NVIC_EncodePriority.  This way the NVIC_SetPriority function can be
used directly, instead of going through HAL_NVIC_SetPriority which must do
extra processing to encode the PRI+SUBPRI.

For a priority grouping of 4 (4 bits for preempt priority, 0 bits for the
sub-priority), which is used in the stm32 port, the IRQ_PRI_xxx constants
remain unchanged in their value.

This patch also "fixes" the use of raise_irq_pri() which should be passed
the encoded value (but as mentioned above the unencoded value is the same
as the encoded value for priority grouping 4, so there was no bug from this
error).
2018-05-02 14:41:02 +10:00
Peter D. Gray
266446624f stm32/dma: Always deinit/reinit DMA channels on L4 MCUs.
The problem is the existing code which tries to optimise the
reinitialisation of the DMA breaks the abstraction of the HAL.  For the
STM32L4 the HAL's DMA setup code maintains two private vars (ChannelIndex,
DmaBaseAddress) and updates a hardware register (CCR).

In HAL_DMA_Init(), the CCR is updated to set the direction of the DMA.
This is a problem because, when using the SD Card interface, the same DMA
channel is used in both directions, so the direction bit in the CCR must
follow that.

A quick and effective fix for the L4 is to simply call HAL_DMA_DeInit() and
HAL_DMA_Init() every time.
2018-05-02 13:41:23 +10:00
Damien George
4c0f664b1a stm32/flash: Remove unused src parameter from flash_erase(). 2018-05-02 13:11:56 +10:00
Damien George
edb600b6a2 stm32/mphalport: Optimise the way that GPIO clocks are enabled. 2018-05-02 13:08:58 +10:00
Damien George
00a659f3ee stm32/dac: Implement printing of a DAC object. 2018-05-02 12:17:45 +10:00
Damien George
dcfd2de5c2 stm32/dac: Make deinit disable the output buffer on H7 and L4 MCUs. 2018-05-02 12:17:45 +10:00
Damien George
d4f8414ebd stm32/adc: Use mp_hal_pin_config() instead of HAL_GPIO_Init().
This makes ADCAll work correctly on L4 MCUs.
2018-05-02 12:17:45 +10:00
Damien George
3022947343 stm32/mphalport: Support ADC mode on a pin for L4 MCUs. 2018-05-02 12:17:45 +10:00
Damien George
68f4cba3d2 stm32/boards: Update pins.csv to include USB pins where needed. 2018-05-01 17:38:51 +10:00
Damien George
b0ad46cd11 stm32/dac: Use mp_hal_pin_config() instead of HAL_GPIO_Init(). 2018-05-01 17:33:08 +10:00
Damien George
04ead56614 stm32/usbd_conf: Use mp_hal_pin_config() instead of HAL_GPIO_Init.
To reduce dependency on the ST HAL for pin operations.
2018-05-01 17:32:19 +10:00
Damien George
a28bd4ac94 stm32/mphalport: Add mp_hal_pin_config_speed() to select GPIO speed.
It should be used after mp_hal_pin_config() or mp_hal_pin_config_alt().
2018-05-01 17:31:23 +10:00
iabdalkader
28c9824c51 stm32/boards/NUCLEO_H743ZI: Enable ADC peripheral. 2018-05-01 15:39:03 +10:00
iabdalkader
8c12f1d916 stm32/adc: Add support for H7 MCU series.
ADC3 is used because the H7's internal ADC channels are connected to ADC3
and the uPy driver doesn't support more than one ADC.

Only 12-bit resolution is supported because 12 is hard-coded and 14/16 bits
are not recommended on some ADC3 pins (see errata).

Values from internal ADC channels are known to give wrong values at
present.
2018-05-01 15:36:11 +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
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