Can pseudo fuses be set for the AS-7 debugger?

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

Hi Folks.  Only 50 minutes till 2018.  I guess it already is for some of you.

 

Can you tell me, please, how to make the AS7 simulator/debugger believe that the SELFPRGEN fuse is set (0)?  I've spent an awful lot of time trying to find it.

 

Let's all have a great year.

 

Mike.

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

First of all, which chip? Not all have this fuse.

 

Second, why does it need to be set in the simulator? Are you trying to simulate a bootloader? What happens if it is NOT set and you try the simulation? If you are working in the debugger, then you are working on real hardware and there is a real fuse that controls it.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Sun. Dec 31, 2017 - 11:54 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Embed the fuse info in the elf file, and it will be programmed...
.
http://www.microchip.com/webdoc/AVRLibcReferenceManual/group__avr__fuse.html

:: Morten

 

(yes, I work for Atmel, yes, I do this in my spare time, now stop sending PMs)

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

Wow!  I didn't expect a response on New Year's day.  Thanks Guys - I had imagined you all did this as a profession, and would be off work today.

 

The chip is an ATtiny85.  I should also have mentioned that I'm programming in assembler.

 

Thanks for the info, meolsen.  This takes me into unfamiliar territory, but I'll read your link and let you know where it gets me.

 

Mike.

Last Edited: Mon. Jan 1, 2018 - 05:59 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Which assembler. If its avr-as it will be trivial to add a .fuse section to the ELF. If Asm2 I'm pretty sure it's impossible.
.
BTW why do you want want this? I've debugged lots of SPM code in the simulator and have never had to mess about with SELPRGEN or any other fuses. The only "gotcha" is the flash caching but I'm not even sure that applies to the sim.

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

Well, I've spent some time trying to figure it out, but I'm not getting anywhere.

The article linked to by meolsen talks about writing stuff into the ELF file.  At first, I examined the files in my project to see if there was a <project name>.elf, then I looked up ELF as an acronym and discovered that it is an Executable Linker File.  The article talks about including .h header files, which is a C-language concept, but in fairness, I had not said at that point that I was programming in assembler.

Clawson, you asked which assembler - and in truth, I don't know.  Maybe it would help if I show the code.  I'm trying to write a byte into flash,using a routine I picked up by searching for it.  I'm pretty sure I know how to do it, or can work it out from what I already have, but it's not happening in the AS7 simulator.  I haven't tried writing it to a chip yet (AT85), because when I get it working, I will be building it into my project.

The routine doesn't actually run - it always ends in an error in rdloop:  but I don't care about that.  I can single-step enough of it to show me what to do, and I can see that the page buffer does not get written to flash.  I may be wrong, but I surmise that it's because the simulator thinks the SELFPRGEN fuse is not set in the extended fuse byte.  Otherwise, there's something wrong with the program, but as I found it on this site, I think it probably works.

The definitions file (tn85def.inc)  contains ...

 

; EXTENDED fuse bits
.equ    SELFPRGEN    = 0    ; Self-Programming Enable

 

but the '0' is not a value - just the number of the bit in the Extended Fuse byte.  The file also equates

 

; LOW fuse bits
.equ    CKSEL0    = 0    ; Select Clock source

 

; HIGH fuse bits
.equ    BODLEVEL0    = 0    ; Brown-out Detector trigger level

 

However, I have not been able to find an equate for the fuse bytes themselves - only the bits.  If I could say something like

EFUSE = 0 << SELFPRGEN    

or simply

EFUSE = 0              ... that would help, but EFUSE is not in the file.

 

Note:  I'm not asking or help with the program.  I only included it to answer the question "Which assembler"

 

Also, to allay questions about writing to flash, the application is a mains on-timer to prevent me leaving the garage light on for a week at a time till I need the car again,or my coffee machine switched on for hours after use.  Once the timer has been programmed, the number of seconds (2 bytes - 7FFF secs = 9 hours) will be written to NVR so that it will survive a power down.  The limit on the number of writes to NVR doesn't come into it.  Once it is programmed, I expect it to be used for a long time without being changed again.

I also know that timers can be bought - but I want to make one.

 ;This example shows SPM write of one page for devices with page write
 ;- the routine writes one page of data from RAM to Flash
 ; the first data location in RAM is pointed to by the Y pointer
 ; the first data location in Flash is pointed to by the Z pointer
 ;- error handling is not included
 ;- the routine must be placed inside the boot space
 ; (at least the do_spm sub routine)
 ;- registers used: r0, r1, temp1, temp2, looplo, loophi, spmcrval
 ; (temp1, temp2, looplo, loophi, spmcrval must be defined by the user)
 ; storing and restoring of registers is not included in the routine
 ; register usage can be optimized at the expense of code size
 .equ PAGESIZEB = (2*PAGESIZE) ;PAGESIZEB is page size in BYTES, not words
 
.org 0x00
ldi R28,0x00 ; YL - addresses data memory (0x0100)
ldi R29,0x01 ; YH

ldi R30,0x00 ; ZL - addresses Flash (0x0600)
ldi R31,0x06 ; ZH

ldi r16,0x69
st Y,R16     ; write to data mem add 0x100

 write_page:
;page erase
ldi R22, (1<<PGERS) + (1<<SPMEN)  ; PGERS is Page Erase
rcall do_spm
;transfer data from RAM to Flash page buffer
ldi R20, low(PAGESIZEB) ;init loop variable
ldi R21, high(PAGESIZEB) ;not required for PAGESIZEB<=256
wrloop:
ld r0, Y+
ld r1, Y+
ldi R22, (1<<SPMEN)
rcall do_spm
adiw ZH:ZL, 2
subi R20, 2
sbci R21,0
brne wrloop
 ;execute page write
subi ZL, low(PAGESIZEB) ;restore pointer
sbci ZH, high(PAGESIZEB) ;not required for PAGESIZEB<=256
ldi R22, (1<<PGWRT) + (1<<SPMEN)
rcall do_spm
;read back and check, optional
ldi R20, low(PAGESIZEB) ;init loop variable
ldi R21, high(PAGESIZEB) ;not required for PAGESIZEB<=256
subi YL, low(PAGESIZEB) ;restore pointer
sbci YH, high(PAGESIZEB)
rdloop:
lpm r0,Z+
ld r1, Y+
cpse r0, r1
rjmp error
subi R20,2
sbci R21,0
brne rdloop
 ;return
ret
 do_spm:
 ;input: R22 determines SPM action
 ;disable interrupts if enabled, store status
in R15, SREG
cli
;check for previous SPM complete
 wait:
in R16, SPMCSR
sbrc R16, SPMEN
rjmp wait
;SPM timed sequence
out SPMCSR, R22
spm
 ;restore SREG (to enable interrupts if originally enabled)
out SREG, R15
ret

error:
rjmp error

 

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

What I wrote (and as Cliff pointed out) is specific to avr-gcc (or avr-as). It will not work for avrasm.

:: Morten

 

(yes, I work for Atmel, yes, I do this in my spare time, now stop sending PMs)

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

I think it may be possible to set fuses with a Stimuli file.   See   http://www.atmel.com/webdoc/simu...

Under Assignments, it says the general statement syntax is

target = value     where Target is the numerical memory address of an I/O register in the I/O map.  For simple devices with flat I/O structure such as tinyAVR® and megaAVR®, the register name as found in the data sheet can also be used.

Under Directives, it gives a directive "$fuse" with an argument of "address value" and a comment "Set fuse byte at address to value.  Fuse addresses generally start at 0."

If there is something in the AT85 datasheet that gives an address of the fuse bytes, then I must have missed it.  It mentions the I/O map in paragraph 3.2 of the datasheet, but very briefly, with no helpful information.

 

Under "Known Issues in Simulator", it says "Setting fuses in the code of the simulated program may interfere with the operation of the simulator. " - so it seems to be possible, but I can't find out how.

 

Can anybody tell me what to do to set this fuse?  It's probably right in front of my face, but I'm not seeing it.

 

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

Well, I've made some progress, but I haven't solved my problem.

I modified the code slightly so that if the transfer to memory works, it raises PB4, or if it fails, it raises PB3, and transferred it to a chip.

With the SELFPRGEN fuse unprogrammed, the routine fails (as expected).

With the fuse programmed, the routine passes, showing that the write to flash was good. (pins tested with a scope).

However, in Studio-7, I can't write to the displayed flash memory, and I'm all the more convinced now that it's because AS7 thinks that the fuse is not set - but I still don't know how to set it in the simulator.

Surely, it must be possible?  Is there a Studio-7 expert who I could ask?

Last Edited: Wed. Jan 3, 2018 - 01:00 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I already told you what that was. Please try to pay attention.

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

Go back and use the more advanced AS4, you can change the fuses there!

 

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

Thank you, John.

When I came to the AVR scene, it seemed intuitive that AS7 would be the more capable package - 7 is a higher number than 4 or 6, so must be later software.

However, software does sometimes lose its way.  I often wish I could go back to Windows XP.  It seems to me that every level since then has added bells & whistles at the expense of usability.

If the experts have stuck with AS4, then it's clearly the way to go.  I'll load it.

 

BTW, is there a development history of Atmel Studio, where I could read what the revisions do?

 

Edit: On second thoughts, don't answer that - Google finds quite a number of links to that question.

Last Edited: Wed. Jan 3, 2018 - 02:18 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

armstack wrote:
If the experts have stuck with AS4

Predicting the population based on one sample, eh? Don't ever go into statistics.. ;-)

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]