Exemple #1
0
/**
 * at the beginning in main.o ?
 */
void main(void)
{
	u8 i;
	//used for printf
	UART3_Init(
					115200,
					UART3_WORDLENGTH_8D,
					UART3_STOPBITS_1,
					UART3_PARITY_NO,
					UART3_MODE_TXRX_ENABLE);

  //UART3_ClearITPendingBit(UART1_IT_RXNE);
	
	_fctcpy('F');
	
	iap_init_global();
	iap_init_UART1_lib();
	
	//"AAA"->"descriptor"->"const initialized from area"->".FLASH_CODE image"
	printf("AAAA\r\n");
	
	while (1){
		iap_checking();
	}
}
/**
  * @brief this function checks if a NDEF message is available
	* @par Parameters None
  * @retval none
  */
static void User_DisplayMessageActiveHaltMode ( uint8_t PayloadLength )
{

	
		//Switch the clock to LSE and disable HSI
		#ifdef USE_LSE
			CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1);
			CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_LSE);	
			CLK_SYSCLKSourceSwitchCmd(ENABLE);
			while (((CLK->SWCR)& 0x01)==0x01);
			CLK_HSICmd(DISABLE);
			CLK->ECKCR &= ~0x01; 
		#else
			CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1);
			CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_LSI);
			CLK_SYSCLKSourceSwitchCmd(ENABLE);
			while (((CLK->SWCR)& 0x01)==0x01);
			CLK_HSICmd(DISABLE);
			CLK->ECKCR &= ~0x01; 
		#endif	
		
		// disable interupt				
		sim();
		// To copy function DISPLAYRAM in RAM section DISPLAY
		#ifdef _COSMIC_
			if (!(_fctcpy('D')))
				while(1);
		#endif
				
			Display_Ram (); // Call in RAM
			
		//	state_machine = STATE_VREF;
						
		#ifdef USE_HSI
			//Switch the clock to HSI
			CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_16);
			CLK_HSICmd(ENABLE);
			while (((CLK->ICKCR)& 0x02)!=0x02);			
			CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSI);
			CLK_SYSCLKSourceSwitchCmd(ENABLE);
			while (((CLK->SWCR)& 0x01)==0x01);
		#else
			CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_2);
			// Select 2MHz HSE as system clock source 
			CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSE);
			// wait until the target clock source is ready 
			while (((CLK->SWCR)& 0x01)==0x01);
			// wait until the target clock source is ready 
			CLK_SYSCLKSourceSwitchCmd(ENABLE);
		#endif
							
		// enable interupt				
		rim();
		

}
Exemple #3
0
/////////////////
//	main routine
/////////////////
void main (void) {
  
  uint8_t   val;    // misc variable

  /////////////////
  //	init peripherals
  /////////////////
  
  // disable interrupts
  DISABLE_INTERRUPTS;

  // copy flash block w/e routines to RAM (if required)
  #if defined(FLASH_BLOCK_OPS) && defined(__CSMC__)
    _fctcpy('R');
  #endif
  
  // switch to 16MHz (default is 2MHz)
  CLK.CKDIVR.byte = 0x00;  
  
  // set option byte for PD4 as beeper output. On modification trigger SW reset 
  val = 0;
  val += flash_write_option_byte(OPT2,   0x80);   // option byte
  val += flash_write_option_byte(NOPT2,  0x7F);   // complementary option byte
  if (val)  WWDG.CR.byte = 0xBF;                  // on change trigger reset
  
  // init timer TIM3 for sleep_x()
  tim3_init();

  // configure beeper pin as output (PD4)
  gpio_init(&PORT_D, PIN_4, OUTPUT_PUSHPULL_FAST);
  
  // enable interrupts
  ENABLE_INTERRUPTS;
    
    
  /////////////////
  //	main loop
  /////////////////
  val = 1;
  while (1) {
    
    // beeper control
    beep(val, 8);     // short bleep
    beep(0, 1000);    // 1s pause
    
    // change frequency [kHz] (supported: 1,2,4)
    if ((val*=2) >4) val=1;
    
  } // main loop

} // main
/**
  * @brief Function to initialize the entry in low power and wait modes
  * @caller test low power mode
  * @param None   
  * @retval None
  */
void LPR_init(void)
{

/*Switch the clock to LSE and disable HSI*/
  #ifdef USE_LSE
    CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_LSE);	
    CLK_SYSCLKSourceSwitchCmd(ENABLE);
    while (((CLK->SWCR)& 0x01)==0x01);
    CLK_HSICmd(DISABLE);
  #else
    CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1);
    CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_LSI);
    CLK_SYSCLKSourceSwitchCmd(ENABLE);
    while (((CLK->SWCR)& 0x01)==0x01);
    CLK_HSICmd(DISABLE);
  #endif

/*Configure event for WAKEUP and FUNCTION, disable the interrupts*/

  sim();
	
/* To copy function LPR_Ram in RAM section LPRUN*/
#ifdef _COSMIC_
  if (!(_fctcpy('L')))
    while(1);
