Commit Graph

61 Commits

Author SHA1 Message Date
Jeff Epler c6bc9c48c9
mimxrt10xx: implement i2sout
tested on metro m7 (green prototype version) with max98357a i2s amplifier and the following test code:
```py
import board
import time
import digitalio
from audiobusio import I2SOut
from audiocore import RawSample
from microcontroller import pin
from ulab import numpy as np

n = np.array(np.sin(np.linspace(0, np.pi*2, 218, endpoint=False)) * 200, dtype=np.int16)
print(n)
r = RawSample(n, sample_rate=8000, channel_count=2)
def main():
    with digitalio.DigitalInOut(board.LED) as l:
        l.switch_to_output(True)
        value = False
        while True:
            with I2SOut(pin.GPIO_06, pin.GPIO_07, pin.GPIO_04) as i:
                time.sleep(.01)
                l.value = value = not value
                i.play(r, loop=True)
                print(i.playing)
                time.sleep(.5)
                i.stop()
                print("STOPPED")
                print(i.playing)
                time.sleep(.5)
                i.play(r, loop=True)
                print(i.playing)
                print("PLAY AGAIN")
                time.sleep(.5)
            time.sleep(1)
```

Only stereo, 16-bit, raw samples were tested; the sample rate is actually fixed
at 48kHz in the core right now. There is more to do, but the basics work.

# Conflicts:
#	ports/mimxrt10xx/Makefile
#	ports/mimxrt10xx/mpconfigport.mk
2023-03-22 12:15:25 -05:00
Scott Shawcroft 9c3c0555dd
Switch iMX RT sdk to NXP repo
Fixes #7645
2023-03-21 16:21:57 -07:00
Scott Shawcroft 5bb8a7a7c6
Improve iMX RT performance
* Enable dcache for OCRAM where the VM heap lives.
* Add CIRCUITPY_SWO_TRACE for pushing program counters out over the
  SWO pin via the ITM module in the CPU. Exempt some functions from
  instrumentation to reduce traffic and allow inlining.
* Place more functions in ITCM to handle errors using code in RAM-only
  and speed up CP.
* Use SET and CLEAR registers for digitalio. The SDK does read, mask
  and write.
* Switch to 2MiB reserved for CircuitPython code. Up from 1MiB.
* Run USB interrupts during flash erase and write.
* Allow storage writes from CP if the USB drive is disabled.
* Get perf bench tests running on CircuitPython and increase timeouts
  so it works when instrumentation is active.
2023-03-14 12:30:58 -07:00
Scott Shawcroft 8a10069995
Merge pull request #7674 from jepler/m7-bootloader-reset
use right DBL_TAP_REG when resetting to bootloader
2023-03-03 13:44:22 -08:00
Jeff Epler b2a08e2cce
use right DBL_TAP_REG when resetting to bootloader
This helps my development scripts work better, and probably also fixes
a problem switching from the circuitpython environment back to arduino.
(specifically, the "1200 baud" serial trick was not rebooting into
the bootloader but was just resetting)
2023-03-03 10:09:31 -06:00
Scott Shawcroft 1acf65ee22
Fix `pwmio` on iMX RT.
It now handles deinit, never_reset and sharing tracking. PWM
now runs in the WAIT state as well during a time.sleep().

_reset_ok() was removed because it was called in one spot right
before deinit().

Some PWMOut were also switched to a bitmap for use instead of
reference count. That way init and deinit are idempotent.

Fixes #6589. Fixes #4841. Fixes #4541.
2023-02-22 11:22:39 -08:00
Dan Halbert d8231f1588 Implement safemode.py 2023-02-13 18:26:38 -05:00
Dan Halbert 8bb369cac5 refactor debug UART to console UART; get working on ESP32 2022-06-30 23:16:46 -04:00
Radomir Dopieralski c0152e7dab Remove gamepadshift module
Everything should be using the keypad module instead.

