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  [ 13 posts ] 
Author Message
 Post subject: How to set the Brownout detect to on in sam7
PostPosted: Fri Mar 09, 2012 5:37 pm 
Offline

Joined: Fri Mar 09, 2012 5:21 pm
Posts: 6
HI All,

I am really confused about how to set the brownout detection to On in a sam7 processor. It should be easy but obviously its not.

Does anyone have the correct lines of code to write into the .s file in Keil please? or if it is not supposed to be done in there then where do you do it and what do you type????!!

So far i have written in to asmfunctions.s the following:

AT91_MC_FCMD_SET_GP_NVM0
AT91_MC_FCMD_SET_GP_NVM1

but i have no way of knowing if this did the trick or if there is more needed to prepare the flash and write to it and lock it afterwards

All i have found on the internet are some long lists of API headers with no explanation of how to use them and there are no worked examples showing up either.

please help

Thanks :?


Top
 Profile  
 
 Post subject: Re: How to set the Brownout detect to on in sam7
PostPosted: Fri Mar 09, 2012 7:21 pm 
Offline

Joined: Fri Mar 09, 2012 1:34 pm
Posts: 68
Here you go...

#define BOD_POWER_ON_BIT 0
#define BOD_RESET_EN_BIT 1


void BOD_PowerOn()
{
if( !BOD_IsPowerOn() )
Flash_SetGPBit( BOD_POWER_ON_BIT );
}

void BOD_PowerOff()
{
if( BOD_IsPowerOn() )
Flash_ClearGPBit( BOD_POWER_ON_BIT );
}

bool BOD_IsPowerOn()
{
return Flash_ReadGPBit( BOD_POWER_ON_BIT );
}

void BOD_ResetEnable()
{
if( !BOD_IsResetEnable() )
Flash_SetGPBit( BOD_RESET_EN_BIT );
}

void BOD_ResetDisable()
{
if( BOD_IsResetEnable() )
Flash_ClearGPBit( BOD_RESET_EN_BIT );
}

bool BOD_IsResetEnable()
{
return Flash_ReadGPBit( BOD_RESET_EN_BIT );
}

_________________
Best regards
Przemyslaw Baranski


Top
 Profile  
 
 Post subject: Re: How to set the Brownout detect to on in sam7
PostPosted: Fri Mar 09, 2012 7:23 pm 
Offline

Joined: Fri Mar 09, 2012 1:34 pm
Posts: 68
And you'll need these functions as well...

#define FLASH_FMCN_BIT 16
#define FLASH_PAGEEN_BIT
bool Flash_SetGPBit( int bitNumber )
{
if( bitNumber > 1 )
return false;

//wait for the ready bit
while( ( AT91C_BASE_MC->MC_FSR & AT91C_MC_FRDY ) == 0 );

//program the number of master clock cycles during 1us
AT91_REG FMR = AT91C_BASE_MC->MC_FMR;
FMR &= ~AT91C_MC_FMCN;
FMR |= FLASH_NUMBER_OF_CYCLES_PER_1US << FLASH_FMCN_BIT;
AT91C_BASE_MC->MC_FMR = FMR;

FlashRam_WriteCommand( FLASH_SGPB, bitNumber );

if( AT91C_BASE_MC->MC_FSR & AT91C_MC_LOCKE )
return false;

if( AT91C_BASE_MC->MC_FSR & AT91C_MC_PROGE )
return false;

//wait cycles

Wait100ms( 1 );

return true;
}

bool Flash_ClearGPBit( int bitNumber )
{
if( bitNumber > 1 )
return false;

//wait for the ready bit
while( ( AT91C_BASE_MC->MC_FSR & AT91C_MC_FRDY ) == 0 );

//program the number of master clock cycles during 1us
//program the number of master clock cycles during 1us
AT91_REG FMR = AT91C_BASE_MC->MC_FMR;
FMR &= ~AT91C_MC_FMCN;
FMR |= FLASH_NUMBER_OF_CYCLES_PER_1US << FLASH_FMCN_BIT;
AT91C_BASE_MC->MC_FMR = FMR;

FlashRam_WriteCommand( FLASH_CGPB, bitNumber );

if( AT91C_BASE_MC->MC_FSR & AT91C_MC_LOCKE )
return false;

if( AT91C_BASE_MC->MC_FSR & AT91C_MC_PROGE )
return false;

//wait cycles

Wait100ms( 1 );

return true;
}