#endif

  LPR_Ram(); // Call in RAM
  
  /*Switch the clock to HSI*/
  CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_8);
  CLK_HSICmd(ENABLE);
  while (((CLK->ICKCR)& 0x02)!=0x02);
  
  CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSI);
  CLK_SYSCLKSourceSwitchCmd(ENABLE);
  while (((CLK->SWCR)& 0x01)==0x01);

}
Exemple #5
0
/**
  * @brief How to Write byte / Write word / Erase a block on FLASH memory.
  * @par Example description
  * - Program 32/64 (FLASH_BLOCK_SIZE/2) bytes from flash program memory end physical address minus FLASH_BLOCK_SIZE up to 
	*   flash program memory end physical address minus FLASH_BLOCK_SIZE/2.
  * - Check programmed bytes
  * - Program 8/16 (FLASH_BLOCK_SIZE/8) words from flash program memory end physical address minus FLASH_BLOCK_SIZE/2 up to 
	*   flash program memory end physical address.
  * - Checked programmed words
  * - Erase the last block in flash program memory
  * - Check erase
  * @par Parameters:
  * None
  * @retval 
  * None
  */
void main(void)
{
    u32 add, start_add, stop_add, new_val2 =0;
    u8 new_val1, val =0;
    u16 block =0;
    u8 i =0;

    _fctcpy('b');

    /* Define flash programming Time */
    FLASH_SetProgrammingTime(FLASH_PROGRAMTIME_STANDARD);

    /* Unlock Program memory */
    FLASH_Unlock(FLASH_MEMTYPE_PROG);
    /* Program FLASH_BLOCK_SIZE/2 bytes & check */
    start_add = FLASH_PROG_END_PHYSICAL_ADDRESS - FLASH_BLOCK_SIZE +1;
    stop_add = start_add + FLASH_BLOCK_SIZE/2;
    new_val1 = 0x55;
    for (add = start_add; add < stop_add; add++)
            {
                FLASH_ProgramByte(add, new_val1);
                if (FLASH_ReadByte(add) != new_val1)
                {
                    /* Error */
                    OperationStatus = FAILED;
                    /* OperationStatus = PASSED, if the data written/read to/from FLASH Program memory is correct */
                    /* OperationStatus = FAILED, if the data written/read to/from FLASH Program memory is corrupted */
                    while (1);
                }
            }

    /* Program FLASH_BLOCK_SIZE/8 words & check */
    start_add = stop_add;
    stop_add = FLASH_PROG_END_PHYSICAL_ADDRESS;
    new_val2 = 0x12345678;
    add = start_add;
    for (i = 0; i < FLASH_BLOCK_SIZE/8; i++)
    {
        FLASH_ProgramWord(add, new_val2);
        add = add + 4;
    }

    /* check */
    for (add = start_add; add < stop_add; add++)
            {

                val = FLASH_ReadByte(add);
                if (val != BYTE_3(new_val2))
                {
                    /* Error */
                    OperationStatus = FAILED;
                    /* OperationStatus = PASSED, if the data written/read to/from FLASH Program memory is correct */
                    /* OperationStatus = FAILED, if the data written/read to/from FLASH Program memory is corrupted */
                    while (1);
                }

                add += 1;
                val = FLASH_ReadByte(add);
                if (val != BYTE_2(new_val2))
                {
                    /* Error */
                    OperationStatus = FAILED;
                    /* OperationStatus = PASSED, if the data written/read to/from FLASH Program memory is correct */
                    /* OperationStatus = FAILED, if the data written/read to/from FLASH Program memory is corrupted */
                    while (1);
                }

                add += 1;
                val = FLASH_ReadByte(add);
                if (val != BYTE_1(new_val2))
                {
                    /* Error */
                    OperationStatus = FAILED;
                    /* OperationStatus = PASSED, if the data written/read to/from FLASH Program memory is correct */
                    /* OperationStatus = FAILED, if the data written/read to/from FLASH Program memory is corrupted */
                    while (1);
                }

                add += 1;
                val = FLASH_ReadByte(add);
                if (val != BYTE_0(new_val2))
                {
                    /* Error */
                    OperationStatus = FAILED;
                    /* OperationStatus = PASSED, if the data written/read to/from FLASH Program memory is correct */
                    /* OperationStatus = FAILED, if the data written/read to/from FLASH Program memory is corrupted */
                    while (1);
                }
            }

    /* Erase the last block & check */
    block = FLASH_PROG_BLOCKS_NUMBER -1; /* Last block of Flash program memory */
    start_add = FLASH_PROG_END_PHYSICAL_ADDRESS - FLASH_BLOCK_SIZE +1;
    stop_add = FLASH_PROG_END_PHYSICAL_ADDRESS;
		/* Without calling the FLASH_WaitForLastOperation function */
		/* When the program goes back to Flash program memory, it is stalled untill the block erase operation is complete.*/
    FLASH_EraseBlock(block, FLASH_MEMTYPE_PROG);

    for (add = start_add; add < stop_add; add++)
            {
                if (FLASH_ReadByte(add) != 0x00)
                {
                    /* Error */
                    OperationStatus = FAILED;
                    /* OperationStatus = PASSED, if the data written/read to/from FLASH Program memory is correct */
                    /* OperationStatus = FAILED, if the data written/read to/from FLASH Program memory is corrupted */
                    while (1);
                }
            }

    /* Pass */
    OperationStatus = PASSED;
    /* OperationStatus = PASSED, if the data written/read to/from FLASH Program memory is correct */
    /* OperationStatus = FAILED, if the data written/read to/from FLASH Program memory is corrupted */
    while (1);

}
Exemple #6
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
  uint32_t add, startadd, stopadd = 0;
  uint8_t newval = 0xAA;
  uint8_t i = 0;

