From b9ff46f1ed5e1468551890ce64a842c77c059ef6 Mon Sep 17 00:00:00 2001
From: Ryan Shaw <ryan.shaw@wisetechglobal.com>
Date: Tue, 15 May 2018 12:46:58 +1000
Subject: [PATCH] stm32: Enable UART7/8 on F4 series that have these
 peripherals.

---
 ports/stm32/boards/startup_stm32f4.s |  8 ++++++++
 ports/stm32/boards/stm32f439_af.csv  | 12 ++++++------
 ports/stm32/mpconfigboard_common.h   |  4 ++++
 ports/stm32/stm32_it.c               |  4 ++--
 4 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/ports/stm32/boards/startup_stm32f4.s b/ports/stm32/boards/startup_stm32f4.s
index e46a93b71..3e29a79a5 100644
--- a/ports/stm32/boards/startup_stm32f4.s
+++ b/ports/stm32/boards/startup_stm32f4.s
@@ -241,6 +241,8 @@ g_pfnVectors:
   .word     0                                 /* CRYP crypto                  */
   .word     HASH_RNG_IRQHandler               /* Hash and Rng                 */
   .word     FPU_IRQHandler                    /* FPU                          */
+  .word     UART7_IRQHandler                  /* UART7                        */
+  .word     UART8_IRQHandler                  /* UART8                        */
 
 /*******************************************************************************
 *
@@ -519,4 +521,10 @@ g_pfnVectors:
    .weak      FPU_IRQHandler
    .thumb_set FPU_IRQHandler,Default_Handler
 
+   .weak      UART7_IRQHandler
+   .thumb_set UART7_IRQHandler,Default_Handler
+
+   .weak      UART8_IRQHandler
+   .thumb_set UART8_IRQHandler,Default_Handler
+
 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/ports/stm32/boards/stm32f439_af.csv b/ports/stm32/boards/stm32f439_af.csv
index dc3641502..4fc1f1116 100644
--- a/ports/stm32/boards/stm32f439_af.csv
+++ b/ports/stm32/boards/stm32f439_af.csv
@@ -64,15 +64,15 @@ PortD,PD12,,,TIM4_CH1,,,,,USART3_RTS,,,,,FMC_A17,,,EVENTOUT,
 PortD,PD13,,,TIM4_CH2,,,,,,,,,,FMC_A18,,,EVENTOUT,
 PortD,PD14,,,TIM4_CH3,,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S,,,,,,FMC_D8,,LCD_G3,EVENTOUT,
@@ -86,8 +86,8 @@ PortF,PF2,,,,,I2C2_SMBA,,,,,,,,FMC_A2,,,EVENTOUT,
 PortF,PF3,,,,,,,,,,,,,FMC_A3,,,EVENTOUT,ADC3_IN9
 PortF,PF4,,,,,,,,,,,,,FMC_A4,,,EVENTOUT,ADC3_IN14
 PortF,PF5,,,,,,,,,,,,,FMC_A5,,,EVENTOUT,ADC3_IN15
-PortF,PF6,,,,TIM10_CH1,,SPI5_NSS,SAI1_SD_B,,UART7_Rx,,,,FMC_NIORD,,,EVENTOUT,ADC3_IN4
-PortF,PF7,,,,TIM11_CH1,,SPI5_SCK,SAI1_MCLK_B,,UART7_Tx,,,,FMC_NREG,,,EVENTOUT,ADC3_IN5
+PortF,PF6,,,,TIM10_CH1,,SPI5_NSS,SAI1_SD_B,,UART7_RX,,,,FMC_NIORD,,,EVENTOUT,ADC3_IN4
+PortF,PF7,,,,TIM11_CH1,,SPI5_SCK,SAI1_MCLK_B,,UART7_TX,,,,FMC_NREG,,,EVENTOUT,ADC3_IN5
 PortF,PF8,,,,,,SPI5_MISO,SAI1_SCK_B,,,TIM13_CH1,,,FMC_NIOWR,,,EVENTOUT,ADC3_IN6
 PortF,PF9,,,,,,SPI5_MOSI,SAI1_FS_B,,,TIM14_CH1,,,FMC_CD,,,EVENTOUT,ADC3_IN7
 PortF,PF10,,,,,,,,,,,,,FMC_INTR,DCMI_D11,LCD_DE,EVENTOUT,ADC3_IN8
diff --git a/ports/stm32/mpconfigboard_common.h b/ports/stm32/mpconfigboard_common.h
index a33b8d042..7449a6895 100644
--- a/ports/stm32/mpconfigboard_common.h
+++ b/ports/stm32/mpconfigboard_common.h
@@ -116,7 +116,11 @@
 #define MP_HAL_UNIQUE_ID_ADDRESS (0x1fff7a10)
 #define PYB_EXTI_NUM_VECTORS (23)
 #define MICROPY_HW_MAX_TIMER (14)
+#ifdef UART8
+#define MICROPY_HW_MAX_UART (8)
+#else
 #define MICROPY_HW_MAX_UART (6)
+#endif
 
 // Configuration for STM32F7 series
 #elif defined(STM32F7)
diff --git a/ports/stm32/stm32_it.c b/ports/stm32/stm32_it.c
index a77802bfa..d2cd0788a 100644
--- a/ports/stm32/stm32_it.c
+++ b/ports/stm32/stm32_it.c
@@ -720,7 +720,7 @@ void USART6_IRQHandler(void) {
     IRQ_EXIT(USART6_IRQn);
 }
 
-#if defined(MICROPY_HW_UART7_TX)
+#if defined(UART8)
 void UART7_IRQHandler(void) {
     IRQ_ENTER(UART7_IRQn);
     uart_irq_handler(7);
@@ -728,7 +728,7 @@ void UART7_IRQHandler(void) {
 }
 #endif
 
-#if defined(MICROPY_HW_UART8_TX)
+#if defined(UART8)
 void UART8_IRQHandler(void) {
     IRQ_ENTER(UART8_IRQn);
     uart_irq_handler(8);
-- 
GitLab