bool Flash_ReadGPBit( int bitNumber )
{
return AT91C_BASE_MC->MC_FSR & ( 1 << ( bitNumber + 8 ));
}

bool Flash_SetLockBit( int bitNumber )
{
if( bitNumber > 1 )
return false;

//wait for the ready bit
while( ( AT91C_BASE_MC->MC_FSR & AT91C_MC_FRDY ) == 0 );

//program the number of master clock cycles during 1us
AT91C_BASE_MC->MC_FMR &= ~AT91C_MC_FMCN;
AT91C_BASE_MC->MC_FMR |= FLASH_NUMBER_OF_CYCLES_PER_1US << FLASH_FMCN_BIT;

//write command in the register and the byte number in the PAGENB
FlashRam_WriteCommand( FLASH_SLB, bitNumber );


if( AT91C_BASE_MC->MC_FSR & AT91C_MC_LOCKE )
return false;

if( AT91C_BASE_MC->MC_FSR & AT91C_MC_PROGE )
return false;

//wait cycles

return true;
}

bool Flash_ClearLockBit( int bitNumber )
{
if( bitNumber > 1 )
return false;

//wait for the ready bit
while( ( AT91C_BASE_MC->MC_FSR & AT91C_MC_FRDY ) == 0 );

//program the number of master clock cycles during 1us
AT91C_BASE_MC->MC_FMR &= ~AT91C_MC_FMCN;
AT91C_BASE_MC->MC_FMR |= FLASH_NUMBER_OF_CYCLES_PER_1US << FLASH_FMCN_BIT;

//write command in the register and the byte number in the PAGENB
FlashRam_WriteCommand( FLASH_CLB, bitNumber );


if( AT91C_BASE_MC->MC_FSR & AT91C_MC_LOCKE )
return false;

if( AT91C_BASE_MC->MC_FSR & AT91C_MC_PROGE )
return false;

//wait cycles?

return true;
}



bool Flash_ReadLockBit( int bitNumber )
{
if( bitNumber > 16 )
return false;

return AT91C_BASE_MC->MC_FSR & ( 1 << ( bitNumber + 16 ));
}

_________________
Best regards
Przemyslaw Baranski


Top
 Profile  
 
 Post subject: Re: How to set the Brownout detect to on in sam7
PostPosted: Sat Mar 10, 2012 10:14 am 
Offline

Joined: Fri Mar 09, 2012 5:21 pm
Posts: 6
WOW! thats a lot more coding than i thought.

Thanks for your help

I assume you put all this in the first power on section of the coding where you are initialising are the peripherals?

Once again thanks for your help


Top
 Profile  
 
 Post subject: Re: How to set the Brownout detect to on in sam7
PostPosted: Sat Mar 10, 2012 12:01 pm 
Offline

Joined: Fri Mar 09, 2012 1:34 pm
Posts: 68
1) Herewith I enclose you all the necessary files.

2) You can setup the BOD whenever you like.

3) There are also procedures to reflash the micro-controller firmware in case you happen to do sth like this. In this case, please note that flashram.cpp file should be put in the RAM.

4) I'd strongly advise you to refer to the documentation, so that you can see what's going on

Best regards
Przemyslaw Baranski


Attachments:
File comment: All necessary files
files.rar [2.67 KiB]
Downloaded 26 times

_________________
Best regards
Przemyslaw Baranski
Top
 Profile  
 
 Post subject: Re: How to set the Brownout detect to on in sam7
PostPosted: Sat Mar 10, 2012 4:28 pm 
Offline

Joined: Fri Mar 09, 2012 5:21 pm
Posts: 6
Thanks Przemyslaw

I greatly appreciate your help

regards

jim


Top
 Profile  
 
 Post subject: Re: How to set the Brownout detect to on in sam7
PostPosted: Tue Apr 24, 2012 4:20 pm 
Offline

Joined: Fri Mar 09, 2012 5:21 pm
Posts: 6
HI Przemyslaw,

