[PATCH] ATmega162 support Topic is solved

ChibiOS public support forum for topics related to the Atmel AVR family of micro-controllers.

Moderators: utzig, tfAteba

Marco
Posts: 128
Joined: Tue Apr 16, 2013 8:22 pm
Has thanked: 4 times
Been thanked: 11 times

[PATCH] ATmega162 support

Postby Marco » Wed Oct 19, 2016 10:30 am

Hi,

I made some changes to add support for the ATmega162. In the ATmega162 the UCSRC register shares the same I/O location as the UBRRH register. The selected register is determined by the MSb value.

Attached is a patch against trunk.

Marco
Attachments
atmega162.patch.zip
Patch for ATmega162 support
(1.06 KiB) Downloaded 63 times

utzig
Posts: 355
Joined: Sat Jan 07, 2012 6:22 pm
Location: Brazil
Has thanked: 1 time
Been thanked: 19 times
Contact:

Re: [PATCH] ATmega162 support

Postby utzig » Wed Oct 19, 2016 12:50 pm

Applied, thanks!

Some nitpicks without looking at the ATmega162 DS! The #ifdef block below is unnecessary because UBRR0H is probably an 8 bit register so the & 0x0f is superfluous.

Code: Select all

#if defined(__AVR_ATmega162__)
  UBRR0H = (config->sc_brr >> 8) & 0x0f;
#else
   UBRR0H = config->sc_brr >> 8;
#endif

In the code below | 0 might have been added for clarity purposes but not required and not common style.

Code: Select all

#if defined(__AVR_ATmega162__)
  UCSR0C = (1 << URSEL0) | 0;
#else
   UCSR0C = 0;
#endif

Btw, what's your environment? I still get errors when merging your patches on macOS Sierra. Works on Linux passing --binary to patch. You should check your auto.crlf config if using the github mirror.

Cheers,
Fabio Utzig

Marco
Posts: 128
Joined: Tue Apr 16, 2013 8:22 pm
Has thanked: 4 times
Been thanked: 11 times

Re: [PATCH] ATmega162 support

Postby Marco » Wed Oct 19, 2016 2:02 pm

Thanks!

UBRR0H is indeed an 8bit register but the effective bits in that register are bits 0-3. Bit 7 should be 0 to select the UBRR0H register. Since config->sc_brr is 16 bits i thought it would be possible for bit 7 to be 1 causing a write to UCSR0C instead of UBRR0H.

Indeed the | 0 was added for clarity. It can be removed.

I'm currently using git under Windows 7. The patch was created against the svn trunk. Probably that caused some issue with line endings.

Marco

utzig
Posts: 355
Joined: Sat Jan 07, 2012 6:22 pm
Location: Brazil
Has thanked: 1 time
Been thanked: 19 times
Contact:

Re: [PATCH] ATmega162 support  Topic is solved

Postby utzig » Wed Oct 19, 2016 2:39 pm

Marco wrote:UBRR0H is indeed an 8bit register but the effective bits in that register are bits 0-3. Bit 7 should be 0 to select the UBRR0H register. Since config->sc_brr is 16 bits i thought it would be possible for bit 7 to be 1 causing a write to UCSR0C instead of UBRR0H.

Ah, nice! Just re-checked for the other supported MCUs and they don't use the 4 MSb, only ATmega162 has a register selector I think. Maybe the code could as well have the & 0xf for all models removing the #ifdef requirement.


Return to “AVR Support”

Who is online

Users browsing this forum: No registered users and 2 guests