Wykres commitów

25 Commity (master)

Autor SHA1 Wiadomość Data
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 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
Damien George 5b4a2baff6 extmod/machine_uart: Factor ports' UART Python bindings to common code.
This is a code factoring to have the Python bindings in one location, and
all the ports use those same bindings.  For all ports except the two listed
below there is no functional change.

The nrf port has UART.sendbreak() removed, but this method previously did
nothing.

The zephyr port has the following methods added:
- UART.init(): supports setting timeout and timeout_char.
- UART.deinit(): does nothing, just returns None.
- UART.flush(): raises OSError(EINVAL) because it's not implemented.
- UART.any() and UART.txdone(): raise NotImplementedError.

Signed-off-by: Damien George <damien@micropython.org>
2023-10-26 10:46:42 +11:00
robert-hh 0701341e7f mimxrt/machine_uart: Set the UART clock to a fixed 40MHz value.
There is a single UART clock for all devices, so switching it for one will
affect all devices used at that time.  This commit fixes that issue by
keeping the clock at a fixed value.

This fixed clock still supports the common baud rates between 300 and
921600 baud.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-09-29 23:43:25 +10:00
robert-hh 297892c4f4 mimxrt/machine_uart: Add a helper function to change the baudrate.
And use it in the Bluetooth bindings instead of setting the baudrate by a
call to the NXP lib.

Also fixes machine_uart.c to work with a baud rate of 921600.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-09-05 10:54:49 +10:00
robert-hh 81c19d93bc mimxrt/machine_uart: Support slow baud rates for UART.
Down to 50 baud (in reverence to Jean-Maurice-Émile Baudot).  Implemented
for the MIMXRT10xx MCU's only.  The MIMXRT1176 runs down to 300 baud.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-09-01 00:41:23 +10:00
robert-hh ce38784fa8 mimxrt/machine_uart: Fix and complete UART.deinit and uart_deinit_all.
The code did not check at deinit whether a UART was initialized.  That did
not matter for all MCU's except MIMXRT1176, which crashes at the second
soft reset in a row.

But since it is a general problem to use UART methods of a UART which has
been deinitialized, checks were added to all applicable methods for a clear
response instead of e.g. a crash.

Deinitialize UART using software reset.  It resets the UART but keeps it
accessible for software, avoiding an exception when UART registers are
accessed after a DeInit.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-09-01 00:27:13 +10:00
Kwabena W. Agyeman afe2ca1a0a mimxrt/machine_uart: Add support for UART hardware flow control.
Signed-off-by: "Kwabena W. Agyeman" <kwagyeman@live.com>
2023-08-15 23:21:33 +10:00
robert-hh e43c669b4a mimxrt/machine_uart: Add uart.deinit method and machine_uart_deinit_all.
The call to machine_uart_deinit_all() is needed to avoid a crash after soft
reset, if a UART had been used and data arrives before it is instantiated
again.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-08-15 23:08:30 +10:00
robert-hh 5e990cc27f mimxrt: Add support for MIMXRT1176 MCUs, and MIMXRT1170_EVK board.
The RT1176 has two cores, but the actual firmware supports only the CM7.
There are currently no good plans on how to use the CM4.

The actual MIMXRT1170_EVK board is on par with the existing MIMXRT boards,
with the following extensions:
- Use 64 MB RAM for the heap.
- Support both LAN interfaces as LAN(0) and LAN(1), with LAN(1)
  being the 1GB interface.

The dual LAN port interface can eventually be adapted as well for the
RT1062 MCU.

This work was done in collaboration with @alphaFred.
2022-11-17 14:11:50 +11:00
Jim Mussared 94beeabd2e py/obj: Convert make_new into a mp_obj_type_t slot.
Instead of being an explicit field, it's now a slot like all the other
methods.

This is a marginal code size improvement because most types have a make_new
(100/138 on PYBV11), however it improves consistency in how types are
declared, removing the special case for make_new.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-19 19:06:15 +10:00
Jim Mussared 6da41b5900 py/obj: Merge getiter and iternext mp_obj_type_t slots.
The goal here is to remove a slot (making way to turn make_new into a slot)
as well as reduce code size by the ~40 references to mp_identity_getiter
and mp_stream_unbuffered_iter.

This introduces two new type flags:
- MP_TYPE_FLAG_ITER_IS_ITERNEXT: This means that the "iter" slot in the
  type is "iternext", and should use the identity getiter.
- MP_TYPE_FLAG_ITER_IS_CUSTOM: This means that the "iter" slot is a pointer
  to a mp_getiter_iternext_custom_t instance, which then defines both
  getiter and iternext.

And a third flag that is the OR of both, MP_TYPE_FLAG_ITER_IS_STREAM: This
means that the type should use the identity getiter, and
mp_stream_unbuffered_iter as iternext.

Finally, MP_TYPE_FLAG_ITER_IS_GETITER is defined as a no-op flag to give
the default case where "iter" is "getiter".

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-19 19:06:13 +10:00
Jim Mussared 9dce82776d all: Remove unnecessary locals_dict cast.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-19 19:06:01 +10:00
Jim Mussared 662b9761b3 all: Make all mp_obj_type_t defs use MP_DEFINE_CONST_OBJ_TYPE.
In preparation for upcoming rework of mp_obj_type_t layout.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-19 19:06:01 +10:00
robert-hh 6472348c1b mimxrt/machine_uart: Fix a bug in UART.write().
Causing an incomplete send if the data size was longer than the buffer
size.
2022-09-13 18:35:48 +10:00
robert-hh 443fbcf81c mimxrt/machine_uart: Set the UART ioctl write poll flag properly.
It was always set to True.  The change adds a check to the tx status flag
which is set when all data is transferred.
2022-09-13 18:35:48 +10:00
robert-hh 65ce7d7ade mimxrt/machine_uart: Drop a few commented lines about TX ring buffer. 2022-09-13 18:35:48 +10:00
robert-hh 49e17c8bb0 mimxrt/machine_uart: Implement uart.flush() and uart.txdone().
uart.flush()

flush() will wait until all characters have been sent.To avoid a
permanent lock, a timeout applies depending on the size of txbuf
and the baud rate.

ret = uart.txdone()

ret is True if no transfer is in progress.
ret is False otherwise.
2022-08-31 00:18:21 +10:00
robert-hh 5cc2dd4f5d mimxrt/machine_uart: Fix an inconsistency for UART.init() arg handling.
With keyword arguments only or just a single non-keyword argument,
UART.init() did not perform the settings.
2022-06-07 18:21:46 +10:00
robert-hh a0432ed9cb mimxrt: Update port to work with new nxp_driver v2.10.
The nxp_driver v2.10 allows for/requires some changes to the code:

- Remove some part of pwm_backlog.*, which is provided by the lib now.
- Change eth.c: the newer versions have additional parameters of the
  library versions.
- Change sdcard.c: use TransferBlocking instead of TransferNonblocking.
- Add some support for the MIMXRT1176 device.
- Set the clocks for UART, I2C, Timer.
- Integrate the I2S module and fix a rebase error.
- Use blocking transfer only for SPI.  It's faster and interferes less with
  other modules.
- Use the clock_config.c files of library v2.8.5.  The mimxrt files keeps
  the clock_config.c files from Verson 2.8.5.  With clock_config.c from
  v2.10, the boards do not work.  Refactoring of the clock set-up is on the
  to-do list.
- Enable expiry timers for UART, I2C and SPI, avoiding a stall in library
  code.
- The clock_config.* files are moved from the board-specific directories to
  the boards directory and given a MCU related name.
2022-06-03 10:48:49 +10:00
Jim Mussared 0e7bfc88c6 all: Use mp_obj_malloc everywhere it's applicable.
This replaces occurences of

    foo_t *foo = m_new_obj(foo_t);
    foo->base.type = &foo_type;

with

    foo_t *foo = mp_obj_malloc(foo_t, &foo_type);

Excludes any places where base is a sub-field or when new0/memset is used.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-05-03 22:28:14 +10:00
Philipp Ebensberger 62cb2069bb mimxrt/machine_pin: Change pin drive constants to DRIVE_x naming.
Updated DRIVE_x constants representing pin drive strength.

Signed-off-by: Philipp Ebensberger
2022-03-08 22:30:33 +11:00
robert-hh 1dc366f901 mimxrt: Replace Pin-config constants by a function call.
The Pin config setting by IOMUXC_SetPinConfig() is supplied by a
bit pattern. That pattern is specific for a MCU family. In preparation
for supporting the MIMXRT117x family, the constant bit pattern is
replaced by a function call, such that the bit pattern is created
at a single place. The code for this functions was taken from
machine_pin.c.

Note: A working port for the MIMXRT1176 exists already.
2022-01-27 16:53:30 +11:00
robert-hh bc1b0fd2c1 mimxrt: Define UART 0 on MIMXRT boards.
UART 0 is attached to the Debug USB port. The settings are
115200 Baud, 8N1.
For MIMXRT1010_EVK this is identical to UART1. For the other boards,
this is an additional UART.
2021-12-14 08:07:52 +01:00
robert-hh 689476c576 mimxrt/machine_uart: Add the UART class to the machine module.
The implementation uses the LPUARTx devices.  Up to 8 UARTs can be used,
given that the pins are accessible.  E.g. 8 on Teensy 4.1, 5 on
MIMXRT1020_EVK.

For Tennsy 4.0 and 4.1 the UART numbers are as printed on the pinout 1..N.
The MIMXRT10xx-EVK boards have only one UART named, which gets the number
1.  All other UART are assigned to different Pins:

MIMXRT1010-EVK:
    D0/D1   UART 1
    D6/D7   UART 2
    A0/D4   UART 3

MIMXRT1020-EVK:
    D0/D1   UART 1
    D6/D9   UART 2
    D10/D12 UART 3
    D14/D15 UART 4
    A0/A1   UART 5

MIMXRT1050-EVK, MIMXRT1060-EVK, MIMXRT1064-EVK:
    D0/D1   UART 1
    D7/D6   UART 2
    D8/D9   UART 3
    A1/A0   UART 4
2021-06-16 01:21:15 +10:00