Well i have been working with the code that you gave me for turning on the Brownout reset function for a while and the code compiles fine but at power up the whole system hangs and appears dead.

I noticed that the programmer i inherited this project from had set the security bit SSB in the assembler startup file so i eliminated that with no effect. So i put that item back in but dropped the Brownout enable and brownout reset enable into the assembler section immediately before setting the security bit. Now the system starts up fine for the first time after reprogramming and obviously goes through the enable routines so it appears to have worked and enabled brownout. However the board only powers up the first time. After that it hangs and appears dead just like when i executed the functions from inside the main code modules.

Interestingly if i clear NVM1 instead of setting it, thus disabling the reset function, the board works fine every time. So it appears to be the reset action itself that is causing the problem. It is almost as if brownout is detecting a reset every time it powers up but then the reset fails to function properly. I took the precaution of enabling NRST and setting the hold time for this to 2 seconds in case the power rail was not within specification but this has no effect and pressing the manual reset button similarly has no effect.

Do you have any idea what the problem might be?

regards

jim


Top
 Profile  
 
 Post subject: Re: How to set the Brownout detect to on in sam7
PostPosted: Tue Apr 24, 2012 10:12 pm 
Offline

Joined: Fri Mar 09, 2012 1:34 pm
Posts: 68
Hi!
I haven't experienced such problems. In my main code I activate the BOD and the reset by the following functions:

BOD_PowerOn();
BOD_ResetEnable();

It is working with no problems. Could you check where the code hangs? Is it prefetch or data abort?

_________________
Best regards
Przemyslaw Baranski


Top
 Profile  
 
 Post subject: Re: How to set the Brownout detect to on in sam7
PostPosted: Wed Apr 25, 2012 10:13 am 
Offline

Joined: Fri Mar 09, 2012 1:34 pm
Posts: 68
Have you enabled the user reset?
AT91C_BASE_RSTC->RSTC_RMR = AT91C_RSTC_URSTEN;

_________________
Best regards
Przemyslaw Baranski


Top
 Profile  
 
 Post subject: Re: How to set the Brownout detect to on in sam7
PostPosted: Wed Apr 25, 2012 10:33 am 
Offline

Joined: Fri Mar 09, 2012 5:21 pm
Posts: 6
Yes but the previous programmer has inserted the following immediately before where i enabled the user reset.

MSR CPSR_c,#0xD3

which is annotated as ' svr mode, no irqs, no fiqs, ensure no interrupts can occur and disrupt initialisation'

my code then is

LDR R1, = RSTC_MR
LDR R2, = 0xA5000F01
STR R2, [R1]

which enables extern reset and sets the hold time to 2 seconds ( The reason for enabling BOD is to mitigate the effect of cold cranking of vehicle ignition).


Top
 Profile  
 
 Post subject: Re: How to set the Brownout detect to on in sam7
PostPosted: Wed Apr 25, 2012 10:45 am 
Offline

Joined: Fri Mar 09, 2012 1:34 pm
Posts: 68
Hi!
Did you check the errata regarding the non-volatile bits? There was a limited number of reprogramming.

_________________
Best regards
Przemyslaw Baranski


Top
 Profile  
 
 Post subject: Re: How to set the Brownout detect to on in sam7
PostPosted: Wed Apr 25, 2012 10:49 am 
Offline

Joined: Fri Mar 09, 2012 1:34 pm
Posts: 68
Hi!
You might also check if you don't have a current surge after reset, which prevents the supply voltage rise fast enough. Look at the electrical parameters section, where Atmel gives necessary parameters for the uC to power up properly.
I think, i finally got what the problem in actuality is.

_________________
Best regards
Przemyslaw Baranski


Top
 Profile  
 
 Post subject: Re: How to set the Brownout detect to on in sam7
PostPosted: Fri May 25, 2012 6:06 pm 
Offline

Joined: Fri Mar 09, 2012 5:21 pm
Posts: 6
Hi once again,

Yes i believe you are right about the current surge. i have tested the 3.3v rail to the processor on power on reset and the slope is only about 60mV/ms rise! but i dont understand why the processor starts up ok when brownout reset is not active and fails when it is made active. Surely it should fail to power up all the time?

regards

JIm


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 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: