I am upgrade my mbed-os from mbed-os 2 to mbed-os 6.15 for stm32L432KC.
My code has been test on stm32H7xxx, and it proved to work. However, the code is not work on stm32L4xxx.
Could you please let me know that do I need to modify any files in target to make the code work in stm32L4xxx?
/*
* Copyright (c) 2020 Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*/
#include "mbed.h"
// Maximum number of element the application buffer can contain
#define MAXIMUM_BUFFER_SIZE 32
// Create a DigitalOutput object to toggle an LED whenever data is received.
static DigitalOut led(PB_0, 1);
// Create a BufferedSerial object with a default baud rate.
static BufferedSerial serial_port(USBTX, USBRX);
BufferedSerial port1(PA_2, PA_3, 921600);
int main(void)
{
// Set desired properties (9600-8-N-1).
serial_port.set_baud(9600);
serial_port.set_format(
/* bits */ 8,
/* parity */ BufferedSerial::None,
/* stop bit */ 1
);
// Application buffer to receive the data
char buf[MAXIMUM_BUFFER_SIZE] = {0};
while (1) {
if (uint32_t num = port1.read(buf, sizeof(buf))) {
// Toggle the LED.
led = !led;
// Echo the input back to the terminal.
port1.write(buf, num);
}
}
}
```````
your stm32L432KC is Nucleo-L432KC or your own custom target?
what do you mean with “not working”?
did the code work on L432kc and Mbed2?
Tips:
In default is the pin PA_3 not allowed for any serial usage. Probably because is also connected to RX of UART2 that is assigned for default STDOUT.
Pin PA_2 is already use for default STOUT. So if you did not rewrite it via mbed_app.json file, then you have same TX pin of same UART controller for both objects - USBTX = PA_2 in default. If you do not want change default settings, then rather use UART1 on pins PA_9 and PA_10.
Thank you for your reply.
We used our customized PCB board. We can not change the board layout.
The PA3 is connected with PA15. So I changed the PA3 to PA15, RX works. But the TX still does not work.
I am new to mbed os. How can I rewrite PA2 to normal UART2 TX in mbed_app_json.file?
And, yes, the code work on L432KC and mbed2 with Serial. But I am not sure any changes has been made in mbed-os previously by senior engineers.
Macros USBTX, USBRX, used in first object with name serial_port, are pins PA_2 and PA_15 of UART2.
Your second object with name port1 use pins PA_2 and PA_3 (your changed to PA_15), that is also UART2. So you have two objects for one UART and also with two baud rates, that can not work ever. Because…
You declared first object which sets the UART2 to default baud rate 9600. Then you declare second object, which sets baud rate of UART2 to 921600. Then finaly in the main, you set the baud rate of UART2 back to 9600 via first object. So, your code will probably working, but on 9600 instead of 921600.
Another problem is the default debug console which is set to UART2. So you have to disable or redirect it via mbed_app.json
/*
* Copyright (c) 2020 Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*/
#include "mbed.h"
// Maximum number of element the application buffer can contain
#define MAXIMUM_BUFFER_SIZE 32
// Create a DigitalOutput object to toggle an LED whenever data is received.
static DigitalOut led(PB_0, 1);
BufferedSerial port1(PA_2, PA_15, 921600);
int main(void)
{
// Application buffer to receive the data
char buf[MAXIMUM_BUFFER_SIZE] = {0};
while (1) {
if (uint32_t num = port1.read(buf, sizeof(buf))) {
// Toggle the LED.
led = !led;
// Echo the input back to the terminal.
port1.write(buf, num);
}
}
}
What is “the other side” ?
I already tested the code what you posted and it is working. However I have only Nucleo-L432KC so my pins are connected to ST-link’s VCP and I have it connected to YAT (Serial terminal application) on Windows 10.