illegal op

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

I tend to reused code.  I have c & h  files for USART0-3, Timer and PWM, that I simply add the files to a program knowing that it is tried and tested.

 

But on a new project I just started, I added the USART0-3 and Timer as usual, but when the init.c calls the Timer init function, I am getting an illegal op exception.

 

How does one get an illegal op when using Atmel Studio v7?  I mean, why would Atmel Studio insert a bad opcode?

 

Any help would be greatly appreciated.

Kind regards,

David

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

dfansler wrote:
I am getting an illegal op exception.
"exception" ? You mean a PC side problem like a null pointer deref or something? Nothing to do with the AVR32-UC3 code you are trying to build? That might suggest one of the AS7 EXE is corrupt perhaps?

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

dfansler wrote:
I am getting an illegal op exception

You need to give more details: when & where, exactly, do you get that?

 

If you're "reusing" old code, are you sure that the code is valid for the new target ?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


 

clawson wrote:
"exception"? ... Nothing to do with the AVR32-UC3

AVR32 does have "exceptions" - including "Illegal Op-code":

 

 

@dfansler  - So, if it is a run-time exception in the AVR32 - you should be able to use an exception handler to see what's happening ...

 

EDIT

 

@dfansler  - if it is a run-time exception in the AVR32, it tells you where was the offending instruction:

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Thu. Mar 18, 2021 - 09:48 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Andy but I don't think he's talking a bout run-time. I think he means build time.

 

In the past it's true that we have seen problems where compilers create .s that when passed to as then throw "illegal opcode" and maybe that is what he is talking about? But it was that curious use of the word "exception" that caught my eye. If he is compiling and during that seeing some on screen message with the word "exception" rather than "error" in it that suggest some x86/x64 code in the build tools may really have thrown an exception (and illegal ref is the usual source of those).

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

clawson wrote:
 but I don't think he's talking a bout run-time. I think he means build time.

Yes, quite possibly - hence the question in #3, and the "ifs" in #4.

 

@ dfansler  - you need to give more detail.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Check your RAM usage.
You might be corrupting the stack.

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


Hi guys - the problem is at run time - not during the build.  The processor is labelled 32UC3a1512-U  1642 A3QMPA   The best I can tell I am running gcc\avr32\4.4.7

 

Allowing the program to free run (no breakpoints), it ends up at:

    .org  0x008

    // Bus Error Data Fetch.

_handle_Bus_Error_Data_Fetch:

    rjmp $

and the registers are

R00 = 0x00000000 R01 = 0x000000E0 R02 = 0x00000000 R03 = 0x00000000 R04 = 0xFFFFFFFF R05 = 0xFFFF3800 R06 = 0x00000000 R07 = 0x00000000 R08 = 0x40000000 R09 = 0x00000400 R10 = 0x00000005 R11 = 0x00000002 R12 = 0x00000000 

int tc_configure_interrupts(volatile avr32_tc_t *tc, unsigned int channel, const tc_interrupt_t *bitfield)
{
  bool global_interrupt_enabled = Is_global_interrupt_enabled();

  // Check for valid input.
  if (channel >= TC_NUMBER_OF_CHANNELS)
    return TC_INVALID_ARGUMENT;

  // Enable the appropriate interrupts.
  tc->channel[channel].ier = bitfield->etrgs << AVR32_TC_ETRGS_OFFSET |
                             bitfield->ldrbs << AVR32_TC_LDRBS_OFFSET |
                             bitfield->ldras << AVR32_TC_LDRAS_OFFSET |
                             bitfield->cpcs << AVR32_TC_CPCS_OFFSET |
                             bitfield->cpbs << AVR32_TC_CPBS_OFFSET |
                             bitfield->cpas << AVR32_TC_CPAS_OFFSET |
                             bitfield->lovrs << AVR32_TC_LOVRS_OFFSET |
                             bitfield->covfs << AVR32_TC_COVFS_OFFSET;

  // Disable the appropriate interrupts.
  if (global_interrupt_enabled) Disable_global_interrupt();
  tc->channel[channel].idr = (~bitfield->etrgs & 1) << AVR32_TC_ETRGS_OFFSET |
                             (~bitfield->ldrbs & 1) << AVR32_TC_LDRBS_OFFSET |
                             (~bitfield->ldras & 1) << AVR32_TC_LDRAS_OFFSET |
                             (~bitfield->cpcs & 1) << AVR32_TC_CPCS_OFFSET |
                        -->>>>>>     (~bitfield->cpbs & 1) << AVR32_TC_CPBS_OFFSET |
                             (~bitfield->cpas & 1) << AVR32_TC_CPAS_OFFSET |
                             (~bitfield->lovrs & 1) << AVR32_TC_LOVRS_OFFSET |
                             (~bitfield->covfs & 1) << AVR32_TC_COVFS_OFFSET;
  tc->channel[channel].sr;
  if (global_interrupt_enabled) Enable_global_interrupt();

  return 0;
}

