how to set the GPNVM1 through programming with c++

Discussion around product based on ARM Cortex M3 core.

Moderators: nferre, ncollot

mininiu5216
Posts: 4
Joined: Thu Mar 08, 2012 10:43 am

how to set the GPNVM1 through programming with c++

Thu Mar 08, 2012 2:59 pm

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!
mininiu5216
Posts: 4
Joined: Thu Mar 08, 2012 10:43 am

Re: how to set the GPNVM1 through programming with c++

Fri Mar 09, 2012 3:29 am

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!
przemekbary
Posts: 68
Joined: Fri Mar 09, 2012 1:34 pm

Re: how to set the GPNVM1 through programming with c++

Fri Mar 09, 2012 2:09 pm

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
mininiu5216
Posts: 4
Joined: Thu Mar 08, 2012 10:43 am

Re: how to set the GPNVM1 through programming with c++

Sat Mar 10, 2012 2:06 pm

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!
przemekbary
Posts: 68
Joined: Fri Mar 09, 2012 1:34 pm

Re: how to set the GPNVM1 through programming with c++

Sat Mar 10, 2012 2:47 pm

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 94 times
flash.rar
(2.03 KiB) Downloaded 135 times
Best regards
Przemyslaw Baranski
CptTitanic
Posts: 871
Joined: Sat Oct 30, 2010 6:04 pm

Re: how to set the GPNVM1 through programming with c++

Thu Apr 19, 2012 2:08 am

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: Select all

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));

Return to “SAM3 Cortex-M3 MCU”

Who is online

Users browsing this forum: No registered users and 2 guests