Issues with ATmega328PB support in AS 7

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Here is a list of issues i notices so far with ATmega328PB support in Atmel Studio 7.0.943 (no missing updates in Device Pack Manager, all installed extensions are up to date).

 

Please note that some of the issues may not be specific to the ATmega328PB but i have not bothered to try with other AVRs as target!

 

 

  1. The following bit defines seem to be missing in iom328pb.h:
    ICIE3 (register TIMSK3)
    ICIE4 (register TIMSK4)
    CS40 (register TCCR4B)
    CS41 (register TCCR4B)
    CS42 (register TCCR4B)

     

    ICIE3 and ICIE4 are also missing in the I/O viewer and CS4 is shown as CS3.
     

  2. When manually triggering an interrupt in the simulator by setting an interrupt flag in the I/O viewer (like TOV1 in TIFR1) the interrupt routine seems to be entered with global interrupts enabled (SREG_I set).

    Actually this seems to be only an display/update issue between the AS UI and the simulator!
    In both, the "Processor Status" view and the "Autos" view (Autos->Floating point registersfrown->SREG->Value) SREG_I is shown as set BUT when stepping through the disassembly one can see that in the SREG value saved on the stack SREG_I is not set!
    Also triggering another interrupt while the first is executed does not cause nested execution!

    0x23 in R0 versus 0xA3 in the Autos view in the screenshot below:
    wrong SREG value
     

  3. Maybe i'm missing something but it seems to me that GCC is generating very inefficient code when accessing multiple members of a struct.

    The following code

      if (g_pConfiguration->m_Tube2Enabled)
      {
        TIMSK3 |= (1 << ICIE3) | (1 << TOIE3);
      }
    
      if (g_pConfiguration->m_Tube3Enabled)
      {
        TIMSK4 |= (1 << ICIE4) | (1 << TOIE4);
      }
    

    gets compiled to

      if (g_pConfiguration->m_Tube2Enabled)
    00000191  LDS R30,0x0100		Load direct from data space
    00000193  LDS R31,0x0101		Load direct from data space
    00000195  LDD R25,Z+1		Load indirect with displacement
    00000196  TST R25		Test for Zero or Minus
    00000197  BREQ PC+0x06		Branch if equal
        TIMSK3 |= (1 << ICIE3) | (1 << TOIE3);
    00000198  LDS R25,0x0071		Load direct from data space
    0000019A  ORI R25,0x21		Logical OR with immediate
    0000019B  STS 0x0071,R25		Store direct to data space
      if (g_pConfiguration->m_Tube3Enabled)
    0000019D  LDS R30,0x0100		Load direct from data space
    0000019F  LDS R31,0x0101		Load direct from data space
    000001A1  LDD R25,Z+2		Load indirect with displacement
    000001A2  TST R25		Test for Zero or Minus
    000001A3  BREQ PC+0x06		Branch if equal
        TIMSK4 |= (1 << ICIE4) | (1 << TOIE4);
    000001A4  LDS R25,0x0072		Load direct from data space
    000001A6  ORI R25,0x21		Logical OR with immediate
    000001A7  STS 0x0072,R25		Store direct to data space
    

    g_pConfiguration is global a non-volatile const pointer to a struct. Non of the struct members a volatile.

    Is there any reason why the compiler loads the pointer value again from memory (19D and 19F) for the second member access other than a missed optimization?

    [Update: Compiler flags: -x c -funsigned-char -funsigned-bitfields -DNDEBUG -Os -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -g2 -Wall -Wextra -Wundef -pedantic -mmcu=atmega328pb -c -std=gnu99 -MD -MP -MF]

 

Bertolt

 

 

 

Last Edited: Thu. Jun 2, 2016 - 06:40 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bmildner wrote:
other than a missed optimization?
Nope, that's what it looks like. Nothing changes Z there so it should be able to reuse the value it already loaded. Donations to the compiler operation always welcome ;-)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bmildner wrote:

The following bit defines seem to be missing in iom328pb.h:

  1. ICIE3 (register TIMSK3)
    ICIE4 (register TIMSK4)
    CS40 (register TCCR4B)
    CS41 (register TCCR4B)
    CS42 (register TCCR4B)

     

    ICIE3 and ICIE4 are also missing in the I/O viewer and CS4 is shown as CS3.
     

Fixed, will be available in the next release of Atmel Studio/mega partpack

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you MannImMond!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Who are actually in charge for the "Atmel" compiler? (some we know from here?)

 

But in general there are many things the compiler misses (and then other things that are fine), so unless you pay for the compiler don't expect that everything is perfect. (but expect that it works)

For things like the example it often make better code if you use a local pointer.

But real optimal code need use of ASM.