Пример #1
0
void System_Init(void)
{
    INTX_DISABLE();  //close all interruption
    HF_BSP_Init();
    enter_bootloader_flag=STMFLASH_ReadWord(FLASH_APP1_ADDR - 4);
    if(enter_bootloader_flag !=256 )    //jump to app code
    {
        enter_bootloader_flag=256;
        STMFLASH_Write(FLASH_APP1_ADDR - 4 , &enter_bootloader_flag , 1);
        HF_Set_Beep_State(1);
        delay_ms(500);
        delay_ms(500);
        HF_Set_Beep_State(0);
        enter_bootloader_flag=0;
        STMFLASH_Write(FLASH_APP1_ADDR - 4 , &enter_bootloader_flag , 1);
        Load_Flash_APP(FLASH_APP1_ADDR);
    }
    enter_bootloader_flag = 0;
    STMFLASH_Write(FLASH_APP1_ADDR - 4 , &enter_bootloader_flag , 1);
    HF_Set_Beep_State(1);
    delay_ms(500);
    delay_ms(500);
    delay_ms(500);
    delay_ms(500);
    HF_Set_Beep_State(0);
    INTX_ENABLE();	 //enable all interruption
}
Пример #2
0
//appxaddr:应用程序的起始地址
//appbuf:应用程序CODE.
//appsize:应用程序大小(字节).
void iap_write_appbin(uint32_t appxaddr,uint8_t *appbuf,uint32_t appsize)
{
	uint32_t t;
	uint16_t i=0,j=0;
	uint32_t temp;
	uint32_t fwaddr=appxaddr;//当前写入的地址
	uint8_t *dfu=binbuf;
	uint8_t *dfu2=appbuf;

	for(i=0;i<appsize/1024;i++)
	{
		//	printf("111111111111111\r\n");
			dfu=binbuf;
			utils_string2bin((char *)dfu2,binbuf,1024);
			for(t=0;t<128;t++)
			{					
				temp=(uint32_t)dfu[3]<<24;   
				temp|=(uint32_t)dfu[2]<<16;    
				temp|=(uint32_t)dfu[1]<<8;
				temp|=(uint32_t)dfu[0];	  
				dfu+=4;//偏移4个字节
				iapbuf[j++]=temp;	     
			} 
			STMFLASH_Write(fwaddr,iapbuf,128);
			File_CRC=crc32(File_CRC,binbuf,512);
			fwaddr+=512;//偏移2048  512*4=2048
			dfu2+=1024;
//			for(j=0;j<512;j++)
//			{
//					printf("%d\r\n",binbuf[j]);
//			}
			j=0;
	}
	
	if(appsize%1024>0)
	{
			dfu=binbuf;
			utils_string2bin((char *)dfu2,binbuf,appsize%1024);
			for(t=0;t<(appsize%1024/2+3)/4;t++)
			{					
				temp=(uint32_t)dfu[3]<<24;   
				temp|=(uint32_t)dfu[2]<<16;    
				temp|=(uint32_t)dfu[1]<<8;
				temp|=(uint32_t)dfu[0];	  
				dfu+=4;//偏移4个字节
				iapbuf[j++]=temp;	     
			} 
			STMFLASH_Write(fwaddr,iapbuf,j);
			File_CRC=crc32(File_CRC,binbuf,(appsize%1024/2));
//			for(j=0;j<appsize%1024/2;j++)
//			{
//					printf("%d\r\n",binbuf[j]);
//			}
	}
}
Пример #3
0
//写入PID值
void PID_WriteFlash(void)
{
	u8 point=29;
	u16 flash_data[39];
	
	//读出Flash数据
	STMFLASH_Read(PAGE1,flash_data,39);
	
	//数据重新写入PID数据!
	flash_data[point++] = ADJUST_FLAG;
	
	flash_data[point++] = (u16)(PID_ROL.P*1000);
	flash_data[point++] = (u16)(PID_ROL.I*1000);
	flash_data[point++] = (u16)(PID_ROL.D*1000);
	
	flash_data[point++] = (u16)(PID_PIT.P*1000);
	flash_data[point++] = (u16)(PID_PIT.I*1000);
	flash_data[point++] = (u16)(PID_PIT.D*1000);
	
	flash_data[point++] = (u16)(PID_YAW.P*1000);
	flash_data[point++] = (u16)(PID_YAW.I*1000);
	flash_data[point++] = (u16)(PID_YAW.D*1000);
	
	//写入Flash数据
	STMFLASH_Write(PAGE1,flash_data,39);
	
}
static void save_data_to_flash()
{
    pd_printf("saving data to flash...\n");
    int32 magic = PANDO_CONFIG_MAGIC;
    STMFLASH_Write(PANDO_CONFIG_ADDRESS, (uint16 *)(&magic), sizeof(int32));
    struct data_pair * cur;
    int32 cnt = 0;
    for(cur=head; cur!=NULL; cur=cur->next) 
    {
        STMFLASH_Write(PANDO_CONFIG_ADDRESS + sizeof(int32) + sizeof(int32) + (cnt * sizeof(struct data_pair)),
            (uint16 *)cur, sizeof(struct data_pair));
        cnt ++;
    }
    STMFLASH_Write(PANDO_CONFIG_ADDRESS + sizeof(int32),
        (uint16 *)&cnt, sizeof(int32));
    pd_printf("done...\n");
}
//函数名:ParameterWrite()
//输入:无
//输出:当收到地址29的字节为0xA5时,返回1,否则返回0
//描述:飞机开机后,当检测到写入参数模式时,写参数用
//作者:马骏
//备注:没考上研,心情不好
char  ParameterWrite()
{

        PIDWriteBuf[0]=16;
        PIDWriteBuf[1]=0;
        PIDWriteBuf[2]=8;//写PID参数  
        STMFLASH_Write(STM32_FLASH_BASE+STM32_FLASH_OFFEST+PIDParameterAdd,PIDWriteBuf,3); //PID 参数写入
  
return 0;
}
Пример #6
0
void TableWriteEEPROM(void)
{
//		uint8_t i=0;
//		float *p;
		uint8_t paramNums=sizeof(table)/sizeof(float);
//		for(i=0;i<sizeof(table);i++)
//		{
//			 p=(float *)(&table) + i;
//			 STMFLASH_Write(TABLE_ADDRESS,(uint16_t *)p,2);
//		}
		STMFLASH_Write(TABLE_ADDRESS,(uint16_t *)(&table),paramNums * 2);
}
Пример #7
0
//函数名:ParameterWrite()
//输入:无
//输出:当收到地址29的字节为0xA5时,返回1,否则返回0
//描述:飞机开机后,当检测到写入参数模式时,写参数用
//作者:马骏
//备注:没考上研,心情不好
char  ParameterWrite()
{
//         PIDParameter.WriteBuf[0] = 23;
//         PIDParameter.WriteBuf[1] = 1;
//         PIDParameter.WriteBuf[2] = 4;
//   
//         BTParameter.WriteBuf[1]  = 0;
//         BTParameter.WriteBuf[2]  = 0;
  
        //STMFLASH_Write(STM32_FLASH_BASE+STM32_FLASH_OFFEST+PIDParameterAdd,PIDParameter.WriteBuf,3); //PID 参数写入Flash
        STMFLASH_Write(STM32_FLASH_BASE+STM32_FLASH_OFFEST+BTParameterAdd,BTParameter.WriteBuf,3);  //蓝牙配置参数写入Flash
       
return 0;
}
Пример #8
0
void BoardConfiguration(void)
{
	u8* upBuffer;
	if(processedData.fun_m==0x01)
	{
		upBuffer=GetBoardInformation();
	
		if(processedData.fun_s==0x01&&uploadTime>0)//上传
		{
			SendData_Check(upBuffer,BOARD_ID_CONFIGURATION_SIZE);
			delay_ms(100);
			uploadTime--;
		}
		else if(processedData.fun_s==0x02&&isConfigured==0)
		{
			STMFLASH_Write(FLASH_SAVE_ADDR,(u16*)receivedData.data,BOARD_ID_CONFIGURATION_SIZE);
			isConfigured=1;
		}
		
	}
}
Пример #9
0
//table defalat . if
void TableResetDefault(void)
{
//		table.version=1.0f;

		STMFLASH_Write(TABLE_ADDRESS,(uint16_t *)(&(table.version)),2);
}
Пример #10
0
//////////////////////////////////////////////////////////////////////////////////////////////////////
//WriteAddr:起始地址
//WriteData:要写入的数据
void Test_Write(u32 WriteAddr,u16 WriteData)   	
{
	STMFLASH_Write(WriteAddr,&WriteData,1);//写入一个字 
}
Пример #11
0
void Iap_Write(uint32_t addr)
{
	uint16_t temp = 0;
	uint16_t data_size = 0;																	//烧录大小
	uint32_t data_len = 0;																	//数据长度
	uint16_t index = 0;																			//数据块索引
	uint32_t crc_val = 0;
	uint32_t addr_now = addr;																//写入地址
	uint8_t data_write[DATA_SIZE] = {0};										//数据缓冲
	
	//
	while(1)
	{
		while((buf_cnt & 0x8000) == 0)													//等待数据接收完毕
		{
			LcdDispValue(1,280,10,"%ds  ",60-Watch_Cnt/2);
			if(Watch_Cnt>WatchTime)	//--WatchTime没有接收到数据转入备用程序
			{
				TIM_ITConfig(TIM4,TIM_IT_Update,DISABLE );	
				LcdDispValue(1,X_Height,Y_Height+120,"Jump into application...");
				Delay_ms(500);
				TIM_ITConfig(TIM3,TIM_IT_Update,DISABLE );
					
				printf("#F7C|HEARTON*");
				Delay_ms(50);
				printf("#SPAREAPP*\r\n");
				Delay_ms(50);
				Iap_load(APP_ADDR2);				//启用备份区程序
			}
		}
		Watch_Cnt = 0;	//--喂模拟窗口狗
		//解析数据
		data_len = (uint32_t)usart_buf[1] << 8 | usart_buf[0];				//获取data有效长度
		if(data_len > 1024)	//--
			data_len = 1024;
		for(temp = 2; temp < data_len + 2; temp++)								//从第二位开始拷贝数据
		{
			data_write[temp - 2] = usart_buf[temp];
		}
		index = usart_buf[DATA_SIZE + 3] << 8 | usart_buf[DATA_SIZE + 2];				//获取地址索引
		crc_val =  usart_buf[DATA_SIZE + 7] << 24 | usart_buf[DATA_SIZE + 6] << 16 | 	//获取CRC值
						  usart_buf[DATA_SIZE + 5] << 8 | usart_buf[DATA_SIZE + 4] ;
		
		addr_now = addr + 1024 * index;		//准备写入地址
		//使用 USART_BUF_SIZE / 4 无法得到长度
		temp = USART_BUF_SIZE ;
		temp /= 4;
		if(!CRC_GetVal((uint32_t *)usart_buf, temp, crc_val))
		{
			printf("Again\n");
			buf_cnt = 0;
			continue;
		}
		//开始写数据
		if(data_len < 1024)																		//写入剩下的数据
		{
			if(data_len % 2 != 0)	//		可能需要除4待定
			{
				data_len += 1;
			}
			STMFLASH_Write(addr_now, (uint32_t *)data_write, data_len / 4);//(uint16_t 2
			data_size += 1;
			STMFLASH_Write(IAP_INFO, &data_len, 1);
			printf("OK\n");
			break;
		}
		else
		{
			STMFLASH_Write(addr_now, (uint32_t*)data_write, data_len / 4);//(uint16_t 
			data_size += 1;
			buf_cnt = 0;
			for(temp = 0; temp < USART_BUF_SIZE; temp++)usart_buf[temp] = 0;
			LcdDispValue(1,X_Height,Y_Height+80,"Upgrading...");
			printf("Next\n");
		}
	}		//烧录完成
	
	//清空串口缓存
	buf_cnt = 0;
	for(temp = 0; temp < USART_BUF_SIZE; temp++)usart_buf[temp] = 0;
}
Пример #12
0
void TableWriteEEPROM(void)
{
		uint8_t paramNums=sizeof(table)/sizeof(float);

		STMFLASH_Write(TABLE_ADDRESS,(uint16_t *)(&table),paramNums * 2);
}
Пример #13
0
//设置22个舵机初始位置
void steering_set_init(void) {
    steering_data.mark=STEERING_INIT_MARK;//标志以设置初始位置
    steering_get(steering_data.init);
    STMFLASH_Write(STEERING_DATA_ADDR, (u16*)(&steering_data), sizeof(struct steering_type));
}