Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

MCS Bootloader for XMEGA 32E5 not uploading flash program
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
enniom

Bascom Member



Joined: 20 Oct 2009
Posts: 496

PostPosted: Tue Nov 03, 2015 10:02 pm    Post subject: MCS Bootloader for XMEGA 32E5 not uploading flash program Reply with quote

Hello,

I used the sample "Bootloader_atxmega32a4.bas" as is using COM1 on PORTC - but changing the Regfile to "xm32e5def.dat" .

The Flash program does not upload and the following log is created by the MCS Bootloader:
Quote:
Log Window
Open COM3
Open COM3
Sending Init byte
Loader returned : 10
Open COM3
Sending Init byte
Loader returned : 10
Open COM3
Sending Init byte
Loader returned : 50
Open COM3
Sending Init byte
Loader returned : 52
Open COM3
Sending Init byte
Loader returned : 50
Open COM3
Sending Init byte
Loader returned : 255
Open COM3
Sending Init byte
Loader returned : 255
Open COM3
Sending Init byte
Loader returned : 255
Open COM3
Sending Init byte
Loader returned : 255
Open COM3
Sending Init byte
Loader returned : 255
Open COM3
Sending Init byte


I'm not sure what should be changed.

E

(BASCOM-AVR version : 2.0.7.9 , Latest : 2.0.7.8 )
Back to top
View user's profile
enniom

Bascom Member



Joined: 20 Oct 2009
Posts: 496

PostPosted: Mon Nov 16, 2015 2:26 pm    Post subject: Reply with quote

Hello,

now that I have done some more testing, there seems to be 2 problems:

1. ClockPol =0|1 creates a Compile Error
Code:

Config Com1 = 57600 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 1
 

Quote:

Error : 86 Line : 25 Invalid parameter for CONFIG parameter or value [1] , in File : C:\Bootloader\Bootloader.XM16E5.Nov16.15.bas


The second problem appears to be associated with the SPM command in the Subroutine DO_SPM:
Execution stops at this command.

Any help would be greatly appreciated.


E.


Code:
$regfile = "xm16e5def.dat"
$hwstack = 200
$swstack = 200
$framesize = 200
$crystal = 32000000

Config Osc = Enabled , 32mhzosc = Enabled                   'internal 2 MHz and 32 MHz enabled
Config Sysclock = 32mhz , Prescalea = 1 , Prescalebc = 1_1  'use 32 MHz and divide by 1 to end up with 32 MHz

'==========================================
'Bootloader Config
'==========================================
$loader = $2000
Disable Interrupts : Stop Watchdog

Dim W As Word , J As Byte

'============================================================================
'config LED
'============================================================================
Fl_red Alias Portc.7
Config Fl_red = Output
Fl_red = 0

Config Com1 = 57600 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
Open "COM1:" For Binary As #1

W = 6
Do
     Decr W : Wait 1
     J = Inkey(#1)

Loop Until W = 0 Or J = 123 Or J = 124

If J = 123 Or J = 124 Then
     Const Maxwordbit = 7                                   'Z7 is maximum bit                                   '
     Const Maxword =(2 ^ Maxwordbit) * 2                    '128
     Const Maxwordshift = Maxwordbit + 1

     Dim Bstatus As Byte , Bretries As Byte , Bmincount As Byte , Bblock As Byte , Bblocklocal As Byte
     Dim Bcsum1 As Byte , Bcsum2 As Byte , Buf(128) As Byte , Csum As Byte
     Dim Spmcrval As Byte                                   'self program command byte value

     Dim Z As Long                                          'this is the Z pointer word
     Dim Vl As Byte , Vh As Byte                            'these bytes are used for the data values
     Dim Wrd As Word , Page As Word                         'these vars contain the page and word address

     Const Nak = &H15                                       'Constants Used In Serial Com
     Const Ack = &H06
     Const Can = &H18

     $timeout = 300000

     Bretries = 5 : Bmincount = 3                           'try 10 times and get 123 at least 3 times
     Do
       Bstatus = Waitkey(#1)                                'wait for the loader to send a byte

       If Bstatus = 123 Then
          If Bmincount > 0 Then
             Decr Bmincount
          Else
             Print #1 , Chr(bstatus);
             Goto Loader
          End If
       Else

          If Bretries > 0 Then
             Bmincount = 3
             Decr Bretries
          Else
             Goto Process_reset
          End If
       End If
     Loop

     Loader:                                                'loader routine. It is a Xmodem-checksum reception routine

     Do
          Bstatus = Waitkey(#1)
     Loop Until Bstatus = 0

     Fl_red = 1

     Spmcrval = &H20 : Gosub Do_spm                         '<<<<< Bootloader hangs here <<<<<<<<<<<<<<<<<<<<
                                                             'appears related to SPM command in Subroutine
     Fl_red = 0

     Bretries = 10
     Do
       Bblocklocal = 1
       Csum = 0                                             'checksum
       Print #1 , Chr(nak);                                 'send a nack first

       Do
         Bstatus = Waitkey(#1)

         Select Case Bstatus
            Case 1:                                         'start of heading, PC ready to send
                 Csum = 1
                 Bblock = Waitkey(#1) : Csum = Csum + Bblock       'get block
                 Bcsum1 = Waitkey(#1) : Csum = Csum + Bcsum1       'get checksum first byte
                 For J = 1 To 128                           'get 128 bytes
                    Buf(j) = Waitkey(#1) : Csum = Csum + Buf(j)
                 Next
                 Bcsum2 = Waitkey(#1)                       'get second checksum byte

                 If Bblocklocal = Bblock Then               'are blocks the same?
                    If Bcsum2 = Csum Then                   'is the checksum the same?

                       Toggle Fl_red

                       Gosub Writepage
                       Print #1 , Chr(ack);                 'acknowledge
                       Incr Bblocklocal                     'increase local block count
                    Else                                    'no match nak
                       Print #1 , Chr(nak);
                    End If
                 Else
                    Print #1 , Chr(nak);                    'blocks do not match
                 End If
            Case 4:                                         'end of transmission
                  If Wrd > 0 Then                           'if something left in the page
                      Wrd = 0                               'Z pointer
                      Spmcrval = &H24 : Gosub Do_spm
                  End If
                  Print #1 , Chr(ack);                      'send ack
                  Waitms 20
                  Goto Process_reset
            Case &H18:                                      'PC aborted
                  Goto Process_reset
            Case 123 : Exit Do
            Case 124 : Exit Do
            Case Else
               Exit Do
         End Select
       Loop
       If Bretries > 0 Then
          Waitms 1000
          Decr Bretries                                     'decrease attempts
       Else
          Goto Process_reset                                'reset
       End If
     Loop
End If

Process_reset:
Fl_red = 0

Rampz = 0
Goto _reset                                                 'start at address 0

End                                                         'end program


Writepage:                                                  'write one or more pages
   For J = 1 To 128 Step 2                                  'write 2 bytes into a page
      Vl = Buf(j) : Vh = Buf(j + 1)                         'Low and High bytes
      lds r0, {vl}                                          'store in r0 and r1 registers
      lds r1, {vh}
      Spmcrval = &H23 : Gosub Do_spm                        'write value into page at word address
      Wrd = Wrd + 2                                         'word address increases with 2 because LS bit of Z is not used
      If Wrd = Maxword Then                                 'page is full
          Wrd = 0                                           'Z pointer needs wrd to be 0
          Spmcrval = &H24 : Gosub Do_spm                    'write page
          Page = Page + 1                                   'next page
      End If
   Next
Return


Do_spm:
  Z = Page                                                  'make equal to page
  Shift Z , Left , Maxwordshift                             'shift to proper place
  Z = Z + Wrd                                               'add word
  lds r30,{Z}
  lds r31,{Z+1}

  #if _romsize > 65536
      lds r24,{Z+2}
      sts rampz,r24
  #endif

  Nvm_cmd = Spmcrval
  Cpu_ccp = &H9D
  spm

Do_spm_busy:
   lds r23, NVM_STATUS
   sbrc r23,7
   rjmp do_spm_busy
Return
 
[/quote]
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 1944

blank.gif
PostPosted: Mon Nov 16, 2015 8:59 pm    Post subject: Reply with quote

enniom wrote:
now that I have done some more testing, there seems to be 2 problems:
1. ClockPol =0|1 creates a Compile Error
Quote:
Error : 86 Line : 25 Invalid parameter for CONFIG parameter or value [1] , in File : C:\Bootloader\Bootloader.XM16E5.Nov16.15.bas

The error message is pretty clear, what do you not understand?
I don't see where's the problem, the original bootloader doesn't use it.
Quote:
The second problem appears to be associated with the SPM command in the Subroutine DO_SPM:
Execution stops at this command.

How would you know?
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5278
Location: Holland

blank.gif
PostPosted: Mon Nov 16, 2015 9:25 pm    Post subject: Reply with quote

I have no idea why you add that ? it is for normal AVR. The original sample has : Config Com1 = 38400 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8 ' use USART C0

I advise to check without the bootloader if the correct baud is used. ie ; if a normal program that prints "hello" work.

_________________
Mark
Back to top
View user's profile Visit poster's website
enniom

Bascom Member



Joined: 20 Oct 2009
Posts: 496

PostPosted: Mon Nov 16, 2015 9:28 pm    Post subject: Reply with quote

Thanks MWS for your reply.

Quote:
I don't see where's the problem, the original bootloader doesn't use it.

You are right. In my efforts to find the problem, I tried to change ClockPol but the Compiler generated an error. This post was intended to point this out.

Quote:
Quote:
The second problem appears to be associated with the SPM command in the Subroutine DO_SPM:
Execution stops at this command.

How would you know?


You'll see in the posted code that a LED is turned on just before the subroutine call in the main program and it is turned off once returns from the subroutine. The LED does not go out implying that there was no return from the Sub and remains "hung"/lit until the uC is reset. This was the case in a number of variations I created in troubleshooting the problem.

E


Edit: Mark, you are right - it is not needed. It is included here because the Compiler creates an error if used. This may be a bug. The HELP does show it to be an option with Xmegas as well.


Last edited by enniom on Mon Nov 16, 2015 9:51 pm; edited 1 time in total
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5278
Location: Holland

blank.gif
PostPosted: Mon Nov 16, 2015 9:46 pm    Post subject: Reply with quote

Quote:
Edit: Mark, you are right - it is not needed. It is included here because the Compiler creates an error if used. This may be a bug.

I am confused. What is the bug?

_________________
Mark
Back to top
View user's profile Visit poster's website
enniom

Bascom Member



Joined: 20 Oct 2009
Posts: 496

PostPosted: Mon Nov 16, 2015 9:56 pm    Post subject: Reply with quote

Sorry Mark for not being clear.

I think the first possible bug is that the Help shows ClockPol to be an option for Xmegas. If it is included in the Config Comx, then the compiler throws an error.
(But ClockPol is not needed in my Bootloader)

The second bug appears to be with the SPM command. When the Do_SPM Sub is called the first time from the Main Program, the uC "Hangs" and does not return. The Xmega 16 or 32E5 needs to be reset and for the Bootloader to restart.

I hope this helps.


E.
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5278
Location: Holland

blank.gif
PostPosted: Mon Nov 16, 2015 10:19 pm    Post subject: Reply with quote

aha, right. I forgot to delete that after copying it. I changed it.

spm : it is an instruction. it should work. i advise :
- check after programming if the chip verifies ok.
- check if a normal program works.

I see you use the xe16. i do not have that one so i cant test it.

_________________
Mark
Back to top
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 1944

blank.gif
PostPosted: Mon Nov 16, 2015 10:45 pm    Post subject: Reply with quote

enniom wrote:
This post was intended to point this out.

And my post should have encouraged you to read this controllers data sheet and notice, that there is no such thing like clock polarity in UART mode. If I remember right a bit called UCPOL exists, but is only valid in SPI mode.
Back to top
View user's profile
enniom

Bascom Member



Joined: 20 Oct 2009
Posts: 496

PostPosted: Mon Nov 16, 2015 11:01 pm    Post subject: Reply with quote

Thanks Mark for taking the time to help.

I can confirm that the first call to the Do_SPM hangs the uC and it is possible that it is the SPM command. This is true for both Xmega 16e5 and 32e5 (I believe you have a 32e5 ??).

There is no program uploaded to Flash. If you refer to the earlier post with the complete Bootloader program, I can confirm that

Code:

Snippet from above post:

     Do
          Bstatus = Waitkey(#1)
     Loop Until Bstatus = 0

     Fl_red = 1                                                      'LED On

     Spmcrval = &H20 : Gosub Do_spm                         '<<<<< Bootloader hangs here <<<<<<<<<<<<<<<<<<<<
                                                             'appears related to SPM command in Subroutine
     Fl_red = 0                                                        'LED Off

 


All initial UART communication and handshaking is OK. The Red LED turns ON. The Do_SPM Sub is called but does not Return. Everything Hangs/Stops.

The Red LED does not go out implying that the the uC is stuck in the Sub and does not Return.

E
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5278
Location: Holland

blank.gif
PostPosted: Mon Nov 16, 2015 11:11 pm    Post subject: Reply with quote

in other topics i checked code from you for xmega32E too and it worked ok for me.
what kind of hardware do you use?
which programmer do you use?
what is the revision of the processor?

_________________
Mark
Back to top
View user's profile Visit poster's website
enniom

Bascom Member



Joined: 20 Oct 2009
Posts: 496

PostPosted: Mon Nov 16, 2015 11:26 pm    Post subject: Reply with quote

Mark,

The uC is a Xmega 32E5-U. I have programmed both the Flash and B/L using an Atmel AVRISP MKII for many months. For the B/L, I have used the MCS Sample Bootloader *.BAS file, with $loader = $2000 for 16E5 and $4000 for 32E5. Communication with the UART is OK.

The PC UART COM Port is through a FTDI FT230X and I have used it successfully in a number of Mega and XMega Bootloaders (including XMega 192A3).

The Flash program I am trying to "Bootload" can be flashed and works properly using the MKII.

I hope this helps.

E
Back to top
View user's profile
enniom

Bascom Member



Joined: 20 Oct 2009
Posts: 496

PostPosted: Tue Nov 17, 2015 2:33 pm    Post subject: Reply with quote

Hello Mark,

One additional observation.

After the Bootloader program shown earlier in this thread is burned onto the 32E5 using the MKII programmer, I use (F4) "Program Chip" from BASCOM to load a simple "blinky" program.

I then see after uC Bootloader executes for the first time the Do_SPM sub (with Page = 0 and WRD = 0), all of the uC memory (Flash AND Bootloader areas) are wiped clean.

E

Edit: Setting the LockBits to prevent SPM from writing to the Bootloader Area (BLBB = WLOCK) does not prevent this problem.
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 1944

blank.gif
PostPosted: Tue Nov 17, 2015 5:52 pm    Post subject: Reply with quote

Just in case you develop the art of selective reading, respectively answering, I want to bring up again Marks question, as follows:
Quote:
what kind of hardware do you use?

In my opinion, your hardware is kludge.

Until contrary is proven, I refuse to believe that Atmel lets such an incredible buggy controller out in the wild, as one may believe from reading the ton of your posted problems here in the forum concerning this XMega.
Nothing points to a common problem, do an Internet lookup and you'll find - nothing, search for a bootloader appnote and you'll find AVR1316, no special provisions therein for E5-support. Furthermore I've compiled and went through the BL's disassembly while doing a simulation.
Not completely, but already till the app_erase command &h20 is SPM'd and subsequent check for execution is done, means the point where you tell, it locks up.

Everything looks fine, registers are addressed as they should be and functionality conforms to C-code of AVR1316.
So till Atmel admits their E5-model is crap, I rather believe your hardware is.
Maybe you got a Chinese clone with a cheap $2.50 watch ticking inside Very Happy
Back to top
View user's profile
enniom

Bascom Member



Joined: 20 Oct 2009
Posts: 496

PostPosted: Tue Nov 17, 2015 7:50 pm    Post subject: Reply with quote

Hello MWS,

You are absolutely right .... looking at this from a distance seems incredible.

I would very much like someone to use the bootloading approach described here (ie: BASCOM samples) to determine if a successful Flash programming can be made. Until then, I am stuck without constructive feedback.

I have programmed many PCB's with this approach but using XMEGA 192A3 and the BASCOM sample code. Six PCB's with 16 and 32E5 uCs, and the problem is as I describe here. Everything else is the same.

I think you'll also agree that one of the problems associated with buffered UART was resolved by Mark.

NOTE: all uC have been purchased from Digikey.

E
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum