From d172acba926b72c57c47697bd640c51c0fcb038d Mon Sep 17 00:00:00 2001
From: Paul Selkirk <paul@psgd.org>
Date: Tue, 20 Sep 2016 09:10:08 -0400
Subject: Still some problem with uart receive under heavy load, so change to a
 2-byte receive buffer with half-complete callbacks, and raise the dma
 priority.

---
 .../TARGET_CRYPTECH_ALPHA/stm32f4xx_hal_msp.c      |  2 +-
 .../TARGET_CRYPTECH_ALPHA/stm32f4xx_it.c           | 42 +++++++++++++++++++---
 .../TARGET_CRYPTECH_ALPHA/stm32f4xx_it_rtos.c      | 42 +++++++++++++++++++---
 3 files changed, 75 insertions(+), 11 deletions(-)

(limited to 'libraries')

diff --git a/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4/TARGET_CRYPTECH_ALPHA/stm32f4xx_hal_msp.c b/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4/TARGET_CRYPTECH_ALPHA/stm32f4xx_hal_msp.c
index 7eeb6df..609c596 100644
--- a/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4/TARGET_CRYPTECH_ALPHA/stm32f4xx_hal_msp.c
+++ b/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4/TARGET_CRYPTECH_ALPHA/stm32f4xx_hal_msp.c
@@ -182,7 +182,7 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart)
     hdma->Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
     hdma->Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
     hdma->Init.Mode = DMA_CIRCULAR;
-    hdma->Init.Priority = DMA_PRIORITY_LOW;
+    hdma->Init.Priority = DMA_PRIORITY_HIGH;
     hdma->Init.FIFOMode = DMA_FIFOMODE_DISABLE;
     /*
       hdma->Init.FIFOThreshold = DMA_FIFO_THRESHOLD_HALFFULL;
diff --git a/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4/TARGET_CRYPTECH_ALPHA/stm32f4xx_it.c b/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4/TARGET_CRYPTECH_ALPHA/stm32f4xx_it.c
index 7b8e97f..f69e790 100644
--- a/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4/TARGET_CRYPTECH_ALPHA/stm32f4xx_it.c
+++ b/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4/TARGET_CRYPTECH_ALPHA/stm32f4xx_it.c
@@ -189,6 +189,12 @@ void USART2_IRQHandler(void)
     HAL_UART_IRQHandler(&huart_user);
 }
 
+/**
+  * @brief  Rx Transfer completed callbacks.
+  * @param  huart: pointer to a UART_HandleTypeDef structure that contains
+  *                the configuration information for the specified UART module.
+  * @retval None
+  */
 void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
 {
     extern void HAL_UART1_RxCpltCallback(UART_HandleTypeDef *huart);
@@ -201,23 +207,49 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
         HAL_UART2_RxCpltCallback(huart);
 }
 
+__weak void HAL_UART1_RxCpltCallback(UART_HandleTypeDef *huart)
+{
+  /* NOTE: This function Should not be modified, when the callback is needed,
+           the HAL_UART1_RxCpltCallback could be implemented in the user file
+   */
+}
+
+__weak void HAL_UART2_RxCpltCallback(UART_HandleTypeDef *huart)
+{
+  /* NOTE: This function Should not be modified, when the callback is needed,
+           the HAL_UART2_RxCpltCallback could be implemented in the user file
+   */
+}
+
 /**
-  * @brief  Rx Transfer completed callbacks.
+  * @brief  Rx Half Transfer completed callbacks.
   * @param  huart: pointer to a UART_HandleTypeDef structure that contains
   *                the configuration information for the specified UART module.
   * @retval None
   */
-__weak void HAL_UART1_RxCpltCallback(UART_HandleTypeDef *huart)
+void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart)
+{
+    extern void HAL_UART1_RxHalfCpltCallback(UART_HandleTypeDef *huart);
+    extern void HAL_UART2_RxHalfCpltCallback(UART_HandleTypeDef *huart);
+
+    if (huart->Instance == USART1)
+        HAL_UART1_RxHalfCpltCallback(huart);
+
+    else if (huart->Instance == USART2)
+        HAL_UART2_RxHalfCpltCallback(huart);
+}
+
+__weak void HAL_UART1_RxHalfCpltCallback(UART_HandleTypeDef *huart)
 {
   /* NOTE: This function Should not be modified, when the callback is needed,
-           the HAL_UART_RxCpltCallback could be implemented in the user file
+           the HAL_UART1_RxHalfCpltCallback could be implemented in the user file
    */
 }
 
