Skip to content

Commit 34a99d1

Browse files
committed
Implements PDMIn for STM32L4 using the SAI peripheral and decimation/filtering in software.
1 parent 952812c commit 34a99d1

File tree

17 files changed

+1512
-47
lines changed

17 files changed

+1512
-47
lines changed

locale/circuitpython.pot

Lines changed: 20 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2442,10 +2442,6 @@ msgstr ""
24422442
msgid "array and index length must be equal"
24432443
msgstr ""
24442444

2445-
#: extmod/ulab/code/numpy/io/io.c
2446-
msgid "array has too many dimensions"
2447-
msgstr ""
2448-
24492445
#: py/objarray.c shared-bindings/alarm/SleepMemory.c
24502446
#: shared-bindings/coproc/CoprocMemory.c shared-bindings/nvm/ByteArray.c
24512447
msgid "array/bytes required on right side"
@@ -2808,10 +2804,6 @@ msgstr ""
28082804
msgid "convolve arguments must not be empty"
28092805
msgstr ""
28102806

2811-
#: extmod/ulab/code/numpy/io/io.c
2812-
msgid "corrupted file"
2813-
msgstr ""
2814-
28152807
#: extmod/ulab/code/numpy/poly.c
28162808
msgid "could not invert Vandermonde matrix"
28172809
msgstr ""
@@ -2899,10 +2891,6 @@ msgstr ""
28992891
msgid "empty"
29002892
msgstr ""
29012893

2902-
#: extmod/ulab/code/numpy/io/io.c
2903-
msgid "empty file"
2904-
msgstr ""
2905-
29062894
#: extmod/moduasyncio.c extmod/moduheapq.c extmod/modutimeq.c
29072895
msgid "empty heap"
29082896
msgstr ""
@@ -3008,7 +2996,7 @@ msgstr ""
30082996
msgid "first argument must be a tuple of ndarrays"
30092997
msgstr ""
30102998

3011-
#: extmod/ulab/code/numpy/transform.c extmod/ulab/code/numpy/vector.c
2999+
#: extmod/ulab/code/numpy/vector.c
30123000
msgid "first argument must be an ndarray"
30133001
msgstr ""
30143002

@@ -3156,7 +3144,7 @@ msgstr ""
31563144
msgid "incorrect padding"
31573145
msgstr ""
31583146

3159-
#: extmod/ulab/code/ndarray.c extmod/ulab/code/numpy/transform.c
3147+
#: extmod/ulab/code/ndarray.c
31603148
msgid "index is out of bounds"
31613149
msgstr ""
31623150

@@ -3223,10 +3211,6 @@ msgstr ""
32233211
msgid "input matrix is singular"
32243212
msgstr ""
32253213

3226-
#: extmod/ulab/code/numpy/create.c
3227-
msgid "input must be 1- or 2-d"
3228-
msgstr ""
3229-
32303214
#: extmod/ulab/code/numpy/carray/carray.c
32313215
msgid "input must be a 1D ndarray"
32323216
msgstr ""
@@ -3235,7 +3219,11 @@ msgstr ""
32353219
msgid "input must be a dense ndarray"
32363220
msgstr ""
32373221

3238-
#: extmod/ulab/code/user/user.c
3222+
#: extmod/ulab/code/numpy/create.c
3223+
msgid "input must be a tensor of rank 2"
3224+
msgstr ""
3225+
3226+
#: extmod/ulab/code/numpy/create.c extmod/ulab/code/user/user.c
32393227
msgid "input must be an ndarray"
32403228
msgstr ""
32413229

@@ -3448,7 +3436,7 @@ msgid "max_length must be 0-%d when fixed_length is %s"
34483436
msgstr ""
34493437

34503438
#: extmod/ulab/code/ndarray.c
3451-
msgid "maximum number of dimensions is "
3439+
msgid "maximum number of dimensions is 4"
34523440
msgstr ""
34533441

34543442
#: py/runtime.c
@@ -3697,7 +3685,7 @@ msgstr ""
36973685
msgid "off"
36983686
msgstr ""
36993687