Note: there are several boards that still had gamepadshift enabled. I
did not contact their authors to make sure they already switched to
keypad in their code and documentation. We should probably wait with
merging this for their go ahead.
2022-05-25 00:48:55 +02:00
Dan Halbert 5b7e0754dd
Merge pull request #6287 from KurtE/mimxrt_pwm
Fix PWM Support for the MIMXRT boards
2022-04-25 09:02:40 -04:00
KurtE 8d9dc1fb93
Update ports/mimxrt10xx/supervisor/port.c
Co-authored-by: Dan Halbert <halbert@halwitz.org>
2022-04-22 11:47:40 -07:00
KurtE 3c343cf1b8
Update ports/mimxrt10xx/supervisor/port.c
Co-authored-by: Dan Halbert <halbert@halwitz.org>
2022-04-22 11:47:30 -07:00
KurtE 1312e5c759
Update ports/mimxrt10xx/supervisor/port.c
Co-authored-by: Dan Halbert <halbert@halwitz.org>
2022-04-22 09:16:27 -07:00
KurtE 49769cfea4 Convert to use debug rx/tx pins to trigger adding this code
As per review request
2022-04-19 14:02:16 -07:00
KurtE 02a0939d2e Fix PWM Support for the MIMXRT boards
There were two main issues with the PWM support.

The first is they would fail to work properly if the board goes
into low power mode, when you do things like:     time.sleep(0.25)
Can make partially work with this by turning on the proper flags
in each of the FlexPWMTimer Timers/sub-timers, but this did not
appear to work if for example you have both A and B channels
enabled.

Second main problem is that the code did not work with the X
channel of each timer/sub-timer.  It looks like someone had
earlier started support for this, But was not sufficient.

Needed to bypass the SDK code and get it closer to the PJRC code.

That is we set the PWM_CTRL_FULL_MASK, which then uses  base->SM[submodule].VAL1  to control
when the timer is reset, so it sets up your cycle/frequency.  But then this implies that X channel
which uses 0, 1 has to be handled specially. So for the different channels:
    A - Uses VAL2 to turn on (0) and VAL3=duty to turn off
    B - Uses VAL4 to turn on (0) and VAL5 to turn off
    X - As mentioned above VAL1 turns off, but its set to the timing for freqency. so
        VAL0 turns on, so we set it to VAL1 - duty
2022-04-16 09:00:45 -07:00
KurtE 7ff0036a26 Fix the pre-check stuff 2022-04-08 15:59:27 -07:00
KurtE 219ef5e407 disable on mimxrt10xx (Teensy40 41) Serial port Hooks
As mentioned in issue #6241  the commit to setup port hooks is now
    causing all input/output that are to go to the Mu window to also
    go to the LpUart that is defined the port serial.c

    and in this case it goes to lpuart4, which on Teensy 4, 4.1 is
    used on Arduino Serial2.  With this new code this port no longer
    works properly.

    This is one way to solve it, in that there is a #if defined() that
    if not set, all of the code in this file is ignored and the higher
    level supervisor stub versions of these functions will be used, which
    don't interfere with Serial2 and my test sketch works again.

    Note: the PR for Switch to Port Serial Hooks, also changed code in
    other ports.  I have not tried to see how.

    There are other more global fixes for this, in which maybe a higer
    level  #if that disables the code within the top level supervisor.  Or
    could be software controlled

    Again this may not be the final solution, but at least it gets
    Serial2 up and running agin.
