UART3 HANDSHAKING BUG

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
User avatar
roland_vs
Posts: 88
Joined: Tue Dec 08, 2015 8:28 pm
Location: Netherlands
Contact:

UART3 HANDSHAKING BUG

Post by roland_vs » Tue Apr 26, 2016 2:47 pm

Dear,

I'm using my own board with the STM32F4xx and use PYB10 as reference. I'm using a setup where alternate pins for UART3 are used. Normally these are:

Code: Select all

// works alright handshake et all
// in mpconfigboard.h of PYB
#define MICROPY_HW_UART3_PORT (GPIOB)
#define MICROPY_HW_UART3_PINS (GPIO_PIN_10 | GPIO_PIN_11)
#define MICROPY_HW_UART3_RTS  (GPIO_PIN_14)
#define MICROPY_HW_UART3_CTS  (GPIO_PIN_13)
But when using alternative pins, the RTS/CTS pins are not configured properly, nor can they be configured through mpconfigboard.h. So I made a hack in uart.c to let it work:

Code: Select all

// in mpconfigboard.h
// RXD/TXD ok, handshake lines cannot be configured
#define MICROPY_HW_UART3_PORT (GPIOC)
#define MICROPY_HW_UART3_PINS (GPIO_PIN_10 | GPIO_PIN_11) // PORTC
// separate GPIO for handshake pins
#define MICROPY_HW_UART3_HSK (GPIOB)
#define MICROPY_HW_UART3_RTS  (GPIO_PIN_14)	// SHOULD BE PORT B
#define MICROPY_HW_UART3_CTS  (GPIO_PIN_13)	// SHOULD BE PORT B
In uart.c:

Code: Select all

#if defined(USART3) && defined(MICROPY_HW_UART3_PORT) && defined(MICROPY_HW_UART3_PINS)
        // USART3 is on PB10/PB11 (CK,CTS,RTS on PB12,PB13,PB14), PC10/PC11 (CK on PC12), PD8/PD9 (CK on PD10)
        case PYB_UART_3:
            UARTx = USART3;
            irqn = USART3_IRQn;
            GPIO_AF_UARTx = GPIO_AF7_USART3;
            GPIO_Port = MICROPY_HW_UART3_PORT;
            GPIO_Pin = MICROPY_HW_UART3_PINS;
            #if defined(MICROPY_HW_UART3_RTS)
            if (uart_obj->uart.Init.HwFlowCtl & UART_HWCONTROL_RTS) {
 		
                //##GPIO_Pin |= MICROPY_HW_UART3_RTS;
                // we need to set the GPIO pins on a different GPIO than the UART
                GPIO_Pin2 = MICROPY_HW_UART3_RTS;
                GPIO_Port2 = MICROPY_HW_UART3_HSK;
                
            }
            #endif
            #if defined(MICROPY_HW_UART3_CTS)
            if (uart_obj->uart.Init.HwFlowCtl & UART_HWCONTROL_CTS) {

                //##GPIO_Pin |= MICROPY_HW_UART3_CTS;
                // we need to set the GPIO pins on a different GPIO than the UART
                GPIO_Pin2 = MICROPY_HW_UART3_CTS;
                GPIO_Port2 = MICROPY_HW_UART3_HSK;

            }
            #endif
            __USART3_CLK_ENABLE();
            break;
        #endif

Post Reply