3700-
#: extmod/ulab/code/utils/utils.c
3688+
#: extmod/ulab/code/numpy/create.c extmod/ulab/code/utils/utils.c
37013689
msgid "offset is too large"
37023690
msgstr ""
37033691

@@ -3714,10 +3702,20 @@ msgid "offset out of bounds"
37143702
msgstr ""
37153703

37163704
#: ports/nrf/common-hal/audiobusio/PDMIn.c
3705+
#: ports/stm/common-hal/audiobusio/PDMIn.c
37173706
msgid "only bit_depth=16 is supported"
37183707
msgstr ""
37193708

3709+
#: ports/stm/common-hal/audiobusio/PDMIn.c
3710+
msgid "only mono is supported"
3711+
msgstr ""
3712+
3713+
#: ports/stm/common-hal/audiobusio/PDMIn.c
3714+
msgid "only oversample=64 is supported"
3715+
msgstr ""
3716+
37203717
#: ports/nrf/common-hal/audiobusio/PDMIn.c
3718+
#: ports/stm/common-hal/audiobusio/PDMIn.c
37213719
msgid "only sample_rate=16000 is supported"
37223720
msgstr ""
37233721

@@ -4247,14 +4245,6 @@ msgstr ""
42474245
msgid "unsupported types for %q: '%q', '%q'"
42484246
msgstr ""
42494247

4250-
#: extmod/ulab/code/numpy/io/io.c
4251-
msgid "usecols is too high"
4252-
msgstr ""
4253-
4254-
#: extmod/ulab/code/numpy/io/io.c
4255-
msgid "usecols keyword must be specified"
4256-
msgstr ""
4257-
42584248
#: py/objint.c
42594249
#, c-format
42604250
msgid "value must fit in %d byte(s)"
@@ -4301,28 +4291,14 @@ msgstr ""
43014291
msgid "wrong axis specified"
43024292
msgstr ""
43034293

4304-
#: extmod/ulab/code/numpy/io/io.c
4305-
msgid "wrong dtype"
4306-
msgstr ""
4307-
4308-
#: extmod/ulab/code/numpy/transform.c
4309-
msgid "wrong index type"
4310-
msgstr ""
4311-
4312-
#: extmod/ulab/code/numpy/compare.c extmod/ulab/code/numpy/create.c
4313-
#: extmod/ulab/code/numpy/io/io.c extmod/ulab/code/numpy/transform.c
4314-
#: extmod/ulab/code/numpy/vector.c
4294+
#: extmod/ulab/code/numpy/compare.c extmod/ulab/code/numpy/vector.c
43154295
msgid "wrong input type"
43164296
msgstr ""
43174297

43184298
#: extmod/ulab/code/numpy/transform.c
43194299
msgid "wrong length of condition array"
43204300
msgstr ""
43214301

4322-
#: extmod/ulab/code/numpy/transform.c
4323-
msgid "wrong length of index array"
4324-
msgstr ""
4325-
43264302
#: extmod/ulab/code/numpy/create.c py/objarray.c py/objstr.c
43274303
msgid "wrong number of arguments"
43284304
msgstr ""

ports/stm/Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,17 @@ SRC_C += \
234234
peripherals/stm32$(MCU_SERIES_LOWER)/$(MCU_VARIANT_LOWER)/periph.c \
235235
packages/$(MCU_PACKAGE).c
236236

237+
ifneq ($(CIRCUITPY_AUDIOBUSIO_PDMIN),0)
238+
SRC_C += \
239+
common-hal/audiobusio/MEMS_Audio.c \
240+
common-hal/audiobusio/MEMS_Audio_ll_stm32l4.c \
241+
common-hal/audiobusio/OpenPDMFilter.c
242+
243+
SRC_STM32 += \
244+
$(HAL_DIR)/Src/stm32$(MCU_SERIES_LOWER)xx_hal_sai.c
245+
246+
endif
247+
237248
ifneq ($(CIRCUITPY_USB),0)
238249
SRC_C += lib/tinyusb/src/portable/st/synopsys/dcd_synopsys.c
239250
endif

