Wykres commitów

46 Commity (master)

Autor SHA1 Wiadomość Data
Angus Gratton 7fd8a6d4bc stm32/dma: Add D-cache protection for DMA RX operations, including SPI.
This new DMA API corrects possible cache coherency issues on chips with
D-Cache, when working with buffers at arbitrary memory locations (i.e.
supplied by Python code).

The API is used by SPI to fix an issue with corrupt data when reading from
SPI using DMA in certain cases.  A regression test is included (it depends
on external hardware connection).

Explanation:

1) It's necessary to invalidate D-Cache after a DMA RX operation completes
   in case the CPU reads (or speculatively reads) from the DMA RX region
   during the operation.  This seems to have been the root cause of issue
   #13471 (only when src==dest for this case).

2) More generally, it is also necessary to temporarily mark the first and
   last cache lines of a DMA RX operation as "uncached", in case the DMA
   buffer shares this cache line with unrelated data.  The CPU could
   otherwise write the other data at any time during the DMA operation (for
   example from an interrupt handler), creating a dirty cache line that's
   inconsistent with the DMA result.

Fixes issue #13471.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-03-08 12:19:48 +11:00
Angus Gratton decf8e6a8b all: Remove the "STATIC" macro and just use "static" instead.
The STATIC macro was introduced a very long time ago in commit
d5df6cd44a.  The original reason for this was
to have the option to define it to nothing so that all static functions
become global functions and therefore visible to certain debug tools, so
one could do function size comparison and other things.

This STATIC feature is rarely (if ever) used.  And with the use of LTO and
heavy inline optimisation, analysing the size of individual functions when
they are not static is not a good representation of the size of code when
fully optimised.

So the macro does not have much use and it's simpler to just remove it.
Then you know exactly what it's doing.  For example, newcomers don't have
to learn what the STATIC macro is and why it exists.  Reading the code is
also less "loud" with a lowercase static.

One other minor point in favour of removing it, is that it stops bugs with
`STATIC inline`, which should always be `static inline`.

Methodology for this commit was:

1) git ls-files | egrep '\.[ch]$' | \
   xargs sed -Ei "s/(^| )STATIC($| )/\1static\2/"

2) Do some manual cleanup in the diff by searching for the word STATIC in
   comments and changing those back.

3) "git-grep STATIC docs/", manually fixed those cases.

4) "rg -t python STATIC", manually fixed codegen lines that used STATIC.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-03-07 14:20:42 +11:00
Damien George 4e6436d4cf stm32/spi: Allow disabling MICROPY_PY_MACHINE_SPI.
This requires that MICROPY_PY_PYB is also disabled.

Signed-off-by: Damien George <damien@micropython.org>
2024-02-07 13:45:51 +11:00
iabdalkader cfcd0c4022 stm32: Add missing header include for debug builds.
Debug build fails if string.h header is not included.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2023-11-28 23:32:52 +11:00
Jim Mussared b4236c7368 stm32: Rename pin_obj_t to machine_pin_obj_t.
This is now consistent with other ports.

Also renamed `pin_{board/cpu}_pins_locals_dict` to
`machine_pin_{board/cpu}_pins_locals_dict`.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-11-03 14:09:08 +11:00
Damien George 3e2706a18d extmod/modmachine: Consolidate mem, i2c and spi headers to modmachine.h.
The contents of machine_mem.h, machine_i2c.h and machine_spi.h have been
moved into extmod/modmachine.h.

Signed-off-by: Damien George <damien@micropython.org>
2023-10-26 17:40:22 +11:00
Damien George 90023b4dcf extmod/modmachine: Clean up decls of machine types to use common ones.
The machine_i2c_type, machine_spi_type and machine_timer_type symbols are
already declared in extmod/modmachine.h and should not be declared anywhere
else.

Also move declarations of machine_pin_type and machine_rtc_type to the
common header in extmod.

