Added baud rate changing on the fly to serial pass through

This commit is contained in:
Raphael Coeffic
2021-11-21 11:18:35 +01:00
committed by Raphael Coeffic
parent f3301e6210
commit c5c2829c24
2 changed files with 26 additions and 6 deletions
+26 -4
View File
@@ -870,8 +870,21 @@ static void spInternalModuleTx(uint8_t* buf, uint32_t len)
intmoduleWaitForTxCompleted(); intmoduleWaitForTxCompleted();
} }
static void spInternalModuleSetBaudRate(uint32_t baud)
{
etx_serial_init params;
params.baudrate = baud;
params.rx_enable = true;
// just in case...
intmoduleWaitForTxCompleted();
// re-configure serial port
intmoduleSerialStart(&params);
}
// TODO: use proper method instead
extern bool cdcConnected; extern bool cdcConnected;
uint32_t usbSerialFreeSpace();
int cliSerialPassthrough(const char **argv) int cliSerialPassthrough(const char **argv)
{ {
@@ -896,8 +909,8 @@ int cliSerialPassthrough(const char **argv)
err = toInt(argv, 3, &baudrate); err = toInt(argv, 3, &baudrate);
if (err == -1) return err; if (err == -1) return err;
if (err == 0) { if (err == 0) {
serialPrint("%s: missing baudrate", argv[0]); // use current USB CDC baudrate
return -1; baudrate = usbSerialBaudRate();
} }
if (!strcmp("rfmod", port_type)) { if (!strcmp("rfmod", port_type)) {
@@ -931,11 +944,16 @@ int cliSerialPassthrough(const char **argv)
auto backupCB = cliReceiveCallBack; auto backupCB = cliReceiveCallBack;
cliReceiveCallBack = spInternalModuleTx; cliReceiveCallBack = spInternalModuleTx;
// setup CDC baudrate callback
usbSerialSetBaudRateCb(spInternalModuleSetBaudRate);
// loop until cable disconnected // loop until cable disconnected
while (cdcConnected) { while (cdcConnected) {
uint8_t data; uint8_t data;
if (intmoduleFifo.pop(data)) { if (intmoduleFifo.pop(data)) {
GPIO_SetBits(EXTMODULE_TX_GPIO, EXTMODULE_TX_GPIO_PIN);
uint8_t timeout = 10; // 10 ms uint8_t timeout = 10; // 10 ms
while(!usbSerialFreeSpace() && (timeout > 0)) { while(!usbSerialFreeSpace() && (timeout > 0)) {
delay_ms(1); delay_ms(1);
@@ -943,14 +961,18 @@ int cliSerialPassthrough(const char **argv)
} }
usbSerialPutc(data); usbSerialPutc(data);
GPIO_ResetBits(EXTMODULE_TX_GPIO, EXTMODULE_TX_GPIO_PIN);
} }
// keep us up & running // keep us up & running
WDG_RESET(); WDG_RESET();
} }
// restore CLI input // restore callsbacks
usbSerialSetBaudRateCb(nullptr);
cliReceiveCallBack = backupCB; cliReceiveCallBack = backupCB;
// and stop module
intmoduleStop(); intmoduleStop();
} }
#endif #endif
@@ -133,8 +133,6 @@ void intmoduleSerialStart(const etx_serial_init* params)
USART_Cmd(INTMODULE_USART, ENABLE); USART_Cmd(INTMODULE_USART, ENABLE);
if (params->rx_enable) { if (params->rx_enable) {
// TODO: move into the caller
intmoduleFifo.clear();
USART_ITConfig(INTMODULE_USART, USART_IT_RXNE, ENABLE); USART_ITConfig(INTMODULE_USART, USART_IT_RXNE, ENABLE);
NVIC_SetPriority(INTMODULE_USART_IRQn, 6); NVIC_SetPriority(INTMODULE_USART_IRQn, 6);
NVIC_EnableIRQ(INTMODULE_USART_IRQn); NVIC_EnableIRQ(INTMODULE_USART_IRQn);