WIZnet Developer Forum

Configure UART0 (PB_2,PB_3) on mbed

Hi,

The mbed freezes when configuring the UART0 on PB_02/PB_03 (W7500).

I’ve also tried to set the alternate function but does’t work.

//configure alternate function
HAL_PAD_AFConfig(PAD_PB,GPIO_Pin_0, PAD_AF2);
HAL_PAD_AFConfig(PAD_PB,GPIO_Pin_1, PAD_AF2);
HAL_PAD_AFConfig(PAD_PB,GPIO_Pin_2, PAD_AF2);
HAL_PAD_AFConfig(PAD_PB,GPIO_Pin_3, PAD_AF2);

//initialize serial on UART0
Serial serial(PB_2, PB_3); // tx, rx

Any idea?

Best regards

Hello, joaopaulob

I think you do not need to use HAL_PAD_AFConfig()

Only you need to declare Serial Class : Serial serial(PB_2, PB_3);

But if even you success the compile, it does not work.

You must change D0(U0_RX), D1(U0_TX) alternative function to GPIO.

Because the D0, D1 order is stronger then PB_2, PB_3 ( I think… )

Thank you,

lawrence

like this…

Digital Output(D0);
Digital Output(D1);

Serial serial(PB_2, PB_3);

Change the D0, D1 function and declare PB_2, PB_3 as UART0.

Lawrence,

I did:

DigitalOut dummy1(PA_13); //D1
DigitalOut dummy2(PA_14); //D0

When I call the function ( Serial serial(PB_2, PB_3) ) I got the error “pinmap not found for peripheral”.

It looks like the mbed do not allow to use these pins for UART0.

Any idea?

Best regards,

hello, joaopaulob

This is what I captured on my web compiler.

Could check your compiler with below lists?

  1. Did you select WIZwiki-W7500 as Web compiler Platform board?
    -> refer the right side and up in that capture.
  2. Try to update mbed library.

Thank you

lawrence

Hi Lawrence,

The program compile successfully, but it freezes on running.

Try to run the following code:

#include "mbed.h"

Serial debug(PC_2, PC_3); //This is my terminal debug UART1
 
int main() {
    
    DigitalOut myled(PA_13);
    DigitalOut urled(PA_14);
    
    debug.baud(115200);
    
    debug.printf("Initializing... \r\n");
    
    Serial device(PB_2, PB_3); // This is the UART0. ->> It freezes here and prints on terminal debug "pinmap not found for peripheral"
    device.baud(9600);

    while(1)
    {
        device.printf("Device UART0 debug \r\n");
        debug.printf("Terminal UART1 debug \r\n");
        wait_ms(600);
    }
} 

Best regards

hello, joaopaulob

Thank you so much!

You are Right!..

It is my fault… I never thought about mbed library.

WIZnet missed add PB_2 and PB_3 in Serial pin map.

Refer below capture.

So… Now you have two solutions.

  1. Change mbed to mbed-dev and Add PB_2 , PB_3 in PeripheralPins.c
    //*** SERIAL ***
    const PinMap PinMap_UART_TX[] = {
        {PA_13, UART_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_PULLUP, Px_AFSR_AF0)},
        {PC_2,  UART_1, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_PULLUP, Px_AFSR_AF0)},
        {PB_2,  UART_1, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_PULLUP, Px_AFSR_AF0)},
        {NC,    NC,     0}
    };

    const PinMap PinMap_UART_RX[] = {
        {PA_14, UART_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_PULLUP, Px_AFSR_AF0)},
        {PC_3,  UART_1, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_PULLUP, Px_AFSR_AF0)},
        {PB_3,  UART_1, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_PULLUP, Px_AFSR_AF0)},
        {NC,    NC,     0}
    };
  1. Use another pin as UART0 , PC_2, PC_3.

Thank you

lawrence

Found a way to “hack” the mbed:

#include "mbed.h"
#include "W7500x_uart.h"

UART_InitTypeDef UART_InitStructure0;

int main() {
    
    Serial rfid(PA_13, PA_14);
    
    DigitalOut dummy1(PA_13);
    DigitalOut dummy2(PA_14);
    
    // Reconfigure to PB2 and PB3
    HAL_PAD_AFConfig(PAD_PB,GPIO_Pin_2, PAD_AF2);
    HAL_PAD_AFConfig(PAD_PB,GPIO_Pin_3, PAD_AF2);
    
    UART_StructInit(&UART_InitStructure0);
    UART_InitStructure0.UART_BaudRate = 9600;
    UART_Init(UART0,&UART_InitStructure0);


    rfid.putc(0xAA);

}

Copyright © 2017 WIZnet Co., Ltd. All Rights Reserved.