SparkFun Forums 

Where electronics enthusiasts find answers.

Tips, tricks, & best best practices using Artemis with your board designs.
User avatar
By bm16ton
#235735
The artemis reboots when serial connection is made so arduino can put it into bootloader and upload code. This well bluntly sucks and breaks/complicates so many projects and other issues. I beg of you to explore a different strategy with new designs like the request for a specific baud thats the standard these days. But If you cant have it work that way and are running linux heres the fix. grab your kernel source edit "drivers/usb/serial/ch341.c" goto the ops table and comment out the dtr op, so turn;

static struct usb_serial_driver ch341_device = {
.driver = {
.owner = THIS_MODULE,
.name = "ch341-uart",
},
.id_table = id_table,
.num_ports = 1,
.open = ch341_open,
.dtr_rts = ch341_dtr_rts, <<<<<<<<< THIS LINE NEEDS COMENTING OUT
.carrier_raised = ch341_carrier_raised,
.close = ch341_close,
.set_termios = ch341_set_termios,
.break_ctl = ch341_break_ctl,
.tiocmget = ch341_tiocmget,
.tiocmset = ch341_tiocmset,
.tiocmiwait = usb_serial_generic_tiocmiwait,
.read_int_callback = ch341_read_int_callback,
.port_probe = ch341_port_probe,
.port_remove = ch341_port_remove,
.reset_resume = ch341_reset_resume,
};

TO

static struct usb_serial_driver ch341_device = {
.driver = {
.owner = THIS_MODULE,
.name = "ch341-uart",
},
.id_table = id_table,
.num_ports = 1,
.open = ch341_open,
/* .dtr_rts = ch341_dtr_rts, */
.carrier_raised = ch341_carrier_raised,
.close = ch341_close,
.set_termios = ch341_set_termios,
.break_ctl = ch341_break_ctl,
.tiocmget = ch341_tiocmget,
.tiocmset = ch341_tiocmset,
.tiocmiwait = usb_serial_generic_tiocmiwait,
.read_int_callback = ch341_read_int_callback,
.port_probe = ch341_port_probe,
.port_remove = ch341_port_remove,
.reset_resume = ch341_reset_resume,
};

You can still trigger dtr via standard ioctls, so now if your kernel source has already been compiled once without a make clean just run "make drivers/usb/serial/ch341.ko" and copy the new ch341.ko over the old one or into an appropriate module updates folder. Now to tigger reset via softwre a simple c app. save the following code in a file names arty-reset.c


#include <stdio.h>
#include <fcntl.h> /* File Control Definitions */
#include <termios.h> /* POSIX Terminal Control Definitions */
#include <unistd.h> /* UNIX Standard Definitions */
#include <errno.h> /* ERROR Number Definitions */
#include <sys/ioctl.h> /* ioctl() */
void main( int argc, char *argv[] )
{
int fd; /*File Descriptor*/


if( argv[1] == 0 ) {
printf("\n Please supply serial name IE /dev/ttyACM0 \n");
return;
}
fd = open(argv[1], O_RDWR | O_NOCTTY );

int DTR_flag;
int RTS_flag;
DTR_flag = TIOCM_DTR;
RTS_flag = TIOCM_RTS;

ioctl(fd,TIOCMBIS,&DTR_flag);

ioctl(fd,TIOCMBIC,&DTR_flag);
close(fd);
fd = open(argv[1], O_RDWR | O_NOCTTY );
ioctl(fd,TIOCMBIS,&RTS_flag);
close(fd);
}

compile it with "gcc -o arty-reset arty-reset.c" after run with serial port as option IE "./arty-reset /dev/ttyUSB0" This could be written in pyhon and added to svl uploader script but i hate python so ill leave it. Should be able to call this from that svl script or good chance calling it in platform file just before svl would work depending how slow python is (dont bet the farm on it without testing) But ive seen it asked before how to do this with official response beig you cant via software alone and hardware hacks would be required, simply not the case. This whole thing could be spruced up to only apply to specific boards etc as well. Hope this helps. Oh i may refuse to use windows but its possible and even easier on windows to block dtr triggering as well.
 Topic permissions

You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum