This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Cortex-M0] I don't know why this is hard fault.

my simple code is ...
--------------------------------------------------------------

unsigned char flag[3] = {0,};
unsigned char abc, sdf, def ;
void main (void)
{
   while(1)
  {
     //if( flag[0] == 0 && flag[1] == 0 && flag[2] == 0 )
       if ( ((*((int *)flag)) & 0xFFFFFF00) == 0 )
       {
            abc &= ~0x1;
            sdf = 0;
            if( def )
            {
                //do_something;
            }
       }
  }
}


-------------------------------------------------------------
this code is going to hard fault handler..
and
-------------------------------------------------------------

unsigned char flag[3] = {0,};
unsigned char abc, sdf, def ;
void main (void)
{
   while(1)
  {
     //if( flag[0] == 0 && flag[1] == 0 && flag[2] == 0 )
       if ( ((*((int *)flag)) & 0xFFFFFF00) == 0 )
       {
        //   abc &= ~0x1;
        //   sdf = 0;
            if( def )
            {
                //do_something;
            }
       }
  }
}


-------------------------------------------------------------
this code is working well..

-------------------------------------------------------------

unsigned char flag[3] = {0,};
unsigned char abc, sdf, def ;
void main (void)
{
   while(1)
  {
     //if( flag[0] == 0 && flag[1] == 0 && flag[2] == 0 )
       if ( ((*((int *)flag)) & 0xFFFFFF00) == 0 )
       {
           abc &= ~0x1;
           sdf = 0;
         /*if( def )
            {
                //do_something;
            }
         */
       }
  }
}


-------------------------------------------------------------
this is also working well..
please let me know what's the problem.. are there any guru??

Parents
  • Single step thru the code. you should clearly see where it faults.

    My guess is 'coz you're typecasting a char pointer to an int pointer. Probably an alignment fault.

    ps I'm not a guru, but I have at least looked at a few manuals.

Reply
  • Single step thru the code. you should clearly see where it faults.

    My guess is 'coz you're typecasting a char pointer to an int pointer. Probably an alignment fault.

    ps I'm not a guru, but I have at least looked at a few manuals.

Children
No data