Commit 82504d54 authored by Klint Youngmeyer's avatar Klint Youngmeyer
Browse files

Add support for I2S bus #3, for the EMAC boards

parent 17474f0b
......@@ -20,6 +20,7 @@
#define MICROPY_HW_ENABLE_CAN (1)
#define MICROPY_HW_ENABLE_USB (1)
#define MICROPY_HW_ENABLE_SDCARD (1)
#define MICROPY_HW_ENABLE_I2S (1)
#define MICROPY_PY_THREAD (1)
#define MICROPY_PY_THREAD_GIL (1)
......@@ -98,6 +99,9 @@
#define MICROPY_HW_SPI2_MISO (pin_I2)
#define MICROPY_HW_SPI2_MOSI (pin_I3)
// I2S buses
#define MICROPY_HW_I2S3 (1)
// CAN busses
#define MICROPY_HW_CAN1_TX (pin_D0)
#define MICROPY_HW_CAN1_RX (pin_D1)
......
......@@ -20,6 +20,7 @@
#define MICROPY_HW_ENABLE_CAN (1)
#define MICROPY_HW_ENABLE_USB (1)
#define MICROPY_HW_ENABLE_SDCARD (1)
#define MICROPY_HW_ENABLE_I2S (1)
#define MICROPY_PY_THREAD (1)
#define MICROPY_PY_THREAD_GIL (1)
......@@ -98,6 +99,9 @@
#define MICROPY_HW_SPI2_MISO (pin_I2)
#define MICROPY_HW_SPI2_MOSI (pin_I3)
// I2S buses
#define MICROPY_HW_I2S3 (1)
// CAN busses
#define MICROPY_HW_CAN1_TX (pin_D0)
#define MICROPY_HW_CAN1_RX (pin_D1)
......
......@@ -20,6 +20,7 @@
#define MICROPY_HW_ENABLE_CAN (1)
#define MICROPY_HW_ENABLE_USB (1)
#define MICROPY_HW_ENABLE_SDCARD (1)
#define MICROPY_HW_ENABLE_I2S (1)
#define MICROPY_PY_THREAD (1)
#define MICROPY_PY_THREAD_GIL (1)
......@@ -98,6 +99,9 @@
#define MICROPY_HW_SPI2_MISO (pin_I2)
#define MICROPY_HW_SPI2_MOSI (pin_I3)
// I2S buses
#define MICROPY_HW_I2S3 (1)
// CAN busses
#define MICROPY_HW_CAN1_TX (pin_D0)
#define MICROPY_HW_CAN1_RX (pin_D1)
......
......@@ -260,6 +260,9 @@ static const uint8_t dma_irqn[NSTREAM] = {
// DMA1 streams
const dma_descr_t dma_I2C_1_RX = { DMA1_Stream0, DMA_CHANNEL_1, dma_id_0, &dma_init_struct_spi_i2c };
const dma_descr_t dma_SPI_3_RX = { DMA1_Stream2, DMA_CHANNEL_0, dma_id_2, &dma_init_struct_spi_i2c };
#if MICROPY_HW_ENABLE_I2S
const dma_descr_t dma_I2S_3_RX = { DMA1_Stream2, DMA_CHANNEL_0, dma_id_2, &dma_init_struct_i2s };
#endif
#if defined(STM32F7)
const dma_descr_t dma_I2C_4_RX = { DMA1_Stream2, DMA_CHANNEL_2, dma_id_2, &dma_init_struct_spi_i2c };
#endif
......@@ -280,6 +283,9 @@ const dma_descr_t dma_DAC_1_TX = { DMA1_Stream5, DMA_CHANNEL_7, dma_id_5, &dma
const dma_descr_t dma_DAC_2_TX = { DMA1_Stream6, DMA_CHANNEL_7, dma_id_6, &dma_init_struct_dac };
#endif
const dma_descr_t dma_SPI_3_TX = { DMA1_Stream7, DMA_CHANNEL_0, dma_id_7, &dma_init_struct_spi_i2c };
#if MICROPY_HW_ENABLE_I2S
const dma_descr_t dma_I2S_3_TX = { DMA1_Stream7, DMA_CHANNEL_0, dma_id_7, &dma_init_struct_i2s };
#endif
const dma_descr_t dma_I2C_1_TX = { DMA1_Stream7, DMA_CHANNEL_1, dma_id_7, &dma_init_struct_spi_i2c };
const dma_descr_t dma_I2C_2_TX = { DMA1_Stream7, DMA_CHANNEL_7, dma_id_7, &dma_init_struct_spi_i2c };
/* not preferred streams
......
......@@ -61,6 +61,8 @@ extern const dma_descr_t dma_I2S_1_RX;
extern const dma_descr_t dma_I2S_1_TX;
extern const dma_descr_t dma_I2S_2_RX;
extern const dma_descr_t dma_I2S_2_TX;
extern const dma_descr_t dma_I2S_3_RX;
extern const dma_descr_t dma_I2S_3_TX;
#elif defined(STM32L0)
......
......@@ -81,7 +81,7 @@
// 32 byte address boundary. Not all STM32 devices have a D-Cache. Buffer alignment
// will still happen on these devices to keep this code simple.
#define MAX_I2S_STM32 (2)
#define MAX_I2S_STM32 (3)
// DMA ping-pong buffer size was empirically determined. It is a tradeoff between:
// 1. memory use (smaller buffer size desirable to reduce memory footprint)
......@@ -541,6 +541,15 @@ STATIC bool i2s_init(machine_i2s_obj_t *self) {
} else {
self->dma_descr_tx = &dma_I2S_2_TX;
}
} else if (self->i2s_id == 3) {
self->hi2s.Instance = I2S3;
__SPI3_CLK_ENABLE();
// configure DMA streams
if (self->mode == I2S_MODE_MASTER_RX) {
self->dma_descr_rx = &dma_I2S_3_RX;
} else {
self->dma_descr_tx = &dma_I2S_3_TX;
}
} else {
// invalid id number; should not get here as i2s object should not
// have been created without setting a valid i2s instance number
......@@ -599,8 +608,10 @@ void HAL_I2S_RxCpltCallback(I2S_HandleTypeDef *hi2s) {
machine_i2s_obj_t *self;
if (hi2s->Instance == I2S1) {
self = machine_i2s_obj[0];
} else {
} else if (hi2s->Instance == I2S2) {
self = machine_i2s_obj[1];
} else {
self = machine_i2s_obj[2];
}
// bottom half of buffer now filled,
......@@ -618,8 +629,10 @@ void HAL_I2S_RxHalfCpltCallback(I2S_HandleTypeDef *hi2s) {
machine_i2s_obj_t *self;
if (hi2s->Instance == I2S1) {
self = machine_i2s_obj[0];
} else {
} else if (hi2s->Instance == I2S2) {
self = machine_i2s_obj[1];
} else {
self = machine_i2s_obj[2];
}
// top half of buffer now filled,
......@@ -638,8 +651,10 @@ void HAL_I2S_TxCpltCallback(I2S_HandleTypeDef *hi2s) {
if (hi2s->Instance == I2S1) {
self = machine_i2s_obj[0];
} else {
} else if (hi2s->Instance == I2S2) {
self = machine_i2s_obj[1];
} else {
self = machine_i2s_obj[2];
}
// for non-blocking operation, this IRQ-based callback handles
......@@ -657,8 +672,10 @@ void HAL_I2S_TxHalfCpltCallback(I2S_HandleTypeDef *hi2s) {
machine_i2s_obj_t *self;
if (hi2s->Instance == I2S1) {
self = machine_i2s_obj[0];
} else {
} else if (hi2s->Instance == I2S2) {
self = machine_i2s_obj[1];
} else {
self = machine_i2s_obj[2];
}
// for non-blocking operation, this IRQ-based callback handles
......@@ -851,6 +868,10 @@ STATIC mp_obj_t machine_i2s_make_new(const mp_obj_type_t *type, size_t n_pos_arg
} else if (i2s_id == 2) {
i2s_id_zero_base = 1;
#endif
#ifdef MICROPY_HW_I2S3
} else if (i2s_id == 3) {
i2s_id_zero_base = 2;
#endif
} else {
mp_raise_ValueError(MP_ERROR_TEXT("invalid id"));
}
......@@ -900,6 +921,10 @@ STATIC mp_obj_t machine_i2s_deinit(mp_obj_t self_in) {
__SPI2_FORCE_RESET();
__SPI2_RELEASE_RESET();
__SPI2_CLK_DISABLE();
} else if (self->hi2s.Instance == I2S3) {
__SPI3_FORCE_RESET();
__SPI3_RELEASE_RESET();
__SPI3_CLK_DISABLE();
}
m_free(self->ring_buffer_storage);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment