Closed CURTLab closed 4 years ago
Have you tried with Arduino IDE? How do you toggle RTS/DTR? Do you really need to invert twice the signals?
Here you can find a small command line utility for Windows to toggle RTS and DTR lines. Launch it in a CMD window and pass the COMxy port as input parameter.
Example how to use it:
toggle_rts_dtr.exe COM14
Besides hterm, I also tied it with a small python script.
import serial
import time
ser = serial.Serial('COM23', 115200)
while (True):
ser.setDTR(1)
ser.setRTS(0)
time.sleep(0.1)
ser.setDTR(0)
ser.setRTS(1)
time.sleep(0.1)
But same result:
I have found out that the RTS pin control is not reliable, and is dependent on the host. DTR control is always reliable. In my test system using the previously attached app, the RTS pin goes high when I set (on host) to low, and goes low when I set DTR to low. So I don't think that this issue is device (STM32) related, but rather host.
Have you tried to control the DTR / CTS pins of a FTDI usb serial adapter?
And do not rely on hterm. I tried Coolterm and produces weird result:
So I don't know how reliable is python. You should first test it with another device to be sure that it works on that.
I made more test and found out a reliable way to toggle RTS:
Example: start condition: DTR =x; RTS = 0; Then: RTS = 1 followed by DTR = x => RTS will be set on device. RTS = 0 followed by DTR = x => RTS will be cleared on device. wherein x can be 0 or 1, but same value during the process.
Try out this method.
Btw, here an improved version of toggle app (windows exe) which allows to toggle continuously RTS and/or DTR based on key press ('r' for RTS=0, 'R' for RTS=1, 'd' for DTR=0, 'D' for DTR=1, any other to quit.). toggle_rts_dtr.zip
EDIT And this is the sketch I was using for tests (with Arduino IDE):
//-----------------------------------------------------------------------------
uint8 old_dtr, old_rts;
//-----------------------------------------------------------------------------
void usbHook(void)
{
uint8 dtr = usb_cdcacm_get_dtr();
if (old_dtr != dtr)
{
old_dtr = dtr;
// you can toggle a pin instead serial
Serial1.write('D'); Serial1.write('0'+dtr); Serial1.write('\n');
}
uint8 rts = usb_cdcacm_get_rts();
if (old_rts != rts)
{
old_rts = rts;
// you can toggle a pin instead serial
Serial1.write('R'); Serial1.write('0'+rts); Serial1.write('\n');
}
}
//-----------------------------------------------------------------------------
extern void usb_cdcacm_set_hooks(uint8_t, voidFuncPtr);
//-----------------------------------------------------------------------------
void setup()
{
enableDebugPorts();
// initialize digital pin PC13 as an output.
pinMode(LED_BUILTIN, OUTPUT);
Serial1.begin(115200);
old_dtr = usb_cdcacm_get_dtr();
old_rts = usb_cdcacm_get_rts();
Serial1.write('D'); Serial1.write('0'+old_dtr); Serial1.write('\n');
Serial1.write('R'); Serial1.write('0'+old_rts); Serial1.write('\n');
usb_cdcacm_set_hooks(USB_CDCACM_HOOK_IFACE_SETUP, usbHook);
}
//-----------------------------------------------------------------------------
void loop()
{
}
Closed because of no response from the OP
I adapted the
USB-uart-w-signals.ino
example in order to upload firmware to the ESP32 using the STM32 blue pill (STM32f103C8T6). I used the USB Serial RTS & DTR signals to switch pins to bring the ESP32 to the upload mode using the ESP's EN and BOOT (GPIO0) pins. Somehow RTS & DTR is not working correctly. DTR functions sometimes but at the moment RTS never worked. If I put the ESP32 into upload mode manually (BOOT to GND, Short pulse to GND for EN), the upload works.I tried different sketches, like the USBComposite with nearly the same code, but here nothing works.
static RESULT usbNoDataSetup(uint8 request)
inSTM32F1\cores\maple\libmaple\usb\stm32f1\usb_cdcacm.c
which also never trigged for RTS.I tried everything I can, but I have no glue how to further investigate the problem.
Code:
PlatformIO config: