Skip to content

Conversation

@jeromecoutant
Copy link
Contributor

Fix #19

For information, used command to generate file templates:

python targets/TARGET_STM/tools/STM32_gen_PeripheralPins.py -m "STM32WLE5JCIx.xml"

@jeromecoutant
Copy link
Contributor Author

@hallard @jpmeijers

@jeromecoutant
Copy link
Contributor Author

I added changes for RAK3172. This is a smaller MCU, with less pins.
Please approve this PR if this is OK for you

@hallard
Copy link
Contributor

hallard commented Sep 7, 2021

Quick view looks better now, thanks.

@jpmeijers
Copy link

Looks good to me

@jeromecoutant jeromecoutant merged commit f3a6206 into master Sep 8, 2021
@jeromecoutant jeromecoutant deleted the PR_LORA_PIN branch September 8, 2021 06:52
@hallard
Copy link
Contributor

hallard commented Sep 8, 2021

BTW could you please add a mbed-os-6.14.0 tag?

@hallard
Copy link
Contributor

hallard commented Sep 28, 2021

Guys, I didn't pay attention to pins modified (just looked on ones added) and I just spent time looking from a dirty bug. My BufferedSerial worked fine and does not anymore after this commit. It's connected to PA_2 PA_3 (Named serial 2 on LoRa E5) and since it's now

// PinMap_UART_TX
{PA_2,       UART_2,   STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)},
{PA_2_ALT0,  LPUART_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_LPUART1)},

// PinMap_UART_RX 
{PA_3,       UART_2,   STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)},
{PA_3_ALT0,  LPUART_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_LPUART1)},

And works with old scheme

//PinMap_UART_TX
{PA_2, LPUART_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_LPUART1)}, 

//PinMap_UART_RX 
{PA_3, LPUART_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_LPUART1)},

Not sure of the cause but that change broke the code, any chance to revert back ? I always fixed a nasty bug related to modbus (same pins) few days ago and I'm pretty sure it's related to same things.

@hallard
Copy link
Contributor

hallard commented Sep 28, 2021

Ok, fixed changing my serial declaration

// Instance Serial
//static BufferedSerial modbus_serial(PA_2, PA_3);
static BufferedSerial modbus_serial(PA_2_ALT0, PA_3_ALT0);

And here we go

@jeromecoutant
Copy link
Contributor Author

OK,
I don't see any problem if you want to set back PA_2 with LPUART_1 and PA_2_ALT0 with UART_2

@hallard
Copy link
Contributor

hallard commented Sep 28, 2021

Yeah even if it works otherwise using ALT_0 may be letting default would avoid end user some headache

You mean something like that? @jpmeijers makes sense to you?

// PinMap_UART_TX
{PA_2_ALT0,       UART_2,   STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)},
{PA_2,  LPUART_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_LPUART1)},

// PinMap_UART_RX 
{PA_3_ALT0,       UART_2,   STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)},
{PA_3, LPUART_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_LPUART1)},

@jpmeijers
Copy link

jpmeijers commented Sep 28, 2021

I actually prefer the way it currently is.

UnbufferedSerial pc(PB_6, PB_7); // UART_1
// UnbufferedSerial loop(PA_2, PA_3); // UART_2
// UnbufferedSerial loop(PA_2_ALT0, PA_3_ALT0); // LPUART_1
// UnbufferedSerial loop(PC_1, PC_0); // LPUART_1

PA2/PA3 are the only two pins on which UART2 can be used, so it makes sense keeping them as the default.

LPUART is the only one that can be used on PC0/PC1 and should therefore be the default there.

Which leaves us with LPUART as the "Alternate" function on PA2/PA3 - like it is currently.

Edit:
Why do you specifically want to use LPUART on PA2/PA3, and not the default UART2? For me the expected behaviour should be UART2.

@hallard
Copy link
Contributor

hallard commented Sep 28, 2021

Sounds good to me keeping things like that.