2022-04-06 15:58:27 -07:00
Scott Shawcroft f5d90fc84f
Switch to port_serial_* hooks
This makes it easier to integrate port specific serial alongside
the common approaches.
2022-03-22 19:40:33 -07:00
Scott Shawcroft 96f5eec2ee
Add Teensy 4.1 power pin and fix SWD for DEBUG=1 2022-03-08 17:17:07 -08:00
Scott Shawcroft 83593a1558
Start of USB host API
This allows you to list and explore connected USB devices. It
only stubs out the methods to communicate to endpoints. That will
come in a follow up once TinyUSB has it. (It's in progress.)

Related to #5986
2022-03-07 18:07:25 -08:00
Jeff Epler 59cb8e91b2
mimxrt1011: enable -Werror=missing-prototypes 2021-11-12 19:30:47 -06:00
Scott Shawcroft d2860b58b0
Check background pending before sleep
There is a race between when we run background tasks and when we
sleep. If an interrupt happens between the two, then we may delay
executing the background task. On some ports we checked this for
TinyUSB already. On iMX RT, we didn't which caused USB issues.
This PR makes it more generic for all background tasks including
USB.

Fixes #5086 and maybe others.
2021-08-19 12:18:13 -07:00
Dan Halbert e9369d50e1
Merge pull request #5067 from tannewt/pulseout_switch
Switch to pin, frequency and duty_cycle PulseOut
2021-07-28 14:58:06 -04:00
Dan Halbert 901a6c27c0 remove gamepad; deprecate gamepadshift 2021-07-26 22:15:09 -04:00
Scott Shawcroft 412eb87080
Switch to pin, frequency and duty_cycle PulseOut
Passing in a PWMOut still works but is deprecated. It will be
removed in CircuitPython 8.0.0

This also switches STM32 timer indices and channel indices to
0-based in our pin data rather than `- 1` everywhere. The latter is
more bug prone.

Most of the way for #3264

Tested on Metro M0, Metro M4, Feather S2, Feather nRF52840, Feather
STM32F4 and Arduino RP2040.
2021-07-26 18:35:49 -07:00
microDev a52eb88031
run code formatting script 2021-03-15 19:27:36 +05:30
Scott Shawcroft 40118bcf57
Add `board_deinit` for use with sleep
This changes lots of files to unify `board.h` across ports. It adds
`board_deinit` when CIRCUITPY_ALARM is set. `main.c` uses it to
deinit the board before deep sleeping (even when pretending.)

Deep sleep is now a two step process for the port. First, the
port should prepare to deep sleep based on the given alarms. It
should set alarms for both deep and pretend sleep. In particular,
the pretend versions should be set immediately so that we don't
miss an alarm as we shutdown. These alarms should also wake from
`port_idle_until_interrupt` which is used when pretending to deep
sleep.

Second, when real deep sleeping, `alarm_enter_deep_sleep` is called.
The port should set any alarms it didn't during prepare based on
data it saved internally during prepare.

ESP32-S2 sleep is a bit reorganized to locate more logic with
TimeAlarm. This will help it scale to more alarm types.

Fixes #3786
2020-12-08 10:52:25 -08:00
Christian Walther c7404a3ff8 Add movable allocation system.
This allows calls to `allocate_memory()` while the VM is running, it will then allocate from the GC heap (unless there is a suitable hole among the supervisor allocations), and when the VM exits and the GC heap is freed, the allocation will be moved to the bottom of the former GC heap and transformed into a proper supervisor allocation. Existing movable allocations will also be moved to defragment the supervisor heap and ensure that the next VM run gets as much memory as possible for the GC heap.

By itself this breaks terminalio because it violates the assumption that supervisor_display_move_memory() still has access to an undisturbed heap to copy the tilegrid from. It will work in many cases, but if you're unlucky you will get garbled terminal contents after exiting from the vm run that created the display. This will be fixed in the following commit, which is separate to simplify review.
2020-11-28 17:50:23 +01:00
Scott Shawcroft 09bc415751
Unify iMX flash config and add Metro M7 1011
This unifies the flash config to the settings used by the Boot ROM.
This makes the config unique per board which allows for changing
quad enable and status bit differences per flash device. It also
allows for timing differences due to the board layout.

This change also tweaks linker layout to leave more ram space for
the CircuitPython heap.
2020-10-07 15:23:47 -07:00
Scott Shawcroft 6857f98426
Split pulseio.PWMOut into pwmio
This gives us better granularity when implementing new ports because
PWMOut is commonly implemented before PulseIn and PulseOut.

Fixes #3211
2020-08-18 13:08:33 -07:00
Jeff Epler 6160d11c5a supervisor: factor out, Handle USB via background callback 2020-07-15 11:49:44 -05:00
Diego Elio Pettenò 34b4993d63 Add license to some obvious files. 2020-07-06 19:16:25 +01:00
Jeff Epler a580f0f1c4 _pew: move to common-hal
I noticed that this code was referring to samd-specific functionality,
and isn't enabled except in one samd board (pewpew10).  Move it.

There is incomplte support for _pew in mimxrt10xx which then caused build
errors; adding a #if guard to check for _pew being enabled fixes it.
The _pew module is not likely to be important on mimxrt but I'll leave the
choice to remove it to someone else.
2020-06-22 10:45:27 -05:00
Lucian Copeland 93cffaa87e Fix pin macros typo, add extra flash protection 2020-06-05 16:43:08 -04:00
Scott Shawcroft 6400113bb9
Merge pull request #3001 from hierophect/mimxrt-teensy-boot
mimxrt10xx: Disable pin_reset on 1060 boards
2020-06-05 10:28:53 -07:00
Lucian Copeland 74effeeefd Add temporary fix warning 2020-06-04 13:30:07 -04:00
Lucian Copeland c93ccd1e91 Disable pin resets on the 1060 2020-06-03 12:07:08 -04:00
Diego Elio Pettenò dd5d7c86d2 Fix up end of file and trailing whitespace.
This can be enforced by pre-commit, but correct it separately to make it easier to review.
2020-06-03 10:56:35 +01:00
Lucian Copeland fe75c7793c Fix SWO/Analog overlap, style changes 2020-05-29 12:19:37 -04:00
Lucian Copeland fd00bb8b7f Fix pin reset flash conflict error 2020-05-28 12:15:21 -04:00
Scott Shawcroft 3c1469b0a5
Add port_fixed_stack for more builds 2020-05-15 16:22:33 -07:00
Scott Shawcroft 4519ddebeb
Merge pull request #2841 from hierophect/mimxrt-spi-oneway
mimxrt10xx: add one-directional SPI
2020-05-06 08:32:21 -07:00
Lucian Copeland bc581fbdfb Add-unidirectional-SPI 2020-05-01 13:15:38 -04:00
Scott Shawcroft 755d404edf
Merge remote-tracking branch 'adafruit/master' into lower_power 2020-04-27 16:45:10 -07:00
Scott Shawcroft bebf27e733
Merge remote-tracking branch 'adafruit/master' into lower_power
This isn't perfect and needs a bit more testing.
2020-04-20 18:25:13 -07:00
Scott Shawcroft 7e3d4c61b5
Update TinyUSB and add interrupt hooks. 2020-04-17 14:16:49 -07:00
Scott Shawcroft 6544bf52fb
Enable SNVS interrupt
The iMX RT has a separate wake up controller, the GPC, that replaces
the NVIC when asleep. It adds the ability to only wake up on certain
interrupts. It seems that it requires at least one enabled interrupt
in the NVIC to turn on it's wake up circuitry. It doesn't need to
be the same interrupt as the wake up signal. For example, the RTC
in the SNVS can wake us up if a USB interrupt is enabled. Before
then it won't work. So, we enable the SNVS interrupt on start up
so it can wake us up.
2020-04-07 17:15:18 -07:00
Scott Shawcroft aae0ce6bad
Fix autoreload and ticks on IMX RT 2020-04-07 14:16:07 -07:00
Scott Shawcroft a8dfba235c
Fix alarm so that it is correctly set. 2020-04-07 13:07:29 -07:00
Lucian Copeland 47a5d83267 Implement F7 Nucleo 2020-04-02 11:47:16 -04:00