ports/stm/boards/swan_r5/mpconfigboard.mk

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,9 @@ CIRCUITPY_PULSEIO = 1
4141
CIRCUITPY_PWMIO = 1
4242
CIRCUITPY_AUDIOPWMIO = 1
4343
CIRCUITPY_CANIO = 0
44-
CIRCUITPY_AUDIOBUSIO = 0
4544
CIRCUITPY_I2CTARGET = 0
4645
# Requires SPI, PulseIO (stub ok):
47-
CIRCUITPY_DISPLAYIO = 0
46+
CIRCUITPY_DISPLAYIO = 1
4847

4948
# These modules are implemented in shared-module/ - they can be included in
5049
# any port once their prerequisites in common-hal are complete.
@@ -71,5 +70,8 @@ CIRCUITPY_BUSDEVICE = 0
7170
CIRCUITPY_KEYPAD = 1
7271
CIRCUITPY_RGBMATRIX = 0
7372
CIRCUITPY_RTC = 1
74-
7573
CIRCUITPY_BUILD_EXTENSIONS = bin,uf2
74+
CIRCUITPY_ENABLE_MPY_NATIVE = 1
75+
CIRCUITPY_AUDIOBUSIO = 1
76+
CIRCUITPY_AUDIOBUSIO_I2SOUT = 0
77+
CIRCUITPY_AUDIOBUSIO_PDMIN = 1

ports/stm/boards/swan_r5/pins.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,5 +129,8 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
129129
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
130130
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
131131
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) },
132+
133+
{ MP_ROM_QSTR(MP_QSTR_MICROPHONE_CLOCK), MP_ROM_PTR(&pin_PA03) },
134+
{ MP_ROM_QSTR(MP_QSTR_MICROPHONE_DATA), MP_ROM_PTR(&pin_PC03) },
132135
};
133136
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Although IS2Out is not enabled on the STM32L4 family, this file is still required for the build to pass
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Although IS2Out is not enabled on the STM32L4 family, this file is still required for the build to pass
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#include <assert.h>
2+
#include <stm32l4xx_hal.h>
3+
4+
#include "MEMS_Audio.h"
5+
#include "MEMS_Audio_ll.h"
6+
7+
static void default_pcm_data_available(MemsAudio *audio, pcm_sample_t *pcmSamples, size_t pcmLength) {
8+
}
9+
10+
11+
12+
/**
13+
* @brief Initializes the MemsAudio instance. Only one instance can be initialized and used at a given time.
14+
*
15+
* @param audio
16+
* @return mems_audio_err_t
17+
*/
18+
mems_audio_err_t mems_audio_init(MemsAudio *audio) {
19+
if (!audio->pcm_data_available) {
20+
audio->pcm_data_available = default_pcm_data_available;
21+
}
22+
return mems_audio_ll_init(audio);
23+
}
24+
25+
/**
26+
* @brief Uninitializes the MemsAudio instance.
27+
*
28+
* @param audio
29+
* @return mems_audio_err_t
30+
*/
31+
mems_audio_err_t mems_audio_uninit(MemsAudio *audio) {
32+
return mems_audio_ll_uninit(audio);
33+
}
34+
35+
/**
36+
* @brief Asynchronously records audio.
37+
*
38+
* @param audio
39+
* @param pdmBuffer
40+
* @param pdmBufferLength
41+
* @return mems_audio_err_t
42+
*/
43+
mems_audio_err_t mems_audio_record(MemsAudio *audio) {
44+
return mems_audio_ll_record(audio);
45+
}
46+
47+
/**
48+
* @brief Pause recording audio.
49+
*/
50+
mems_audio_err_t mems_audio_pause(MemsAudio *audio) {
51+
return mems_audio_ll_pause(audio);
52+
}
53+
54+
/**
55+
* @brief Resume recording audio.
56+
*
57+
* @param audio
58+
* @return mems_audio_err_t
59+
*/
60+
mems_audio_err_t mems_audio_resume(MemsAudio *audio) {
61+
return mems_audio_ll_resume(audio);
62+
}
63+
64+
/**
65+
* @brief Stop recording audio and
66+
*
67+
* @param audio
68+
* @return mems_audio_err_t
69+
*/
70+
mems_audio_err_t mems_audio_stop(MemsAudio *audio) {
71+
return mems_audio_ll_stop(audio);
72+
}

0 commit comments

Comments
 (0)