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

Mega 32 bootloader z Bascom boot

ba2niedz 04 Lut 2012 18:38 2129 2
REKLAMA
  • #1 10495162
    ba2niedz
    Poziom 10  
    Witam,

    Męczę się żeby uruchomić bootloader w atmega 32 z przykładów Bascoma:
    Program któy chce wgrać to:

    Cytat:
    '-------------------------------------------------------------------------------
    ' BOOTNEW.BAS
    ' (c) 2003, MCS Electronics
    ' The purpose of this file is to test the bootloader
    ' 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"


    Config Lcdpin = Pin , Db4 = Portc.4 , Db5 = Portc.5 , Db6 = Portd.7 , Db7 = Porta.7 , E = Portc.3 , Rs = Portc.2
    Config Lcd = 20 * 4
    Cursor Off
    Cls


    Do
    Print "Hello, this is a new prog"
    Waitms 500
    Loop
    End


    a zmodyfikowany bootloader:
    Cytat:
    '--------------------------------------------------------------
    ' BOOT.BAS
    ' Bootloader example for the M163
    ' 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
    'bootloader 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
    '--------------------------------------------------------------

    'Our communication settings
    $regfile = "m32def.dat"
    $crystal = 8000000
    $baud = 19200

    Print "Checking bootloader"
    Portd.4 = 1
    If Pind.4 = 0 Then
    Print "Entering bootloader"
    jmp $3E00 ' make a jump to the boot code location. See the datasheet for the entrypoint
    End If
    Print "Not entering bootloader"

    '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 bootloader is written in ASM. This because the bootloader may not call routines from
    'the main program. Why? Because during programming they get erased!
    $boot = $3e00

    'no interrupts are allowed during bootloader 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 bootloader 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 bootloader 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


    Fuse bity ustawiłem w AVR BURN-O-MAT tak że procesor startuje od adresu 0x00
    rozmiar dla bootloadera=512

    I w bascomie próbuje wgrać nowy program za pomocą terminala i uruchamia się bootloader potem klikam upload, pojawiają się znaki zapytania, ale po zakończeniu nic się nie dzieje procesor ma jakieś śmieci zamiast programu.

    Proszę o pomoc jak ustawić fuse bity i gdzie robię błąd bo naprawdę nie mam pomysłu.

    Pozdrawiam
  • REKLAMA
  • #3 10496424
    ba2niedz
    Poziom 10  
    A masz może kod źródłowy do tego? tzn. jak działa ten bootloader ?
REKLAMA