I am using L432KB, but it has same structure as L432KC, B and C means the flash memory size. I tried to upgrade my mbed-os from 5.15 to 6.15.
mbed-os 6.15 support L432KC.
In mbed 5.15, I used Serial for UART, but in mbed 6.15, UART has been deprecated. I can’t use Serial.getc() and Serial.printf() any more.
I am try to using BufferedSerial and UnbufferedSerial with the example code. I could upload code to the chip. But neither of them work for me.
But the code works fine on my H743ZI2 board. Is it possible to give me some guides or instruction for how to implement read() and write() on L432KB.
#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(PA_0);
// Create a BufferedSerial object with a default baud rate.
static BufferedSerial serial_port(PA_2, PA_15);
int main(void)
{
// Set desired properties (9600-8-N-1).
serial_port.set_baud(912600);
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 = serial_port.read(buf, sizeof(buf))) {
// Toggle the LED.
led = !led;
// Echo the input back to the terminal.
serial_port.write(buf, num);
}
}
}
/*
* Copyright (c) 2020 Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*/
#include "mbed.h"
// Create a DigitalOutput object to toggle an LED whenever data is received.
static DigitalOut led(PA_0);
// Create a UnbufferedSerial object with a default baud rate.
static UnbufferedSerial serial_port(PA_2, PA_15);
void on_rx_interrupt()
{
char c;
// Toggle the LED.
led = !led;
// Read the data to clear the receive interrupt.
if (serial_port.read(&c, 1)) {
// Echo the input back to the terminal.
serial_port.write(&c, 1);
}
}
int main(void)
{
// Set desired properties (9600-8-N-1).
serial_port.baud(912600);
serial_port.format(
/* bits */ 8,
/* parity */ SerialBase::None,
/* stop bit */ 1
);
// Register a callback to process a Rx (receive) interrupt.
serial_port.attach(&on_rx_interrupt, SerialBase::RxIrq);
}