AVR Code

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

Hello, I want to know if there is a code on an atmega32, would I be able to extract that code if there were no protection enabled on the atmega32? If yes then how would I be able to do that, and what software do I need to do that?

Thank You

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

The c source code gets converted by the c compiler from ascii human readable c text to binary AVR execuatble binary opcodes/instructions. If you have the c source, you can edit it and compile it and get a new hex file to burn into the AVR. If you just read the program out of flash, you can sort of disassemble it into assembly language with no comments, but if it was generated by a c compiler, it will be hard to read. Hope this helps.

Imagecraft compiler user

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

Yes, you can "extract" the code if protection fuses are not set. You can use Atmel Studio and any programmer (suitable for an ATmega32).

BUT, as Bob says, that code is not in C. It is in assembly language. With careful analysis, which takes time and is generally done by humans, not machines, you might be able guess the original C source.

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

Thank you for the replies, I won't have a problem reading assembly language, when I learned the AVR programming I learned it with assembly language. Thank you again for the reply

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

Quote:

I learned the AVR programming

Then surely you already know all about ISP and JTAG? You must be aware that you can use your own ISP programmer to read code from your mega32? Or did you only ever use it to write code into the chip not realising it could be used in either direction?

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

When I said I learned the AVR Programming I didn't mean the hardware part I meant the Software part meaning how to code in Assembly Language. I use the Proteus simulation software to simulate my AVR programs. I used the ISP only to write the code on the chip and I have never used a JTAG. Would it be possible to read the code of the AVR chip with the JTAG on the AVR Studio 6?

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

Of course it is possible. But since you have an ISP, just do it with that.

But I have to ask what you think that this "code" would look like. If you expect C code because you wrote the code in C, you would be wrong. And even if you wrote the code in assembly, what you get back out of the chip will not be that, either. You get back machine code. That can be disassembled into readable code, but it will not have the niceties of the original.

Regards,
Steve A.

The Board helps those that help themselves.

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

Thanks for the reply, really helped alot

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

Hello, I am coding the AVR with the Assembly Language, and I wanted to make my own libraries and include them in my source code. I created one and its not working, any ideas how I could do that? I am working with the Atmel Studio 6.0. I have included the code that I am working with in the attachments.

Thank You

Attachment(s): 

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

And for those who cannot read .rar files:

//delay.inc
delay:
	ldi r20, 8
L2:	ldi r21, 100
L1:	ldi r22, 100
L0:	nop
	dec r22
	brne L0
	dec r21
	brne L1
	dec r20
	brne L2
	ret
//main.asm
.include "m32def.inc"
.include "delay.inc"

	ldi r16, 0xFF
	out ddrc, r16
again:	out portc, r16
	call delay
	com r16
	rjmp again

As you are using CALL you probably want to start by initialising the stack pointer. Later AVRs do this automatically but the mega32 you use does not.

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

Hello, let me more clearer, I have initialized the stack pointer and I have build the code, there were no compilation or syntax errors. When I run the code on the AVR nothing happens, that means that the call function doesn't happen. Any suggestions? And again I want to create my own libraries in assembly language and include them in the main source code which is also in assembly language. I am also using ISIS Proteus Simulation to try on my programs.

Thank You

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

I already told you what was wrong?!

//main.asm 
.include "m32def.inc" 
.include "delay.inc" 

   ldi r16, low(RAMEND) 
   out SPL, r16
   ldi r16, high(RAMEND) 
   out SPH,  r16
   ldi r16, 0xFF 
   out ddrc, r16 
again:   out portc, r16 
   call delay 
   com r16 
   rjmp again 

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

Quote:
I have initialized the stack pointer and I have build the code

Not in the code you've shown.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
//main.asm
.include "m32def.inc"
.include "delay.inc"

You have to insert "delay.inc" to a place where the main program cannot reach it.

For example

.include "m32def.inc"

.cseg
   jmp start
.include "delay.inc" 

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

Quote:

to a place where the main program cannot reach it.

Well spotted. I guess on the end would perhaps be the easiest option?

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

Hello, when I said that I have initialized the stack pointer I did initialize it in another code not the one that I have posted, I just didn't re-post the adjusted code. I have placed the "delay.inc" where the main program couldn't reach and it worked fine. Thank you all for the help and suggestions. :D

Thank You

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

Quote:

not the one that I have posted,

so you are just intent on wasting all our time? Great.

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

Quote:

Hello, when I said that I have initialized the stack pointer I did initialize it in another code not the one that I have posted

If you want help with some code then why post some other code than the one you want help with.

Suppose this was a car forum, and I wanted help help with my car that won't start - how much sense would it make to post photos of my washing machine?

It is up to you to put as much effort as you possibly can to post facts that actually help people here to help you. If there was little effort put into the formulation of the question, then there will eventually be little effort put into answers.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

1- I have made the adjustments that were in the replies and I have stated that

Quote:
I have initialized the stack pointer and I have build the code, there were no compilation or syntax errors.

2- I DID NOT POST A CODE THAT I DIDN'T NEED HELP WITH. All the adjustments that were suggested were done to the same code that I have posted.
3- I didn't waste anybody's time, what I meant by "another code" is the adjusted code, sorry if I wasn't clear with this part.
4- It was clear that the problem that I posted was solved in my last reply.
Quote:
I have placed the "delay.inc" where the main program couldn't reach and it worked fine.

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

Quote:

I didn't waste anybody's time

People here read the code you posted. It contained a programming error, i.e. that the stack wasn't initialized. They spent time reading your code and posting the results of their analysis. Are you saying it was well spent time?

I'm out.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

Hello I have a question regarding the Atmega32 UART. I have set baud rate and all the other related values of the UART. My question here when the Atmega32 sends out the data, does it start with a START BIT or not?

Thank You

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

mahmoud899 wrote:

...does it start with a START BIT or not?

What does the datasheet say?

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

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

Thanks