Signed-off-by: Damien George <damien@micropython.org>
2023-10-26 16:20:53 +11:00
Angus Gratton e6cfb77342 stm32/spi: Add STM32WL5 SUBGHZ SPI peripheral.
This is a "normal" SPI peripheral with no external pins, to avoid having to
grow spi_obj[] for just this one board map it as SPI ID 3 (board has SPI
IDs 1,2 already).

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2023-08-23 11:58:08 +10:00
Damien George 61339aa506 stm32: Add initial support for H5 MCUs.
This commit adds initial support for STM32H5xx MCUs.  The following
features have been confirmed to be working on an STM32H573:
- UART over REPL and USB CDC
- USB CDC and MSC
- internal flash filesystem
- machine.Pin
- machine.SPI transfers with DMA
- machine.ADC
- machine.RTC
- pyb.LED
- pyb.Switch
- pyb.rng
- mboot

Signed-off-by: Damien George <damien@micropython.org>
2023-06-15 11:09:20 +10:00
Damien George 6c8b19c7e2 stm32/spi: Return error code and raise exception if SPI init fails.
Signed-off-by: Damien George <damien@micropython.org>
2023-03-09 12:47:45 +11:00
Angus Gratton b3e38ac632 stm32/spi: Downgrade SPIHandle definitions to static.
Seems unused outside of spi.c, spi_obj[] array is the expected way to
iterate these.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2022-11-11 13:23:24 +11:00
iabdalkader af4ba6d1b4 stm32: Rename machine I2C and SPI types consistently across ports.
This renames:
- machine_hard_i2c_type -> machine_i2c_type
- machine_hard_spi_type -> machine_spi_type
2022-10-22 12:54:42 +11:00
robert-hh 54eaa8c8a6 stm32/mphalport: Add mp_hal_get_spi_obj() helper function.
The function spi_from_mp_obj() is kept since it is used by the cc3k driver.
2022-08-23 14:59:48 +10:00
Asensio Lorenzo Sempere 010012c7c3 stm32: Add support for G0 MCUs.
This commit adds support for the STM32G0 series of MCUs.

Signed-off-by: Asensio Lorenzo Sempere <asensio.aerospace@gmail.com>
2022-04-28 11:56:15 +10:00
David P f365025c9c stm32: Replace master/slave with controller/peripheral in I2C and SPI.
Replace "master" with "controller" and "slave" with "peripheral" in
comments, errors, and debug messages.

Add CONTROLLER and PERIPHERAL constants to pyb.SPI and pyb.I2C classes;
retain MASTER and SLAVE constants for backward compatiblity.
2021-07-18 11:23:41 +10:00
Mike Causer 47b778332a all: Replace busses with buses.
"buses" is the widely accepted plural form of "bus".
2021-05-20 23:22:03 +10:00
Reinhard Feger 79c186f5c9 stm32/spi: Fix baudrate calculation for H7 series.
Fixes issue #6342.
2021-03-11 01:06:52 +11:00
Damien George 1e4e2644ec stm32: Add support for a board to reserve certain peripherals.
Allows reserving CAN, I2C, SPI, Timer and UART peripherals.  If reserved
the peripheral cannot be accessed from Python.

Signed-off-by: Damien George <damien@micropython.org>
2020-12-07 17:22:08 +11:00
Jim Mussared def76fe4d9 all: Use MP_ERROR_TEXT for all error messages. 2020-04-05 15:02:06 +10:00
Damien George 69661f3343 all: Reformat C and Python source code with tools/codeformat.py.
This is run with uncrustify 0.70.1, and black 19.10b0.
2020-02-28 10:33:03 +11:00
Damien George ad7213d3c3 py: Add mp_raise_msg_varg helper and use it where appropriate.
This commit adds mp_raise_msg_varg(type, fmt, ...) as a helper for
nlr_raise(mp_obj_new_exception_msg_varg(type, fmt, ...)).  It makes the
C-level API for raising exceptions more consistent, and reduces code size
on most ports:

   bare-arm:   +28 +0.042%
minimal x86:  +100 +0.067%
   unix x64:   -56 -0.011%