Line 25 (with the -->>>>>>>) is where the the program jumps to      location 000040F6  add R0, R0   In fact there are a whole slew of R0, R0 with an occasional --- No source file -------.

 

If I single step thru the program, I get a different exception :

    .org  0x020

    // Illegal Opcode.

_handle_Illegal_Opcode:

    rjmp $

R00 = 0x00000AD8 R01 = 0x00000AD8 R02 = 0x00000000 R03 = 0x00000000 R04 = 0xFFFFFFFF R05 = 0xF7FD3800 R06 = 0x00000000 R07 = 0xF7FD3800 R08 = 0x00004002 R09 = 0x00000000 R10 = 0x0000C002 R11 = 0x00000000 R12 = 0xF7FD3800 

 

 

int tc_init_waveform(volatile avr32_tc_t *tc, const tc_waveform_opt_t *opt)
{
  // Check for valid input.
  if (opt->channel >= TC_NUMBER_OF_CHANNELS)
    return TC_INVALID_ARGUMENT;

  // GENERATE SIGNALS: Waveform operating mode.
-->>>>>  tc->channel[opt->channel].cmr = opt->bswtrg << AVR32_TC_BSWTRG_OFFSET |
                                  opt->beevt << AVR32_TC_BEEVT_OFFSET |
                                  opt->bcpc << AVR32_TC_BCPC_OFFSET |
                                  opt->bcpb << AVR32_TC_BCPB_OFFSET |
                                  opt->aswtrg << AVR32_TC_ASWTRG_OFFSET |
                                  opt->aeevt << AVR32_TC_AEEVT_OFFSET |
                                  opt->acpc << AVR32_TC_ACPC_OFFSET |
                                  opt->acpa << AVR32_TC_ACPA_OFFSET |
                                  1 << AVR32_TC_WAVE_OFFSET |
                                  opt->wavsel << AVR32_TC_WAVSEL_OFFSET |
                                  opt->enetrg << AVR32_TC_ENETRG_OFFSET |
                                  opt->eevt << AVR32_TC_EEVT_OFFSET |
                                  opt->eevtedg << AVR32_TC_EEVTEDG_OFFSET |
                                  opt->cpcdis << AVR32_TC_CPCDIS_OFFSET |
                                  opt->cpcstop << AVR32_TC_CPCSTOP_OFFSET |
                                  opt->burst << AVR32_TC_BURST_OFFSET |
                                  opt->clki << AVR32_TC_CLKI_OFFSET |
                                  opt->tcclks << AVR32_TC_TCCLKS_OFFSET;

  return 0;
}

At the line just under the // GENERATE SIGNALS: - the line with -->>> is where the program jumps to 

    .org  0x020

    // Illegal Opcode.

_handle_Illegal_Opcode:

    rjmp $

 

The int tc_int_waveform() is a part of the tc.c function in src/ASF/avr32/drivers/tc folder.

 

I hope this is enough information to help, unless you need my source code as well.

Thanks,

David

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

1:) Are you pasing a valid address (0xFFF3800 for the 1 timer-module in the UC3Axxx) in volatile avr32_tc_t *tc ?
2:) confirm that TC_NUMBER_OF_CHANNELS is 3
3:) move the call to tc_init_waveform(,,) to somewhere else in your initialization code and see if the problem follows.

Last Edited: Fri. Mar 19, 2021 - 04:32 AM