Atmel website | ARM Community | AVR freaks | Technical Support
Banner
 FAQ •  Search •  Register •  Login 

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: how to set the GPNVM1 through programming with c++
PostPosted: Thu Mar 08, 2012 2:59 pm 
Offline

Joined: Thu Mar 08, 2012 10:43 am
Posts: 4
hello
I want to program using sam-ba.dll by myself to achieve the functional like the SAM-BA that could upload file to AT91SAM3U4-EK。I know that the program can load from flash 0 throuth set GPNVM0、GPNVM1、GPNVM2,However,I don't know how to write the code with c++. So I need your help ,thank you!


Top
 Profile  
 
 Post subject: Re: how to set the GPNVM1 through programming with c++
PostPosted: Fri Mar 09, 2012 3:29 am 
Offline

Joined: Thu Mar 08, 2012 10:43 am
Posts: 4
mininiu5216 wrote:
hello
I want to program using sam-ba.dll by myself to achieve the functional like the SAM-BA that could upload file to AT91SAM3U4-EK。I know that the program can load from flash 0 throuth set GPNVM0、GPNVM1、GPNVM2,However,I don't know how to write the code with c++. So I need your help ,thank you!


Top
 Profile  
 
 Post subject: Re: how to set the GPNVM1 through programming with c++
PostPosted: Fri Mar 09, 2012 2:09 pm 
Offline

Joined: Fri Mar 09, 2012 1:34 pm
Posts: 68
Hi!
I am not familiar with the SAM3 family, but I wrote a piece of code for SAM7 that worked like a bootloader. The firmware was downloaded via GSM modem. Then the processor reprogrammed itself.

In your case, you'd like to use USART to achieve similar? Right? If this is the case, I can send you *.h and *.cpp files to study. It might be a good starting point.

Best regards
Przemyslaw Baranski

_________________
Best regards
Przemyslaw Baranski


Top
 Profile  
 
 Post subject: Re: how to set the GPNVM1 through programming with c++
PostPosted: Sat Mar 10, 2012 2:06 pm 
Offline

Joined: Thu Mar 08, 2012 10:43 am
Posts: 4
Hi
thank you for your reply.I want to program a little tool by myself which can upload the .bin to the flash through USB.Then the program can start and run from flash .
To realize this function,First,we should initialize flash through the applet and set GPNVM1 (my idea).Is there some experience for the question to you?
thanks!


Top
 Profile  
 
 Post subject: Re: how to set the GPNVM1 through programming with c++
PostPosted: Sat Mar 10, 2012 2:47 pm 
Offline

Joined: Fri Mar 09, 2012 1:34 pm
Posts: 68
Hi!
This is not easy but doable.
1) I'd suggest USART instead of USB. It's much easier. You can use FTDI to convert from USB<->UART

2) The program should be properly structured:
a) Reset
b) Basic initialization
c) Bootloader - check through USART if new software available. If so download it and reprogram "User program". If not jump to "User program"
d) User program

3) There are following things that should be considered:
a) during reprogramming the flash, the bootloader should be run from RAM. The FLASH memory cannot be reprogrammed and used at the same time
b) You might want to check the correctness of the *.bin by adding some control sum, e.g. 16-bit CRC
c) You make the whole updating procedure immune against unexpected events like power failure etc in which case the procedure should recover from it. After reflashing, the bootloader should check if the program was correctly flashed.

4) Herewith I attach basic files for FLASH operations - setting, clearing FLASH bits, programming FLASH pages etc. Note that the flashram.cpp should be run from RAM. These files were written for SAM7 uC. I guess, they can be easily adapted for your uC. At least, that's a good starting point.

5) You can use fromelf.exe program to convert from *.hex to *.bin.

6) Please, study the files and refer to the documentation. Should the need arise, you can ask here


Attachments:
crc.rar [547 Bytes]
Downloaded 33 times
flash.rar [2.03 KiB]
Downloaded 58 times

_________________
Best regards
Przemyslaw Baranski
Top
 Profile  
 
 Post subject: Re: how to set the GPNVM1 through programming with c++
PostPosted: Thu Apr 19, 2012 2:08 am 
Offline

Joined: Sat Oct 30, 2010 6:04 pm
Posts: 784
You know those aren't CRC (Cyclic Redundancy Check) routines, but rather a VERY weak parity check, right?

This is what a CRC looks like using one of the standard 16-bit polynomials. This is a bitwise method, but could be done faster with 4-bit or 8-bit parallel methods using tables.

Code:
uint16 CRC16(uint16 crc, int count, uint8 *buffer)
{
  int i;

  while(count--)
  {
    crc ^= ((uint16)*buffer++) << 8;
    i = 8;
    while(i--)
      if (crc & 0x8000)
        crc = (crc << 1) ^ 0x1021;
      else
        crc <<= 1;
  }
  return crc;
}

printf("CRC16 %04X\n", CRC16(0xFFFF,0x200,SectorBuffer));


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


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 post attachments in this forum

Search for:
Jump to: