can anyone analys this code or give codevision equivalent

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

(__extension__({ \

uint8_t __result; \

__asm__ __volatile__ \

( \

"sts %1, %2\n\t" \

"lpm %0, Z" "\n\t" \

: "=r" (__result) \

: "i" (_SFR_MEM_ADDR(__SPM_REG)), \

"r" ((uint8_t)(__BOOT_SIGROW_READ)), \

"z" ((uint16_t)(addr)) \

); \

__result; \

}))

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

Elsewhere in that file is:

#  define __SPM_REG    SPMCSR
or
#  define __SPM_REG    SPMCR

also:

#define __BOOT_SIGROW_READ (_BV(__SPM_ENABLE) | _BV(SIGRD))

also

#  define __SPM_ENABLE  SPMEN
or
#  define __SPM_ENABLE  SELFPRGEN

So the code effectively says:

uint8_t boot_signature_byte_get(const __flash uint8_t * addr) {
    __SPM_REG = __BOOT_SIGROW_READ;
    return *addr;
}

That is still in "GCC format" (the __flash is a GCC thing) but CV should have some equivalent of "__flash" (it might even be __flash in fact!).

 

Replace __SPM_REG and __BOOTSIGROW_READ in that when you know whether the AVR you are trying to use has SPMCR or SPMCSR and SPEN or SELFPRGEN.

Last Edited: Thu. Dec 14, 2017 - 09:09 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is this just a continuation of your other thread - which has outstanding questions:

 

https://www.avrfreaks.net/forum/programmer-show-me-ics-signature

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

Hi sorry im researching about this topic and i cant ask my question there

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

awneil wrote:
Is this just a continuation of your other thread - which has outstanding questions:

And the other-other thread https://www.avrfreaks.net/forum/c... where OP gave an x51 fragment?

 

Indeed, you gurus will need to reverse-translate sophisticated [to me] GCC inline assembler chunks -- I ran out of eye of newt.  That said, OP is posing fairly low-level constructs/concepts out of context.  In this thread, there is no mention of which AVR model.  Other models may not even have an SPM reg, or values may be different.

 

-- read the datasheet section on how the read the signature row info.

-- if it indeed involves a flash read, then learn how to do that in CV.

-- combine the two.

 

 

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

can anyone ... or give codevision equivalent

Hah -- found it.  David Prentice solved this (and related) problems some years ago...

https://www.avrfreaks.net/forum/p...

uint8_t boot_signature_byte_get(uint16_t address)
{
#asm
                ldd r31, y+1;    //move Pagedata MSB reg 1
                ldd r30, y+0;    //move Pagedata LSB reg 1  
                ldi r26, 33;
                sts SPMCRAddr, r26;     //move spmcrval to SPM control register
                lpm r30, z;            	//store program memory
#endasm
}

Making it inline is left as an exercise for the student.

 

And -- in a current CV version, the parameter loaded into Z might not be on the stack.

And -- the "33" constant may not be the same for your target AVR model.

And -- other caveats about possible save-restore of registers.

 

Is there a 4-cycle limitation?  If so, probably why the C sequence that Cliff showed is not used directly -- after seting SPMxCR value, a straight flash read might not get to the LPM in four cycles if the parameter bytes are read off the stack.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

theusch wrote:
the "33" constant may not be the same for your target AVR model.

Again:  thus defeating the object of this code to identify the model of the processor!!

 

https://www.avrfreaks.net/comment...

 

https://www.avrfreaks.net/comment...

 

 

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

awneil wrote:
Again: thus defeating the object of this code to identify the model of the processor!!

Do we know that we are on the same snipe hunt as finding what an arbitrary unmarked IC is?

And for the benefit of the doubt, OP could be using signature as an example...perhaps it is cal data OP is after.

 

In digging out the CV equivalent of spm_boot.h and equivalent, some pertinent prior discussions were found.  One can winnow down to find the model expecially with a limited universe to choose from.  If a model like Mega48 with no sig row read support, then something other than 1e will be found.  And so on.

 

Continuing with that, there are only so many AVR8 models with sig row read functionality.  There are only so many possible addresses for SPMCR/SPMCSR.  There will only be so many combinations for the magic bits needed.

 

[another complication that I found is the Mega88-family datasheet and chip-includes having wrong/incomplete information on this feature.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

theusch wrote:
Do we know that we are on the same snipe hunt as finding what an arbitrary unmarked IC is?

To be fair, no - not for sure.

 

The OP has been asked to clarify but, so far, has not.

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

awneil wrote:
Again: thus defeating the object of this code to identify the model of the processor!!

I'm reminded of  chemistry lab assignment:  Identify the unknown substance in the container (usually a tube of fluid).

 

One then carries out a number of tests to play the 20 Questions game with the fluid.  And indeed, some/many will be n/a.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

but those are external tests applied to the sample - which is rather different from the sample trying to identify itself internally ...

 

"I'm pink, therefore I'm Spam..."

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...