logo elektroda
logo elektroda
X
logo elektroda
REKLAMA
REKLAMA
Adblock/uBlockOrigin/AdGuard mogą powodować znikanie niektórych postów z powodu nowej reguły.

Bootloader ATmega32 nie wiem co jest nie tak

Rekin73 06 Lut 2010 11:48 2651 6
REKLAMA
  • #1 7651325
    Rekin73
    Poziom 14  
    Witam
    Przerobiłem gotowy projekt "boot" z programu Bascom, tam jest napisany na procesor ATmega163 a ja potrzebuje na ATmega32. Program "boot" wgrałem do chipa ale gdy chce wgrać nowy program za pomocą terminala wszystko niby idzie dobrze dostaje znaki zapytania z powrotem. Ale program sie nie zapisuje w chipie jest sam tylko bootloadera.

    Nie wiem gdzie leży problem mecze sie z tym juz dwa tygodnie.

    Przepraszam za ortografie ale pracuje na PC z klawiatura Niemiecka tak jak sam Windows jest niemiecki.

    Z góry dziękuje za pomoc.

    Pozdrawiam
    <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    $prog &HFF , &HE1 , &H9B , &H00    ' generated. Take care that the chip supports all fuse bytes.$PROG &HFF,&HE1,&H9B,&H00'
    'generated. Take care that the chip supports all fuse bytes.'-------------------------------------------------------------------------------
    
    'IMPORTANT : Look at BOOTLOADER.BAS which is simpler
    
    '-------------------------------------------------------------------------------
    '--------------------------------------------------------------------------------
    'name                     : boot.bas
    'copyright                : (c) 1995-2005, MCS Electronics
    'purpose                  : bootloadera example for the M163
    'micro                    : Mega163
    'suited for demo          : yes
    'commercial addon needed  : no
    'use in simulator         : not possible
    '
    'set fusebit FE to 512 bytes for bootspace for this example
    'At start up a message is displayed. When you make PIND.7 low the
    'bootloadera will be started
    'This program serves as an example. It can be changed for other chips.
    'Especially the page size and the boot entry location might need a change
    '--------------------------------------------------------------------------------
    '$regfile = "m163def.dat"
    $regfile = "m32def.dat"
    
    'Our communication settings
    $crystal = 8000000
    $baud = 9600
    $hwstack = 32                                               ' default use 32 for the hardware stack
    $swstack = 10                                               'default use 10 for the SW stack
    $framesize = 40                                             'default use 40 for the frame space
    
    
    Print "Checking bootloadera"
    Portc.7 = 0
    If Pinc.7 = 1 Then
       Print "Entering bootloadera"
       jmp $1e00                                                ' make a jump to the boot code location. See the datasheet for the entrypoint
    End If
    Print "Not entering bootloadera"
    
    'you code would continue here
    End
    
    
    
    
    '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    '                    B O O T  L O A D E R
    '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    
    'The fusebit FE is set so that we have 512 bytes for the boot code
    'Only a part is used btw
    'But it sets the bootstart address to 1E00 hex. which happens to be in the M161 too
    
    'The $boot diretive will bind the code below into address specified
    'This will generate large files with FFFF opcode from the end of the normal program to the start
    'of the bootcode
    'Note that the bootloadera is written in ASM. This because the bootloadera may not call routines from
    'the main program. Why? Because during programming they get erased!
    $boot = $1e00
    Print " start"
    
    'no interrupts are allowed during bootloadera programming
    Disable Interrupts
    
    
    'Standard Intel hex file can be sent
    ':10 0000 00 0C 94 2400189500001895000018950000 25
    ':00 0000 01 FF
    ' size , address,record type, data, checksum
    'The sample bootloadera does not use the checksum
    
    'The same baudrate is used as the main program is using
    'but we can change it here when we like. Just unremark the next line and/or change it
    'But take in mind that the bootloadera sender must use the same baud rate !!!
    'Baud = 19200
    
    
    clr r18                                          ; word counter for written data
    clr r23                                          ; page counter
    
    rcall _erase_page                                ; erase first page
    
    _read_lines:
      rcall _rec_line                                ; get line into SRAM pointed by X
      ldi r26,$61                                    ; point to start of line
      clr r27
      ld r24,x+                                      ; get char in r24
      rcall _hex2number                              ; convert result in r17
      ld r24,x+
      rcall _hex2number2                             ; convert second char , r17 holds the number of hex pairs to get
      mov r19,r17                                    ; number of entries
      tst r19
      brne _readnext                                 ; not the end record
      rjmp _write_last_page                          ; final line so write the last page
    
    _readnext:
      adiw xl,6                                      ; point to first pair
    _readnextpair:
      ld r24,x+                                      ; get char in r24
      rcall _hex2number                              ; convert result in r17
      ld r24,x+
      rcall _hex2number2                             ; convert second char , r17 holds the data
      mov r0,r17                                     ; save in r0
      dec r19                                        ; adjust pair data counter
      ld r24,x+                                      ; get char in r24
      rcall _hex2number                              ; convert result in r17
      ld r24,x+
      rcall _hex2number2                             ; convert second char , r17 holds the data
      mov r1,r17                                     ; save data
      rcall _write_page                              ; write into page buffer
      cpi r18,64                                     ; page is 128 bytes is 64 words
      breq _writeit                                  ; write page since it is full
    _lbl1:
      dec r19                                        ; adjust data pair
      brne _readnextpair                             ; more data
      rjmp _read_lines                               ; next line
    
    _writeit:
      rcall _save_page                               ; save page
      rcall _erase_page                              ; erase next page
      Rjmp _lbl1                                     ; continue
    
    _write_last_page:
      rcall _save_page                               ; save last page
      rjmp _exit_page                                ; exit needs a reset
    
    
    
    ' get 1 byte from serial port and store in R24
    _recbyte:
      Sbis USR, 7                                    ; Wait for character
      rjmp _recbyte
      in r24, UDR                                    ; get byte
    Ret
    
    'get one line from the serial port and store in location pointed by X
    _rec_line:
      ldi r26,$60                                    ; point to first location in SRAM
      clr r27
    _rec_line5:
      sbis usr,5
      rjmp _rec_line5
      ldi r24, 63 ; ?
      !out udr,r24                                   ; show ? so we know we can send next line
    _rec_line1:
      rcall _recbyte                                 ; get byte
      cpi r24,13                                     ; enter?
      breq _rec_line2                                ; yes ready
      st x+,r24                                      ; no so store in sram buffer
      rjmp _rec_line1                                ; next byte
    _rec_line2:
      clr r24                                        ; string terminator
      st x,r24
    ret
    
    ' convert HEX byte in r24 into bin value , on exit byte in r17
    _hex2number:
      clr r17
    _hex2number4:
      Subi R24,65                                    ; subtract 65
      Brcc _hex2number3                              ; in case carry was cleared
      Subi R24,249                                   ; not
    _hex2number3:
      Subi R24,246
      Add R17,R24                                    ; add to accu
    ret
    
    ';called for the second byte
    _hex2number2:
      Lsl R17                                        ; shift data
      Lsl R17
      Lsl R17
      Lsl R17
      rjmp _hex2number4                              ; handle the conversion
    
    
    'page address in z7-z13
    _erase_page:
      mov r31,r23                                    ; page address
      lsr r31                                        ; get z8-z13 shift ls bit into carry
      clr r30
      ror r30                                        ; get z7
      ldi r24,3                                      ; page erase command
      rcall _do_spm
      clr r16 ; page cleared indicator
    ret
    
    _write_page:
      mov r31,r23                                    ; page address z8-z13
      lsr r31
      clr r30
      ror r30                                        ; carry to z7
    
      mov r24,r18                                    ; word address buffer counter
      lsl r24
      add r30,r24                                    ; z1-z6
      ldi r24,1                                      ; buffer fill
      rcall _do_spm
      inc r18
    ret
    
    
    _save_page:
    'z0-z6 must be 0
    'z7-z13 is the page address
    'r0 and r1 are ignored
      mov r31,r23
      lsr r31
      clr r30
      ror r30
    
      ldi r24,5                                       ; write page
      rcall _do_spm
      clr r18                                         ; page word address counter
      inc r23                                         ; page counter
    ret
    
    _exit_page:
      in r24,spmcr
      sbrs r24,asb
      rjmp _exit_page1
      ldi r24,17
      rcall _do_spm
      rjmp _exit_page
    _exit_page1:
    End
    
    
    '; execute spm instruction , data in R24
    _do_spm:
      sbic eecr, eewe
      rjmp _Do_spm
    !  Out Spmcr , R24
      spm
    !.obj Ffff                                         ; needs FFFF according to datasheet
      nop
    _wait_spm:
      In r24,spmcr
      sbrc r24, 0
      rjmp _wait_spm
    ret
    
    End
    <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    



    [color=red]inventco.eu - proszę poprawić błędy - regulamin p.15 - inaczej post pójdzie do kosza.
  • REKLAMA
  • REKLAMA
  • #3 7652847
    Rekin73
    Poziom 14  
    To jak jest poprawnie $7e00 ?
  • REKLAMA
  • #4 7654338
    Wojtek75
    Poziom 24  
    W nocie uC na str. 255 masz tabelkę (Boot Size Configuration) która powinna ci co nieco wyjaśnić.
  • REKLAMA
  • #5 7656478
    Rekin73
    Poziom 14  
    Dziękuję Wojtek75 to pomogło adres jest $3e00 ale jeszcze coś nie pasuje. Pierwszy program za pomocą Terminala wszedł a drugi już nie chce. Wygląda jak by procesor nie skoczył do adresu bootloadera bo się ten znak zapytania nie zgłasza.
  • #6 7657431
    Wojtek75
    Poziom 24  
    W każdym programie, który wgrywasz za pomocą bootloadera powinieneś umieścić warunek najlepiej w pętli głównej, którym można go ponownie wywołać, czyli np:
    if coś tam then
    Print "Entering bootloadera" 
    jmp $3e00
  • #7 7657712
    Rekin73
    Poziom 14  
    Tak mam zrobione po wgraniu bootloadera, wgrywałem Cod programu wszystko Ok dostaje odpowiedz i leci juz nowy program. Chce wgrać jeszcze raz ten sam program juz nie idzie tak jak by sie zawiesił. Jak maja byc po ustawiane te Lock i Fuse Bits

    
    --------------------------------------------------------------------------------
    'name                     : bootnew.bas
    'copyright                : (c) 1995-2005, MCS Electronics
    'purpose                  : test the bootloader
    'micro                    : Mega128
    'suited for demo          : yes
    'commercial addon needed  : no
    'use in simulator         : possible
    '
    ' After the ? mark from the loader, set the focus to this window and then
    ' Select Upload from the Terminal Emulator
    '--------------------------------------------------------------------------------
    
    $crystal = 8000000
    $baud = 19200
    $regfile = "m32def.dat"
    $hwstack = 32                                               ' default use 32 for the hardware stack
    $swstack = 10                                               'default use 10 for the SW stack
    $framesize = 40                                             'default use 40 for the frame space
    
    Portc.7 = 0
    
    Do
      Print "Hello, this is a new prog"
      Waitms 50
    
    If Pinc.7 = 1 Then
       Print "Entering bootloader"
       jmp $3e00
     
    End If
    Print "Not entering bootloader"
    
    Loop
     End
    
REKLAMA