USBSerial in the Portenta Machine control

Hi, new here. I am trying to establish a Serial communication over USB-A port in the Portenta Machine Control. I came across this and this link like more or less what i am looking for. But which one i can use to make the communication/connection work. I have USB-TTL module with me, so i can test with this module whether some dummy data is transmitting(TX) or receiving(RX) with the help of noticing the led indication in the module. Also i tried to do establish the communication, did not work out.
arduino code

#include <mbed.h>
#include <USBSerial.h>
#include "greentea-client/test_env.h"

#define MSG_VALUE_DUMMY "0"
#define CDC_LOOPBACK_REPS 1200
#define SERIAL_LOOPBACK_REPS 100
#define MSG_KEY_PORT_OPEN_WAIT "port_open_wait"
#define USB_DEV_SN_LEN (32)
char usb_dev_sn[USB_DEV_SN_LEN + 1];

USBSerial cdc(true, 0x10c4, 0xea60, 0x0001);

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);

}

void loop() {
  cdc.configured();
  cdc.ready();

  cdc.connect();
  while(!cdc.configured()){
    Serial.println("cdc not configured");
    delay(1);
  }

  greentea_send_kv(MSG_KEY_PORT_OPEN_WAIT, MSG_VALUE_DUMMY);

  cdc.wait_ready();
  uint8_t rx_buff, tx_buff;
  for(int i = 0; i < CDC_LOOPBACK_REPS; i++){
    tx_buff = static_cast<uint8_t>(rand() % 0x100);
    rx_buff = static_cast<uint8_t>(tx_buff + 1);
    cdc.send(&tx_buff, 1);
    Serial.println("Sending: %02X\n");
    if (tx_buff < 0x10) Serial.print("0"); 
      Serial.println(tx_buff, HEX);
    cdc.receive(&rx_buff, 1, NULL);
    assert(tx_buff== rx_buff);
    Serial.print("Received: 0x");
    if (rx_buff < 0x10) Serial.print("0");
    Serial.println(rx_buff, HEX); 
   
  }
  cdc.disconnect();

  Serial.println("Hello world");
  delay(1000);
}

Nothing happening, and nothing in the serial monitor. I am kinda lost. If someone help me with this, it will be so helpful. Thanks in Advance

Hello,

It is hard to help because Portenta is little bit expensive for play and also it is not Mbed enabled board, so I can give you just basic tips.

  • I do not know what you want to do with USBSerial and USB-TTL. USB-TTL is good for standart UART with TX/RX but definitly not for USB D+/D-
  • usually is good to start from the example of requested API and how it will work then modify it according to your requirements
  • App on host side have to manage DTR signal, that is probably the reason you see nothing in serial terminal
  • Lines of code below have no point when you have set true in first paramater of the constructor. The USBSerial is set to blocking in the default. That mean it waits for a connection from opposite side, that is the reason why your code not reach the main. So until you not connect a terminal application on your pc to a correct port nothing will happen.
  cdc.configured();
  cdc.ready();

  cdc.connect();
  while(!cdc.configured()){
    Serial.println("cdc not configured");
    delay(1);
  }

BR, Jan

@JohnnyK Thanks for showing up, there is a purpose of using serial over USB-A port in the PMC, to read the battery data from the BMS. Although there’s a reference(this) for reading the bms data. I am using the USB_TTL module for just testing(make sure i can transmit and receive data), instead of using BMS. Now you can see where i am heading with this.
i changed the constructor from true to false,
the output in the serial monitor is
"cdc not configured"

Please do not understand me wrong, but I am still not sure we are on same wave.

From my understanding you want to connect PMC with Daly BMS to get some data about battery state and so on.
However according to your link the BMS communicate over UART (Tx/Rx) so you can not connect it to USBA because that is real USB. You have to connect it to an UART of PMC.

BR, Jan

Alright, I understand your point… As. Per the datasheet The USB-A port can act as a host, you can also see the USB-A description in the page 24. so I can read the data through this port from a device right? I am not well aware of this PMC board. Let me know if I am wrong.
Note: I did not find any useful support on how to use the USB-A port in the PMC

Yeah, that is really written there and it is probably possible. But it does not matter what this USB can act, it is still USB and not UART. It is similar like with PC, you can not connect UART directly to USB without any convertor like your USB to TTL is but PC has a driver for that.

BR, Jan

Thanks @JohnnyK. Anyway, i am gonna keep work on that, and i will update here.

I found Daly BMS usually provides RS485 so you can try to connect it to RS485 also on PMC instead of USB what si not possible. But Daly produces many variants of this BMS so maybe is cool to have exact name for exact datasheet.

Merry Christmas

BR, Jan

Noted your thoughts. i will get back here either way i fail or succeed on this.

I have bought this PMC also, I thought it could be useful for our company products. But I’ve seen now that the SWD pins PA13/PA14 are used for some IO stuff, incredible. So no hardware debugging possible, it is really unbelievable how Arduino CC can do that. And this is called ‘Arduino Pro’, but they still think that Pro’s are not able to use a debugger.

Ok, shut down PC now,
merry Xmas!

1 Like

Approached the arduino support, they said the USB-UART converter(CH340) module comes with BMS does not compatable with Arduino Portenta H7 board. So no matter what libraries we use, it won’t work out. I don’t know whether i close this issue or not, maybe it can help others. BTW, thanks @JohnnyK for your thoughts. Appreciate it.