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 using make atmega328 BAUD_RATE=115200 then every thing works fine at 115200 Baud, but if I compile using make atmega328 BAUD_RATE=57600 the Baud rate is still 115200 and all that I can see changing in the .lst file is
#if LED_START_FLASHES > 0
// Set up Timer 1 for timeout counter
TCCR1B = _BV(CS12) | _BV(CS10); // div 1024
7e10: 85 e0 ldi r24, 0x05 ; 5
7e12: 80 93 81 00 sts 0x0081, r24
UCSRA = _BV(U2X); //Double speed mode USART
UCSRB = _BV(RXEN) | _BV(TXEN); // enable Rx & Tx
UCSRC = _BV(URSEL) | _BV(UCSZ1) | _BV(UCSZ0); // config USART; 8N1
UBRRL = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 );
#else
UART_SRA = _BV(U2X0); //Double speed mode USART0
7e16: 82 e0 ldi r24, 0x02 ; 2
7e18: 80 93 c0 00 sts 0x00C0, r24
UART_SRB = _BV(RXEN0) | _BV(TXEN0);
7e1c: 88 e1 ldi r24, 0x18 ; 24
7e1e: 80 93 c1 00 sts 0x00C1, r24
UART_SRC = _BV(UCSZ00) | _BV(UCSZ01);
7e22: 86 e0 ldi r24, 0x06 ; 6
7e24: 80 93 c2 00 sts 0x00C2, r24
UART_SRL = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 );
7e28: 80 e1 ldi r24, 0x10 ; 16
7e2a: 80 93 c4 00 sts 0x00C4, r24
#endif
#endif
#if LED_START_FLASHES > 0
// Set up Timer 1 for timeout counter
TCCR1B = _BV(CS12) | _BV(CS10); // div 1024
7e10: 85 e0 ldi r24, 0x05 ; 5
7e12: 80 93 81 00 sts 0x0081, r24
UCSRA = _BV(U2X); //Double speed mode USART
UCSRB = _BV(RXEN) | _BV(TXEN); // enable Rx & Tx
UCSRC = _BV(URSEL) | _BV(UCSZ1) | _BV(UCSZ0); // config USART; 8N1
UBRRL = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 );
#else
UART_SRA = _BV(U2X0); //Double speed mode USART0
7e16: 82 e0 ldi r24, 0x02 ; 2
7e18: 80 93 c0 00 sts 0x00C0, r24
UART_SRB = _BV(RXEN0) | _BV(TXEN0);
7e1c: 88 e1 ldi r24, 0x18 ; 24
7e1e: 80 93 c1 00 sts 0x00C1, r24
UART_SRC = _BV(UCSZ00) | _BV(UCSZ01);
7e22: 86 e0 ldi r24, 0x06 ; 6
7e24: 80 93 c2 00 sts 0x00C2, r24
UART_SRL = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 );
7e28: 82 e2 ldi r24, 0x22 ; 34
7e2a: 80 93 c4 00 sts 0x00C4, r24
#endif
#endif
The 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.
Cheers
Chris