diff --git a/.github/workflows/ports_psoc6.yml b/.github/workflows/ports_psoc6.yml index ba92db3ca3bc..f71e7a2a2fe9 100644 --- a/.github/workflows/ports_psoc6.yml +++ b/.github/workflows/ports_psoc6.yml @@ -70,8 +70,9 @@ jobs: source tools/ci.sh && ci_psoc6_flash_multiple_devices ${{ matrix.board }} firmware.hex tools/psoc6/${{ runner.name }}-devs.yml - name: Run psoc6 tests timeout-minutes: 12 - run: | - ./tests/ports/psoc6/run_psoc6_tests.sh --test-suite ci-tests --board ${{ matrix.board }} --hil ${{ runner.name }} + run: | + ./tests/ports/psoc6/run_psoc6_tests.sh --test-suite pdm_pcm --board ${{ matrix.board }} --hil ${{ runner.name }} +#./tests/ports/psoc6/run_psoc6_tests.sh --test-suite ci-tests --board ${{ matrix.board }} --hil ${{ runner.name }} - name: Container teardown if: failure() || success() run: | diff --git a/tests/ports/psoc6/board_ext_hw/multi/pdm_pcm.py b/tests/ports/psoc6/board_ext_hw/multi/pdm_pcm.py deleted file mode 100644 index 2ea0ba90444e..000000000000 --- a/tests/ports/psoc6/board_ext_hw/multi/pdm_pcm.py +++ /dev/null @@ -1,67 +0,0 @@ -import os -from machine import PDM_PCM, Pin -import machine - -# Allocate pin based on board -board = os.uname().machine -if "CY8CPROTO-062-4343W" in board: - clk_pin = "P10_4" - data_pin = "P10_5" - send_signal_to_tx_pin = "P10_0" - -elif "CY8CPROTO-063-BLE" in board: - print("SKIP") - raise SystemExit -elif "CY8CKIT-062S2-AI" in board: - clk_pin = "P10_4" - data_pin = "P10_5" - - -def generate_exp_seq(data): - exp_seq = bytearray(data * 64) - return exp_seq - - -# Test Case 1: Blocking mode -_sampling_rate = [8000, 16000, 32000, 48000, 22050, 44100] -_mode = [PDM_PCM.MONO_LEFT, PDM_PCM.MONO_RIGHT, PDM_PCM.STEREO] -_bits = 16 -exp_data = [[0xFF]] -iterations = 100 -exp_seq = generate_exp_seq([0x00]) - -for i in range(len(_sampling_rate)): # Check for all sampling rates - set_sampling_rate = _sampling_rate[i] - if _sampling_rate[i] == 22050 or _sampling_rate[i] == 44100: - machine.freq(machine.AUDIO_PDM_22_579_000_HZ) - else: - machine.freq(machine.AUDIO_PDM_24_576_000_HZ) - for j in range(len(_mode)): # Check for all modes - set_mode = _mode[j] - if set_mode == PDM_PCM.STEREO: - iterations = 200 - pdm_pcm = PDM_PCM( - 0, - sck=clk_pin, - data=data_pin, - sample_rate=set_sampling_rate, - decimation_rate=64, - bits=PDM_PCM.BITS_16, - format=set_mode, - left_gain=0, - right_gain=0, - ) - pdm_pcm.init() # Start - - for k in range(iterations): - rx_buf = bytearray([0] * 64) - num_read = pdm_pcm.readinto(rx_buf) - # print("buf :", ''.join(f'{x:02x} ' for x in rx_buf)) - if rx_buf[:3] == bytearray([exp_data[0][0], exp_data[0][0], exp_data[0][0]]): - is_seq_received = rx_buf == exp_seq - if is_seq_received: - print( - f"data high received for mode = {set_mode}, bits = PDM_PCM.BITS_16, rate = {set_sampling_rate} : {is_seq_received}" - ) - break - pdm_pcm.deinit() diff --git a/tests/ports/psoc6/board_ext_hw/multi/pdm_pcm.py.exp b/tests/ports/psoc6/board_ext_hw/multi/pdm_pcm.py.exp deleted file mode 100644 index d584ab99ac3b..000000000000 --- a/tests/ports/psoc6/board_ext_hw/multi/pdm_pcm.py.exp +++ /dev/null @@ -1,18 +0,0 @@ -data high received for mode = 0, bits = PDM_PCM.BITS_16, rate = 8000 : True -data high received for mode = 1, bits = PDM_PCM.BITS_16, rate = 8000 : True -data high received for mode = 2, bits = PDM_PCM.BITS_16, rate = 8000 : True -data high received for mode = 0, bits = PDM_PCM.BITS_16, rate = 16000 : True -data high received for mode = 1, bits = PDM_PCM.BITS_16, rate = 16000 : True -data high received for mode = 2, bits = PDM_PCM.BITS_16, rate = 16000 : True -data high received for mode = 0, bits = PDM_PCM.BITS_16, rate = 32000 : True -data high received for mode = 1, bits = PDM_PCM.BITS_16, rate = 32000 : True -data high received for mode = 2, bits = PDM_PCM.BITS_16, rate = 32000 : True -data high received for mode = 0, bits = PDM_PCM.BITS_16, rate = 48000 : True -data high received for mode = 1, bits = PDM_PCM.BITS_16, rate = 48000 : True -data high received for mode = 2, bits = PDM_PCM.BITS_16, rate = 48000 : True -data high received for mode = 0, bits = PDM_PCM.BITS_16, rate = 22050 : True -data high received for mode = 1, bits = PDM_PCM.BITS_16, rate = 22050 : True -data high received for mode = 2, bits = PDM_PCM.BITS_16, rate = 22050 : True -data high received for mode = 0, bits = PDM_PCM.BITS_16, rate = 44100 : True -data high received for mode = 1, bits = PDM_PCM.BITS_16, rate = 44100 : True -data high received for mode = 2, bits = PDM_PCM.BITS_16, rate = 44100 : True diff --git a/tests/ports/psoc6/board_ext_hw/multi/pdm_pcm_gen.py b/tests/ports/psoc6/board_ext_hw/multi/pdm_pcm_gen.py deleted file mode 100644 index 61fa3bb067da..000000000000 --- a/tests/ports/psoc6/board_ext_hw/multi/pdm_pcm_gen.py +++ /dev/null @@ -1,22 +0,0 @@ -import os -from machine import Pin - -# Allocate pin based on board -board = os.uname().machine -if "CY8CPROTO-062-4343W" in board: - clk_pin = "P10_4" - data_pin = "P10_5" -elif "CY8CPROTO-063-BLE" in board: - print("SKIP") - raise SystemExit -elif "CY8CKIT-062S2-AI" in board: - clk_pin = "P10_4" - data_pin = "P10_5" - -start_time = time.time() - -data_out = Pin("P13_7", mode=Pin.OUT, value=False) -clk_in = Pin("P13_6", Pin.IN, Pin.PULL_DOWN) - -while time.time() - start_time < 10: # Wait for 5 second - data_out.low() diff --git a/tests/ports/psoc6/board_ext_hw/multi/pdm_pcm_rx.py b/tests/ports/psoc6/board_ext_hw/multi/pdm_pcm_rx.py new file mode 100644 index 000000000000..d4f4a5f48dc3 --- /dev/null +++ b/tests/ports/psoc6/board_ext_hw/multi/pdm_pcm_rx.py @@ -0,0 +1,122 @@ +import os +from machine import PDM_PCM, Pin +import machine +import time + +# Allocate pin based on board +board = os.uname().machine +if "CY8CPROTO-062-4343W" in board: + clk_pin = "P10_4" + data_pin = "P10_5" + send_signal_to_tx_pin = "P10_3" + +elif "CY8CPROTO-063-BLE" in board: + print("SKIP") + raise SystemExit +elif "CY8CKIT-062S2-AI" in board: + clk_pin = "P10_4" + data_pin = "P10_5" + + +def generate_exp_seq(data): + exp_seq = bytearray(data * 64) + return exp_seq + + +send_signal = Pin(send_signal_to_tx_pin, mode=Pin.OUT, pull=Pin.PULL_DOWN, value=False) +send_signal.value(0) + +print("1. blocking read implementation ") + +_sampling_rate = [8000, 16000, 32000, 48000, 22050, 44100] +_mode = [PDM_PCM.MONO_LEFT, PDM_PCM.MONO_RIGHT, PDM_PCM.STEREO] +_bits = 16 +exp_data = [[0x00], [0xFF]] +iterations = 100 +rounds = 2 + +for m in range(rounds): + exp_seq = generate_exp_seq(exp_data[m]) + if m == 0: + print("*** Test for data high ***") + else: + print("*** Test for data low ***") + + for i in range(len(_sampling_rate)): # Check for all sampling rates + set_sampling_rate = _sampling_rate[i] + if _sampling_rate[i] == 22050 or _sampling_rate[i] == 44100: + machine.freq(machine.AUDIO_PDM_22_579_000_HZ) + else: + machine.freq(machine.AUDIO_PDM_24_576_000_HZ) + for j in range(len(_mode)): # Check for all modes + set_mode = _mode[j] + if set_mode == PDM_PCM.STEREO: + iterations = 200 + pdm_pcm = PDM_PCM( + 0, + sck=clk_pin, + data=data_pin, + sample_rate=set_sampling_rate, + decimation_rate=64, + bits=PDM_PCM.BITS_16, + format=set_mode, + left_gain=0, + right_gain=0, + ) + pdm_pcm.init() # Start + + for k in range(iterations): + rx_buf = bytearray([1] * 64) + num_read = pdm_pcm.readinto(rx_buf) + # print("buf :", ''.join(f'{x:02x} ' for x in rx_buf)) + if rx_buf[:3] == bytearray([exp_data[m][0], exp_data[m][0], exp_data[m][0]]): + is_seq_received = rx_buf == exp_seq + if is_seq_received: + print( + f"data received for mode = {set_mode}, bits = PDM_PCM.BITS_16, rate = {set_sampling_rate} : {is_seq_received}" + ) + break + pdm_pcm.deinit() + send_signal.high() + time.sleep(1) # Wait to sync + +send_signal.deinit() + +############################################################################### +print("\n2. irq non-blocking read implementation ") + +rx_done = False + + +def rx_complete_irq(obj): + global rx_done + rx_done = True + + +machine.freq(machine.AUDIO_PDM_24_576_000_HZ) +pdm_pcm = PDM_PCM( + 0, + sck=clk_pin, + data=data_pin, + sample_rate=set_sampling_rate, + decimation_rate=64, + bits=PDM_PCM.BITS_16, + format=set_mode, + left_gain=0, + right_gain=0, +) + +pdm_pcm.init() # Start + +rx_buf = bytearray([0] * 64) +pdm_pcm.irq(rx_complete_irq) +num_read = pdm_pcm.readinto(rx_buf) + +while not rx_done: + pass + +# if we get pass this rx_done flag has been +# modified by the interrupt + +print("rx blocking done") +pdm_pcm.deinit() diff --git a/tests/ports/psoc6/board_ext_hw/multi/pdm_pcm_rx.py.exp b/tests/ports/psoc6/board_ext_hw/multi/pdm_pcm_rx.py.exp new file mode 100644 index 000000000000..07bbe9346779 --- /dev/null +++ b/tests/ports/psoc6/board_ext_hw/multi/pdm_pcm_rx.py.exp @@ -0,0 +1,42 @@ +1. blocking read implementation +*** Test for data high *** +data received for mode = 0, bits = PDM_PCM.BITS_16, rate = 8000 : True +data received for mode = 1, bits = PDM_PCM.BITS_16, rate = 8000 : True +data received for mode = 2, bits = PDM_PCM.BITS_16, rate = 8000 : True +data received for mode = 0, bits = PDM_PCM.BITS_16, rate = 16000 : True +data received for mode = 1, bits = PDM_PCM.BITS_16, rate = 16000 : True +data received for mode = 2, bits = PDM_PCM.BITS_16, rate = 16000 : True +data received for mode = 0, bits = PDM_PCM.BITS_16, rate = 32000 : True +data received for mode = 1, bits = PDM_PCM.BITS_16, rate = 32000 : True +data received for mode = 2, bits = PDM_PCM.BITS_16, rate = 32000 : True +data received for mode = 0, bits = PDM_PCM.BITS_16, rate = 48000 : True +data received for mode = 1, bits = PDM_PCM.BITS_16, rate = 48000 : True +data received for mode = 2, bits = PDM_PCM.BITS_16, rate = 48000 : True +data received for mode = 0, bits = PDM_PCM.BITS_16, rate = 22050 : True +data received for mode = 1, bits = PDM_PCM.BITS_16, rate = 22050 : True +data received for mode = 2, bits = PDM_PCM.BITS_16, rate = 22050 : True +data received for mode = 0, bits = PDM_PCM.BITS_16, rate = 44100 : True +data received for mode = 1, bits = PDM_PCM.BITS_16, rate = 44100 : True +data received for mode = 2, bits = PDM_PCM.BITS_16, rate = 44100 : True +*** Test for data low *** +data received for mode = 0, bits = PDM_PCM.BITS_16, rate = 8000 : True +data received for mode = 1, bits = PDM_PCM.BITS_16, rate = 8000 : True +data received for mode = 2, bits = PDM_PCM.BITS_16, rate = 8000 : True +data received for mode = 0, bits = PDM_PCM.BITS_16, rate = 16000 : True +data received for mode = 1, bits = PDM_PCM.BITS_16, rate = 16000 : True +data received for mode = 2, bits = PDM_PCM.BITS_16, rate = 16000 : True +data received for mode = 0, bits = PDM_PCM.BITS_16, rate = 32000 : True +data received for mode = 1, bits = PDM_PCM.BITS_16, rate = 32000 : True +data received for mode = 2, bits = PDM_PCM.BITS_16, rate = 32000 : True +data received for mode = 0, bits = PDM_PCM.BITS_16, rate = 48000 : True +data received for mode = 1, bits = PDM_PCM.BITS_16, rate = 48000 : True +data received for mode = 2, bits = PDM_PCM.BITS_16, rate = 48000 : True +data received for mode = 0, bits = PDM_PCM.BITS_16, rate = 22050 : True +data received for mode = 1, bits = PDM_PCM.BITS_16, rate = 22050 : True +data received for mode = 2, bits = PDM_PCM.BITS_16, rate = 22050 : True +data received for mode = 0, bits = PDM_PCM.BITS_16, rate = 44100 : True +data received for mode = 1, bits = PDM_PCM.BITS_16, rate = 44100 : True +data received for mode = 2, bits = PDM_PCM.BITS_16, rate = 44100 : True + +2. irq non-blocking read implementation +rx blocking done diff --git a/tests/ports/psoc6/board_ext_hw/multi/pdm_pcm_tx.py b/tests/ports/psoc6/board_ext_hw/multi/pdm_pcm_tx.py new file mode 100644 index 000000000000..58fedd57f5a1 --- /dev/null +++ b/tests/ports/psoc6/board_ext_hw/multi/pdm_pcm_tx.py @@ -0,0 +1,50 @@ +import os +from machine import Pin +import time + +# Allocate pin based on board +board = os.uname().machine +if "CY8CPROTO-062-4343W" in board: + clk_in_pin = "P10_1" + data_out_pin = "P10_5" + sync_in_pin = "P10_0" +elif "CY8CPROTO-063-BLE" in board: + print("SKIP") + raise SystemExit +elif "CY8CKIT-062S2-AI" in board: + print("SKIP") + raise SystemExit + +start_time = time.time() + +sig_val = 1 +test_done = False + + +def signal_irq(event): + global sig_val + sig_val = 0 + + +def blocking_delay_ms(delay_ms): + start = time.ticks_ms() + while time.ticks_diff(time.ticks_ms(), start) < delay_ms: + pass + + +data_out = Pin(data_out_pin, mode=Pin.OUT, pull=Pin.PULL_DOWN, value=False) +clk_in = Pin(clk_in_pin, Pin.IN, Pin.PULL_DOWN) +sync_data = Pin(sync_in_pin, Pin.IN, Pin.PULL_DOWN) +sync_data.irq(handler=signal_irq, trigger=Pin.IRQ_RISING) + +data_out.value(1) +while test_done == False: + while sig_val: + pass + data_out.value(0) + blocking_delay_ms(200000) + test_done = True + +data_out.deinit() +clk_in.deinit() +sync_data.deinit() diff --git a/tests/ports/psoc6/run_psoc6_tests.sh b/tests/ports/psoc6/run_psoc6_tests.sh index 8c493d36bffd..728edc777a11 100755 --- a/tests/ports/psoc6/run_psoc6_tests.sh +++ b/tests/ports/psoc6/run_psoc6_tests.sh @@ -38,6 +38,7 @@ usage() { echo " uart run uart tests" echo " spi run spi tests" echo " i2s run i2s tests" + echo " pdm_pcm run pdm_pcm tests" echo " bitstream run bitstream tests" echo " watchdog run watchdog tests" echo " multi-instance run multiple board instances tests" @@ -236,6 +237,11 @@ i2s_tests() { "" "i2s_tx" ${dev_stub} "${tests_psoc6_dir}/board_ext_hw/multi/i2s_tx.py" } +pdm_pcm_tests() { + run_tests "pdm_pcm" ${dev_test} "${tests_psoc6_dir}/board_ext_hw/multi/pdm_pcm_rx.py" \ + "" "pdm_pcm_tx" ${dev_stub} "${tests_psoc6_dir}/board_ext_hw/multi/pdm_pcm_tx.py" +} + wdt_tests() { run_tests "wdt" ${dev_test} "${tests_psoc6_dir}/board_only_hw/single/wdt.py" sleep 2 @@ -341,6 +347,17 @@ run_ci_tests() { fi fi i2s_tests + + if [ "${board}" == "CY8CPROTO-062-4343W" ] || [ "${board}" == "CY8CPROTO-063-BLE" ]; then + dev_test=${devs_b[0]} + dev_stub=${devs_a[0]} + else + if [ "${board}" == "CY8CKIT-062S2-AI" ]; then + dev_test=${devs_c[0]} + dev_stub=${devs_b[0]} + fi + fi + pdm_pcm_tests if [ "${board}" == "CY8CPROTO-062-4343W" ] || [ "${board}" == "CY8CPROTO-063-BLE" ]; then dev_test=${devs_a[0]} @@ -399,6 +416,9 @@ case ${test_suite} in "i2s") i2s_tests ;; + "pdm_pcm") + pdm_pcm_tests + ;; "uart") uart_tests ;;