Author Topic: How do I compile optiboot for 57600 Baud ? (Solved)  (Read 1738 times)

0 Members and 1 Guest are viewing this topic.

Offline chris_leysonTopic starter

  • Super Contributor
  • ***
  • Posts: 1542
  • Country: wales
How do I compile optiboot for 57600 Baud ? (Solved)
« on: May 05, 2018, 08:45:34 pm »
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

Code: [Select]
#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

Code: [Select]
#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


« Last Edit: May 06, 2018, 10:45:32 am by chris_leyson »
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9915
  • Country: us
Re: How do I compile optiboot for 57600 Baud ?
« Reply #1 on: May 05, 2018, 09:23:08 pm »
I don't think your Makefile is passing the parameter

https://docs.oracle.com/cd/E19504-01/802-5880/make-28/index.html

https://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html#Preprocessor-Options

You can pass a parameter at the command line to the Makefile and the Makefile can, in turn, pass it to the preprocessor.
 

Offline chris_leysonTopic starter

  • Super Contributor
  • ***
  • Posts: 1542
  • Country: wales
Re: How do I compile optiboot for 57600 Baud ? (Solved)
« Reply #2 on: May 06, 2018, 12:06:44 pm »
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.  :palm:

Anyway optiboot bootloader now working at 9600, 19200, 38400 and 115200  :-+
I'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.
« Last Edit: May 06, 2018, 12:12:18 pm by chris_leyson »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf