From 397c7a2406e14f76cce194f369eb8a19778271f9 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Wed, 12 Jan 2022 19:32:21 +1100 Subject: [PATCH 1/6] Update stm32f1xx_hal_msp.c --- source/Core/BSP/Miniware/stm32f1xx_hal_msp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Core/BSP/Miniware/stm32f1xx_hal_msp.c b/source/Core/BSP/Miniware/stm32f1xx_hal_msp.c index 7b88dc04de..5ee6dea04d 100644 --- a/source/Core/BSP/Miniware/stm32f1xx_hal_msp.c +++ b/source/Core/BSP/Miniware/stm32f1xx_hal_msp.c @@ -7,7 +7,7 @@ void HAL_MspInit(void) { __HAL_RCC_AFIO_CLK_ENABLE(); - HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4); + // HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4); /* System interrupt init*/ /* MemoryManagement_IRQn interrupt configuration */ From f79dec5ee3aeafc701107f7d2570db186d3ff7d1 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Wed, 12 Jan 2022 20:03:44 +1100 Subject: [PATCH 2/6] TEMP: Disable DMA I2C --- source/Core/BSP/Miniware/I2C_Wrapper.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/Core/BSP/Miniware/I2C_Wrapper.cpp b/source/Core/BSP/Miniware/I2C_Wrapper.cpp index 37d521c1c6..c138c1a6b4 100644 --- a/source/Core/BSP/Miniware/I2C_Wrapper.cpp +++ b/source/Core/BSP/Miniware/I2C_Wrapper.cpp @@ -56,11 +56,12 @@ bool FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress, uint8_t *pDat bool FRToSI2C::Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size) { if (!lock()) return false; - if (HAL_I2C_Master_Transmit_DMA(&hi2c1, DevAddress, pData, Size) != HAL_OK) { + if (HAL_I2C_Master_Transmit(&hi2c1, DevAddress, pData, Size, 1000) != HAL_OK) { I2C_Unstick(); unlock(); return false; } + unlock(); return true; } From aea4a01d81618770177204d6a22605ca14dff45d Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Wed, 12 Jan 2022 20:03:58 +1100 Subject: [PATCH 3/6] Update I2C_Wrapper.cpp --- source/Core/BSP/Miniware/I2C_Wrapper.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/Core/BSP/Miniware/I2C_Wrapper.cpp b/source/Core/BSP/Miniware/I2C_Wrapper.cpp index c138c1a6b4..1038e41db1 100644 --- a/source/Core/BSP/Miniware/I2C_Wrapper.cpp +++ b/source/Core/BSP/Miniware/I2C_Wrapper.cpp @@ -11,10 +11,10 @@ SemaphoreHandle_t FRToSI2C::I2CSemaphore = nullptr; StaticSemaphore_t FRToSI2C::xSemaphoreBuffer; void FRToSI2C::CpltCallback() { - hi2c1.State = HAL_I2C_STATE_READY; // Force state reset (even if tx error) - if (I2CSemaphore) { - xSemaphoreGiveFromISR(I2CSemaphore, NULL); - } + // hi2c1.State = HAL_I2C_STATE_READY; // Force state reset (even if tx error) + // if (I2CSemaphore) { + // xSemaphoreGiveFromISR(I2CSemaphore, NULL); + // } } bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t MemAddress, uint8_t *pData, uint16_t Size) { From 969611cf794c0c04e6f40e8165c5ffea8828b42c Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Sun, 30 Jan 2022 11:42:41 +1100 Subject: [PATCH 4/6] Turn DMA back on --- .gitignore | 1 + source/Core/BSP/Miniware/I2C_Wrapper.cpp | 13 ++++++------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index d1040dc1d1..a9a7c21a01 100644 --- a/.gitignore +++ b/.gitignore @@ -176,3 +176,4 @@ fabric.properties CoreCompileInputs.cache .vscode/settings.json +source/compile_commands.json diff --git a/source/Core/BSP/Miniware/I2C_Wrapper.cpp b/source/Core/BSP/Miniware/I2C_Wrapper.cpp index 1038e41db1..888a3a0937 100644 --- a/source/Core/BSP/Miniware/I2C_Wrapper.cpp +++ b/source/Core/BSP/Miniware/I2C_Wrapper.cpp @@ -11,10 +11,10 @@ SemaphoreHandle_t FRToSI2C::I2CSemaphore = nullptr; StaticSemaphore_t FRToSI2C::xSemaphoreBuffer; void FRToSI2C::CpltCallback() { - // hi2c1.State = HAL_I2C_STATE_READY; // Force state reset (even if tx error) - // if (I2CSemaphore) { - // xSemaphoreGiveFromISR(I2CSemaphore, NULL); - // } + hi2c1.State = HAL_I2C_STATE_READY; // Force state reset (even if tx error) + if (I2CSemaphore) { + xSemaphoreGiveFromISR(I2CSemaphore, NULL); + } } bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t MemAddress, uint8_t *pData, uint16_t Size) { @@ -56,12 +56,11 @@ bool FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress, uint8_t *pDat bool FRToSI2C::Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size) { if (!lock()) return false; - if (HAL_I2C_Master_Transmit(&hi2c1, DevAddress, pData, Size, 1000) != HAL_OK) { + if (HAL_I2C_Master_Transmit_DMA(&hi2c1, DevAddress, pData, Size) != HAL_OK) { I2C_Unstick(); unlock(); return false; } - unlock(); return true; } @@ -78,7 +77,7 @@ void FRToSI2C::I2C_Unstick() { unstick_I2C(); } void FRToSI2C::unlock() { xSemaphoreGive(I2CSemaphore); } -bool FRToSI2C::lock() { return xSemaphoreTake(I2CSemaphore, (TickType_t)50) == pdTRUE; } +bool FRToSI2C::lock() { return xSemaphoreTake(I2CSemaphore, (TickType_t)500) == pdTRUE; } bool FRToSI2C::writeRegistersBulk(const uint8_t address, const I2C_REG *registers, const uint8_t registersLength) { for (int index = 0; index < registersLength; index++) { From d6b65490f446b0d6fa21f7799ae4f805869cb0f2 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Sun, 30 Jan 2022 12:35:08 +1100 Subject: [PATCH 5/6] Testing hacky DMA workaround Revert "Testing hacky DMA workaround" This reverts commit 5c78958d77679d706b2a922468bfdd978418b937. From 6b25e603e0f1d578283bbd1b23ec823f78b0774a Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Sun, 30 Jan 2022 13:30:44 +1100 Subject: [PATCH 6/6] use IRQ mode --- source/Core/BSP/Miniware/I2C_Wrapper.cpp | 4 ++-- source/Core/BSP/Miniware/stm32f1xx_hal_msp.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/Core/BSP/Miniware/I2C_Wrapper.cpp b/source/Core/BSP/Miniware/I2C_Wrapper.cpp index 888a3a0937..47150ab5b3 100644 --- a/source/Core/BSP/Miniware/I2C_Wrapper.cpp +++ b/source/Core/BSP/Miniware/I2C_Wrapper.cpp @@ -56,7 +56,7 @@ bool FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress, uint8_t *pDat bool FRToSI2C::Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size) { if (!lock()) return false; - if (HAL_I2C_Master_Transmit_DMA(&hi2c1, DevAddress, pData, Size) != HAL_OK) { + if (HAL_I2C_Master_Transmit_IT(&hi2c1, DevAddress, pData, Size) != HAL_OK) { I2C_Unstick(); unlock(); return false; @@ -77,7 +77,7 @@ void FRToSI2C::I2C_Unstick() { unstick_I2C(); } void FRToSI2C::unlock() { xSemaphoreGive(I2CSemaphore); } -bool FRToSI2C::lock() { return xSemaphoreTake(I2CSemaphore, (TickType_t)500) == pdTRUE; } +bool FRToSI2C::lock() { return xSemaphoreTake(I2CSemaphore, (TickType_t)50) == pdTRUE; } bool FRToSI2C::writeRegistersBulk(const uint8_t address, const I2C_REG *registers, const uint8_t registersLength) { for (int index = 0; index < registersLength; index++) { diff --git a/source/Core/BSP/Miniware/stm32f1xx_hal_msp.c b/source/Core/BSP/Miniware/stm32f1xx_hal_msp.c index 5ee6dea04d..37bd47c288 100644 --- a/source/Core/BSP/Miniware/stm32f1xx_hal_msp.c +++ b/source/Core/BSP/Miniware/stm32f1xx_hal_msp.c @@ -82,7 +82,7 @@ void HAL_I2C_MspInit(I2C_HandleTypeDef *hi2c) { GPIO_InitStruct.Pin = SCL_Pin | SDA_Pin; GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /* Peripheral clock enable */