-__weak void HAL_UART2_RxCpltCallback(UART_HandleTypeDef *huart)
+__weak void HAL_UART2_RxHalfCpltCallback(UART_HandleTypeDef *huart)
 {
   /* NOTE: This function Should not be modified, when the callback is needed,
-           the HAL_UART_TxCpltCallback could be implemented in the user file
+           the HAL_UART2_RxHalfCpltCallback could be implemented in the user file
    */
 }
 
diff --git a/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4/TARGET_CRYPTECH_ALPHA/stm32f4xx_it_rtos.c b/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4/TARGET_CRYPTECH_ALPHA/stm32f4xx_it_rtos.c
index 1118db2..0b829b3 100644
--- a/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4/TARGET_CRYPTECH_ALPHA/stm32f4xx_it_rtos.c
+++ b/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4/TARGET_CRYPTECH_ALPHA/stm32f4xx_it_rtos.c
@@ -193,6 +193,12 @@ void USART2_IRQHandler(void)
     HAL_UART_IRQHandler(&huart_user);
 }
 
+/**
+  * @brief  Rx Transfer completed callbacks.
+  * @param  huart: pointer to a UART_HandleTypeDef structure that contains
+  *                the configuration information for the specified UART module.
+  * @retval None
+  */
 void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
 {
     extern void HAL_UART1_RxCpltCallback(UART_HandleTypeDef *huart);
@@ -205,23 +211,49 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
         HAL_UART2_RxCpltCallback(huart);
 }
 
+__weak void HAL_UART1_RxCpltCallback(UART_HandleTypeDef *huart)
+{
+  /* NOTE: This function Should not be modified, when the callback is needed,
+           the HAL_UART1_RxCpltCallback could be implemented in the user file
+   */
+}
+
+__weak void HAL_UART2_RxCpltCallback(UART_HandleTypeDef *huart)
+{
+  /* NOTE: This function Should not be modified, when the callback is needed,
+           the HAL_UART2_RxCpltCallback could be implemented in the user file
+   */
+}
+
 /**
-  * @brief  Rx Transfer completed callbacks.
+  * @brief  Rx Half Transfer completed callbacks.
   * @param  huart: pointer to a UART_HandleTypeDef structure that contains
   *                the configuration information for the specified UART module.
   * @retval None
   */
-__weak void HAL_UART1_RxCpltCallback(UART_HandleTypeDef *huart)
+void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart)
+{
+    extern void HAL_UART1_RxHalfCpltCallback(UART_HandleTypeDef *huart);
+    extern void HAL_UART2_RxHalfCpltCallback(UART_HandleTypeDef *huart);
+
+    if (huart->Instance == USART1)
+        HAL_UART1_RxHalfCpltCallback(huart);
+
+    else if (huart->Instance == USART2)
+        HAL_UART2_RxHalfCpltCallback(huart);
+}
+
+__weak void HAL_UART1_RxHalfCpltCallback(UART_HandleTypeDef *huart)
 {
   /* NOTE: This function Should not be modified, when the callback is needed,
-           the HAL_UART_RxCpltCallback could be implemented in the user file
+           the HAL_UART1_RxHalfCpltCallback could be implemented in the user file
    */
 }
 
-__weak void HAL_UART2_RxCpltCallback(UART_HandleTypeDef *huart)
+__weak void HAL_UART2_RxHalfCpltCallback(UART_HandleTypeDef *huart)
 {
   /* NOTE: This function Should not be modified, when the callback is needed,
-           the HAL_UART_TxCpltCallback could be implemented in the user file
+           the HAL_UART2_RxHalfCpltCallback could be implemented in the user file
    */
 }
 
-- 
cgit v1.2.3