#ifdef _COSMIC_
/* Call the _fctcpy() function with the first segment character as parameter 
   "_fctcpy('F');"  for a manual copy of the declared moveable code segment
   (FLASH_CODE) in RAM before execution*/
  _fctcpy('F');
#endif /*_COSMIC_*/

#ifdef _RAISONANCE_
/* Call the standard C library: memcpy() or fmemcpy() functions available through 
   the <string.h> to copy the inram function to the RAM destination address */
  MEMCPY(FLASH_EraseBlock,
         (void PointerAttr*)&__address__FLASH_EraseBlock,
         (int)&__size__FLASH_EraseBlock);
  MEMCPY(FLASH_ProgramBlock,
         (void PointerAttr*)&__address__FLASH_ProgramBlock,
         (int)&__size__FLASH_ProgramBlock);
#endif /*_RAISONANCE_*/

  /* Initialize I/Os in Output Mode */
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);

  /* High speed internal clock prescaler */
  CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1);

  /* Define flash programming Time*/
  FLASH_SetProgrammingTime(FLASH_ProgramTime_Standard);

  FLASH_Unlock(FLASH_MemType_Program);
  /* Wait until Flash Program area unlocked flag is set*/
  while (FLASH_GetFlagStatus(FLASH_FLAG_PUL) == RESET)
  {}

  /* Unlock flash data eeprom memory */
  FLASH_Unlock(FLASH_MemType_Data);
  /* Wait until Data EEPROM area unlocked flag is set*/
  while (FLASH_GetFlagStatus(FLASH_FLAG_DUL) == RESET)
  {}

  /* Fill the buffer in RAM */
  for (i = 0; i < FLASH_BLOCK_SIZE; i++)
  {
    GBuffer[i] = newval;
  }
  /* This function is executed from RAM */
  FLASH_ProgramBlock(BLOCK_OPERATION, FLASH_MemType_Data, FLASH_ProgramMode_Standard, GBuffer);
  
  /* Wait until End of high voltage flag is set*/
  while (FLASH_GetFlagStatus(FLASH_FLAG_HVOFF) == RESET)
  {}
  /* Check the programmed block */
  startadd = FLASH_DATA_EEPROM_START_PHYSICAL_ADDRESS + ((uint16_t)BLOCK_OPERATION * (uint16_t)FLASH_BLOCK_SIZE);
  stopadd = startadd + (uint16_t)FLASH_BLOCK_SIZE;
  for (add = startadd; add < stopadd; add++)
      {
        if (FLASH_ReadByte(add) != newval)
        {
          /* Error */
          OperationStatus = FAILED;
          /* OperationStatus = PASSED, if the data written/read to/from Flash program memory is correct */
          /* OperationStatus = FAILED, if the data written/read to/from Flash program memory is corrupted */
          while (1)
          {
            STM_EVAL_LEDToggle(LED1); /*FAIL: write error */
            
            Delay(0xFFFF);
          }
        }
      }
  /* Erase block 0 and verify it */
  /* This function is executed from RAM */
  FLASH_EraseBlock(BLOCK_OPERATION, FLASH_MemType_Data);

  /* Wait until End of high voltage flag is set*/
  while (FLASH_GetFlagStatus(FLASH_FLAG_HVOFF) == RESET)
  {}

  for (add = startadd; add < stopadd; add++)
      {
        if (FLASH_ReadByte(add) != 0x00)
        {
          /* Error */
          OperationStatus = FAILED;
          /* OperationStatus = PASSED, if the data written/read to/from Flash program memory is correct */
          /* OperationStatus = FAILED, if the data written/read to/from Flash program memory is corrupted */
          while (1)
          {
            STM_EVAL_LEDToggle(LED2); /* FAIL: Erase error */
            
           Delay(0xFFFF);
          }
        }
      }

  /* Pass */
  OperationStatus = PASSED;
  /* OperationStatus = PASSED, if the data written/read to/from Flash program memory is correct */
  /* OperationStatus = FAILED, if the data written/read to/from Flash program memory is corrupted */
  while (1)
  {
    STM_EVAL_LEDToggle(LED3); /* PASS: without errors*/
    
    Delay(0xFFFF);
  }
}