How do I compile optiboot for 57600 Baud ? (Solved) - Page 1
Forum section: electronics / beginners

author: chris_leyson
author_rank: Super Contributor
timestamp: May 05, 2018, 08:45:34 pm
content: I must be doing something wrong because I can't get optiboot to compile properly for 57600 Baud or any other Baud rate for that matter.I'm using the latest sources from Github with the included makefiles.If I compile usingmake atmega328 BAUD_RATE=115200then every thing works fine at 115200 Baud, but if I compile usingmake atmega328 BAUD_RATE=57600the Baud rate is still 115200 and all that I can see changing in the .lst file isCode:#if LED_START_FLASHES > 0// Set up Timer 1 for timeout counterTCCR1B = _BV(CS12) | _BV(CS10); // div 10247e10:85 e0ldir24, 0x05; 57e12:80 93 81 00sts0x0081, r24UCSRA = _BV(U2X); //Double speed mode USARTUCSRB = _BV(RXEN) | _BV(TXEN); // enable Rx & TxUCSRC = _BV(URSEL) | _BV(UCSZ1) | _BV(UCSZ0); // config USART; 8N1UBRRL = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 );#elseUART_SRA = _BV(U2X0); //Double speed mode USART07e16:82 e0ldir24, 0x02; 27e18:80 93 c0 00sts0x00C0, r24UART_SRB = _BV(RXEN0) | _BV(TXEN0);7e1c:88 e1ldir24, 0x18; 247e1e:80 93 c1 00sts0x00C1, r24UART_SRC = _BV(UCSZ00) | _BV(UCSZ01);7e22:86 e0ldir24, 0x06; 67e24:80 93 c2 00sts0x00C2, r24UART_SRL = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 );7e28:80 e1ldir24, 0x10; 167e2a:80 93 c4 00sts0x00C4, r24#endif#endifCode:#if LED_START_FLASHES > 0// Set up Timer 1 for timeout counterTCCR1B = _BV(CS12) | _BV(CS10); // div 10247e10:85 e0ldir24, 0x05; 57e12:80 93 81 00sts0x0081, r24UCSRA = _BV(U2X); //Double speed mode USARTUCSRB = _BV(RXEN) | _BV(TXEN); // enable Rx & TxUCSRC = _BV(URSEL) | _BV(UCSZ1) | _BV(UCSZ0); // config USART; 8N1UBRRL = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 );#elseUART_SRA = _BV(U2X0); //Double speed mode USART07e16:82 e0ldir24, 0x02; 27e18:80 93 c0 00sts0x00C0, r24UART_SRB = _BV(RXEN0) | _BV(TXEN0);7e1c:88 e1ldir24, 0x18; 247e1e:80 93 c1 00sts0x00C1, r24UART_SRC = _BV(UCSZ00) | _BV(UCSZ01);7e22:86 e0ldir24, 0x06; 67e24:80 93 c2 00sts0x00C2, r24UART_SRL = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 );7e28:82 e2ldir24, 0x22; 347e2a:80 93 c4 00sts0x00C4, r24#endif#endifThe only difference between the the two .lst files is UART_SRL = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 ); but that doesn't change the Baud rate, it's still 115200. ??It looks like I've got my "make" commannd line arguments wrong, maybe. I'm a hardware guy and when I write in C I try to avoid using define statements and only use them if necessary or useful... and makefiles don't help when things get re-defined. How the hell do I trace compile time variables there must be tools to do this sort of thing but as I'm a hardware guy I'm not aware of them any pointers would be appreciated.I really need to drop the Baud rate between the USB to serial interface and the processor. There is a cable in between the ATmega16U2 and ATmega328P as well as RS485 transmitters and receivers with slew rate limiting. Serial comms between the two doesn't work at 115200, it works fine at 57600.Any help would be greatly appreciated.CheersChris

author: rstofer
author_rank: Super Contributor
timestamp: May 05, 2018, 09:23:08 pm
content: I don't think your Makefile is passing the parameterhttps://docs.oracle.com/cd/E19504-01/802-5880/make-28/index.htmlhttps://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html#Preprocessor-OptionsYou can pass a parameter at the command line to the Makefile and the Makefile can, in turn, pass it to the preprocessor.

author: chris_leyson
author_rank: Super Contributor
timestamp: May 06, 2018, 12:06:44 pm
content: To be honest it was a dumb question because there was nothing wrong with the make file and the parameters were getting passed to the compiler and the values for UART_SRL are correct. I should have read the lst files and I guess I probably uploaded the wrong hex file at one point.Anyway optiboot bootloader now working at 9600, 19200, 38400 and 115200I've been testing it on an Arduino UNO Rev 3 to rule out and problems with custom hardware and I can't get he bootloader to work reliably at 57600 because I get the programmer not responding message either straight away or sometimes after avrdude has read the chip parameters. It's strange because a simple serial loopback sketch that runs at 57600 Baud works OK with no errors. It needs more investigation when I have time.