const AP_HAL::HAL& hal = AP_HAL::get_HAL();
AP_HAL::UARTDriver *uart = hal.serial(4); // tried 0, 1, 2, 3, and 4
uart->begin(1000000); // tried other baud rates as well
COM port is not available and cannot connect to mission planner. But if I initialize the uart later through some other function the problem does not appear. Any ideas on why might that happens?
No idea why the UART isn’t initializing, but you’ll never get a valid connection to Mission Planner without sending MavLink (which is far more complex than a single byte message).
Thanks for the response but I didn’t really get what you mean. What I probably did not make clear enough is that I try to connect to Mission Planner with a USB (the normal way). The uart is just configured for another use (to interface a device), but I think it somehow messes with the whole system when initialized early in the code (perhaps the drivers for uarts don’t have enough time to load). In my case I need to send messages with a custom format to interface a device not supported by the current firmware.
Btw, I was wondering how to configure serialx_protocol in the aforementioned case (no predefined protocols - just want to receive and send raw messages). I tried:
none, but the uart output was suppressed
various others, but the output was filled with extra traffic corrupting my messages
scripting, the only one that did not mess with the output but I am not sure if it induces any other issues.