Why do you specifically want to use LPUART on PA2/PA3, and not the default UART2? For me the expected behaviour should be UART2.

Because I'm using 2 Serial devices on 2 different projects, each is connected to PA_2/PA_3 of LoRa E5. Really nothing fancy on serial port communication, just used bufferedSerial and API from start without any issue
But since this change it has stopped to works, on both projects.

So now, since these changes, I changed

static BufferedSerial modbus_serial(PA_2, PA_3);

to

static BufferedSerial modbus_serial(PA_2_ALT0, PA_3_ALT0);

and things worked back again, don't ask me why just using UART2 it does not work, I have no idea, code after serial init in project 2 is simple as that (looking from frame sent on regular basis by serial device)

    while (_sensor_serial.readable())
    {
        uint8_t c;
        _sensor_serial.read(&c, 1);
        // blah blah
    }

@jeromecoutant
Copy link
Contributor Author

jeromecoutant commented Sep 29, 2021

don't ask me why just using UART2 it does not work

Maybe because UART2 is missing in
https://github.com/ARMmbed/mbed-os/blob/master/targets/TARGET_STM/TARGET_STM32WL/serial_device.c#L61-L73

:-(

@jpmeijers
Copy link

jpmeijers commented Sep 29, 2021

Even with that missing my serial loopback works fine. I have a short between PA2 and PA3 and another short between PC1 and PC0.

mbed0s 6.15.0
stm32customtargets master 7b869b6
Target: LORA_E5
Build profile: DEBUG and RELEASE tested

mbed_app.json

{
    "config": {
        "main_stack_size":     { "value": 4096 }
    },
    "target_overrides": {
        "*": {
            "platform.stdio-convert-newlines": true,
            "platform.stdio-baud-rate": 115200,
            "platform.default-serial-baud-rate": 115200,
            "mbed-trace.enable": false,
            "mbed-trace.max-level": "TRACE_LEVEL_DEBUG"
        }
    }
}

main.cpp

#include "mbed.h"

UnbufferedSerial pc(PB_6, PB_7); // UART_1
UnbufferedSerial loop(PA_2, PA_3); // UART_2
// UnbufferedSerial loop(PA_2_ALT0, PA_3_ALT0); // LPUART_1
// UnbufferedSerial loop(PC_1, PC_0); // LPUART_1

int main()
{
    printf("Startup\n");
    char byteRead = 0;
    while (true) {
        while(pc.readable()) {
            pc.read(&byteRead, 1);
            loop.write(&byteRead, 1);
        }
        while(loop.readable()) {
            loop.read(&byteRead, 1);
            pc.write(&byteRead, 1);
        }
    }
}

And also testing both UART2 and LPUART at the same time works

#include "mbed.h"

UnbufferedSerial pc(PB_6, PB_7); // UART_1
UnbufferedSerial loop(PA_2, PA_3); // UART_2
// UnbufferedSerial loop(PA_2_ALT0, PA_3_ALT0); // LPUART_1
UnbufferedSerial loopLp(PC_1, PC_0); // LPUART_1

int main()
{
    printf("Startup\n");
    char byteRead = 0;
    while (true) {
        while(pc.readable()) {
            pc.read(&byteRead, 1);
            loop.write(&byteRead, 1);
            loopLp.write(&byteRead, 1);
        }
        while(loop.readable()) {
            loop.read(&byteRead, 1);
            pc.write(&byteRead, 1);
        }
        while(loopLp.readable()) {
            loopLp.read(&byteRead, 1);
            pc.write(&byteRead, 1);
        }
    }
}
[09:16:16:190] Startup␍␊
[09:16:20:980] asfasdfasd␍␊ -- only PA2/PA3 shorted
[09:16:30:445] aassffaassddffaassdd␍␍␊ -- PA2/PA3 and PC1/PC0 shorted

Maybe something else in @hallard's code is interfering with UART2? @hallard can you maybe run this simple loopback program and see if that works for you?

@jeromecoutant
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LORA E5 - LPUART and other UART pins

4 participants