unix nanbox:  -300 -0.068%
      stm32:  -204 -0.054% PYBV10
     cc3200:    +0 +0.000%
    esp8266:   -64 -0.010% GENERIC
      esp32:  -104 -0.007% GENERIC
        nrf:  -136 -0.094% pca10040
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
2020-02-13 11:52:40 +11:00
Damien George 14bec7964f stm32/spi: Factor out code to calculate SPI source frequency. 2019-07-03 12:02:46 +10:00
iabdalkader 07af74daef stm32/spi: Enable SPI IRQs and add IRQHandlers for H7 MCUs.
The H7 HAL uses SPI IRQs when the SPI is running in DMA mode.
2019-05-15 15:59:25 +10:00
Damien George 6e30f96b0b ports: Convert legacy uppercase macro names to lowercase. 2019-02-12 14:54:51 +11:00
boochow 9d3372bded stm32: Add peripheral support for STM32L432.
The L432 does not have: GPIOD, TIM3, SPI2, ADC dual mode operation, 2-banks
flash.
2018-12-06 13:32:43 +11:00
iabdalkader f0db1a5ab1 stm32/spi: Fix calculation of SPI clock source on H7 MCUs. 2018-10-17 15:26:26 +11:00
Damien George 6f015d337d stm32/spi: Be sure to set all SPI config values in SPI proto init. 2018-09-11 17:36:11 +10:00
Damien George b0c8a94b41 stm32/dma: Pass DMA direction as parameter to dma_init not in cfg struct
Some DMA channels (eg for SDIO) can be used in both directions and this
patch allows such peripherals to dynamically select the DMA direction.
2018-09-11 17:18:06 +10:00
Damien George 056e0b6293 stm32/spi: Add implementation of low-level SPI protocol.
Can be used, for example, to configure external SPI flash using a hardware
SPI interface (code to be put in a board's bdev.c file):

    STATIC const spi_proto_cfg_t hard_spi_bus = {
        .spi = &spi_obj[5],
        .baudrate = 10000000,
        .polarity = 0,
        .phase = 0,
        .bits = 8,
        .firstbit = SPI_FIRSTBIT_MSB,
    };

    STATIC mp_spiflash_cache_t spi_bdev_cache;

    const mp_spiflash_config_t spiflash_config = {
        .bus_kind = MP_SPIFLASH_BUS_SPI,
        .bus.u_spi.cs = pin_A0,
        .bus.u_spi.data = (void*)&hard_spi_bus,
        .bus.u_spi.proto = &spi_proto,
        .cache = &spi_bdev_cache,
    };

    spi_bdev_t spi_bdev;
2018-08-14 22:10:43 +10:00
Damien George 8300be6d0f stm32/spi: Split out pyb.SPI and machine.SPI bindings to their own files
The aim here is to have spi.c contain the low-level SPI driver which is
independent (not fully but close) of MicroPython objects and methods, and
the higher-level bindings are separated out to pyb_spi.c and machine_spi.c.
2018-08-14 17:11:07 +10:00
Damien George 86e0b25532 stm32/spi: Round up prescaler calc to never exceed requested baudrate.
Requesting a baudrate of X should never configure the peripheral to have a
baudrate greater than X because connected hardware may not be able to
handle higher speeds.  This patch makes sure to round the prescaler up so
that the actual baudrate is rounded down.
2018-08-10 16:39:47 +10:00
Damien George e1ae9939ac stm32: Support compiling with object representation D.
With this and previous patches the stm32 port can now be compiled using
object representation D (nan boxing).  Note that native code and frozen mpy
files with float constants are currently not supported with this object
representation.
2018-07-08 23:25:11 +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 ea7e747979 stm32: Add support for STM32F0 MCUs. 2018-05-28 21:49:49 +10: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
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 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 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 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 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 762db9ad2f stm32/spi: Add support for a board naming SPI peripherals 4, 5 and 6. 2018-02-02 17:44:05 +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
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 a3dc1b1957 all: Remove inclusion of internal py header files.
Header files that are considered internal to the py core and should not
normally be included directly are:
    py/nlr.h - internal nlr configuration and declarations
    py/bc0.h - contains bytecode macro definitions
    py/runtime0.h - contains basic runtime enums

Instead, the top-level header files to include are one of:
    py/obj.h - includes runtime0.h and defines everything to use the
        mp_obj_t type
    py/runtime.h - includes mpstate.h and hence nlr.h, obj.h, runtime0.h,
        and defines everything to use the general runtime support functions

Additional, specific headers (eg py/objlist.h) can be included if needed.
2017-10-04 12:37:50 +11:00
Damien George 01dd7804b8 ports: Make new ports/ sub-directory and move all ports there.
This is to keep the top-level directory clean, to make it clear what is
core and what is a port, and to allow the repository to grow with new ports
in a sustainable way.
2017-09-06 13:40:51 +10:00