3 years, 2 months ago.

Serial attach with Nucleo L432KC doesn't work

This code says hello but never stop blinking when one char is sent to Nucleo L432KC

  1. include "mbed.h"
  1. define TX_PIN USBTX
  2. define RX_PIN USBRX
  3. define BRATE 921600
  4. define LED_PIN LED0
  5. define TOGGLE_RATE (0.5f)
  6. define BUFF_LENGTH 4

Serial test_connection(USBTX, USBRX,BRATE);

volatile bool blinking = true;

DigitalOut LED(LED1); uint8_t rx_buf[BUFF_LENGTH + 1];

void blink(void) { if (blinking) { LED = !LED; } }

void serialCb() {

blinking = false; rx_buf[0] = test_connection.getc(); test_connection.write(rx_buf, 1, 0, 0); }

int main() { wait(5.0); test_connection.attach(&serialCb);

test_connection.printf("hello\n"); while (0==0) { blink(); wait(1.0); } }

2 Answers

3 years, 2 months ago.

Please publish correct formatted code that users have a chance to understand what you are doing. The mbed code formatting will allow this. For Tags I recommand STM32L432, Serial

The the serialCb() you set “blinking = false; “ this may be the problem. Another point is I don’t know if the L432KC mbed clock setup allows 921600 baud, try a lower number e.g. 230400 which I verified that this works.

PS: For while (0==0) I usually use while(true) Regards Helmut

Hi, It doesn't work with anyspeed. The behavior awaiting is that blinking stop when one char is received on usb serial port.The problem is that the Serial.attach method doesn't work any more on this controller.I mean no interrupt are trigged, this code works perfect before.

posted by Cyril Canovas 19 Mar 2019

When a code worked before this is no an argument that it is ok, check out the blinking = false logic, reformat the code that other can see it. Break down the code to isolate the problem. It works in my projects as well in Paul’s

posted by Helmut Tschemernjak 20 Mar 2019
3 years, 1 month ago.

Interrupt serial definitely works on the L432KC, I'm using it, @ 921600 baud.

Try this simple program as an example and build your code round it.

https://os.mbed.com/users/sarahmarshy/code/SerialPassthrough/