Example #1
0
void updateConfiguration(mxchipWNet_HA_st *configData)
{
  uint32_t paraStartAddress, paraEndAddress;
  
  paraStartAddress = PARA_START_ADDRESS;
  paraEndAddress = PARA_END_ADDRESS;
  
  FLASH_If_Init();
  FLASH_If_Erase(paraStartAddress, paraEndAddress);   
  FLASH_If_Write(&paraStartAddress, (u32 *)&configData->conf, sizeof(mxchipWNet_HA_config_st));
  FLASH_Lock();
}
Example #2
0
void updateConfig(config_t *pConfig)
{
	uint32_t paraStartAddress, paraEndAddress;
	
	paraStartAddress = PARA_START_ADDRESS;
	paraEndAddress = PARA_END_ADDRESS;
	
	FLASH_If_Init();
	FLASH_If_Erase(paraStartAddress, paraEndAddress);		// 擦除16K 数据保存区;	
	FLASH_If_Write(&paraStartAddress, (u32 *)pConfig, sizeof(config_t));
	FLASH_Lock();
}
Example #3
0
/****************************************************************************************
** 函数名称: FlashParaUpdate
** 功能描述: 更新Flash 中保存的参数
** 参           数: 无
** 返   回  值: none
** 作      者: Sevent
** 日      期: 2013年08月27日
**---------------------------------------------------------------------------------------
** 修 改 人: 
** 日   期: 
**--------------------------------------------------------------------------------------
****************************************************************************************/
void FlashParaUpdate(EAbox_st *configData)
{
	uint32_t paraStartAddress, paraEndAddress;
	
	paraStartAddress = PARA_START_ADDRESS;
	paraEndAddress = PARA_END_ADDRESS;
	
	FLASH_If_Init();
	FLASH_If_Erase(paraStartAddress, paraEndAddress);		// 擦除16K 数据保存区;	
	FLASH_If_Write(&paraStartAddress, (u32 *)configData, sizeof(eabox_config_t));
	FLASH_Lock();
}
/**
  * @brief  Processes TFTP write request
  * @param  to: pointer on the receive IP address
  * @param  to_port: receive port number
  * @retval none
  */
static int IAP_tftp_process_write(struct udp_pcb *upcb, struct ip_addr *to, int to_port)
{
  tftp_connection_args *args = NULL;
  /* This function is called from a callback,
  * therefore interrupts are disabled,
  * therefore we can use regular malloc   */
  args = mem_malloc(sizeof *args);
  if (!args)
  {
	 udp_lcd_y += UPDATE_WORD_SIZE + UPDATE_ROW_DISTANCE;
	 lcd_font24(udp_lcd_x,udp_lcd_y,COLOR_POINT,COLOR_BACK,"> ÒÔÌ«ÍøÉý¼¶³ö´íÁË¡£´íÎó´úÂ룺5",UPDATE_FONT); 
	 UDP_AddUpdateError();
// #ifdef USE_LCD
//     LCD_SetTextColor(Red);
//     LCD_DisplayStringLine(Line9, (uint8_t*)"Memory error");
// #endif
    IAP_tftp_cleanup_wr(upcb, args);
    return 0;
  }

  args->op = TFTP_WRQ;
  args->to_ip.addr = to->addr;
  args->to_port = to_port;
  /* the block # used as a positive response to a WRQ is _always_ 0!!! (see RFC1350)  */
  args->block = 0;
  args->tot_bytes = 0;

  /* set callback for receives on this UDP PCB (Protocol Control Block) */
  udp_recv(upcb, IAP_wrq_recv_callback, args);
  
  total_count =0;
  
  /* init flash */
  FLASH_If_Init();
  
  /* erase user flash area */
  FLASH_If_Erase(USER_FLASH_FIRST_PAGE_ADDRESS);
 
  Flash_Write_Address = USER_FLASH_FIRST_PAGE_ADDRESS;    
  /* initiate the write transaction by sending the first ack */
  IAP_tftp_send_ack_packet(upcb, to, to_port, args->block);
  
  lcd_font24(udp_lcd_x,udp_lcd_y,COLOR_POINT,COLOR_BACK,"> ÕýÔÚдÈëÎļþ...",UPDATE_FONT);
  udp_lcd_y += UPDATE_WORD_SIZE + UPDATE_ROW_DISTANCE;
// #ifdef USE_LCD
//   LCD_DisplayStringLine(Line8, (uint8_t*)"State: Programming..");
// #endif
  return 0;
}
Example #5
0
void sampleMemory_loadSamples()
{
	uint8_t numSamples = sd_getNumSamples();


	if(numSamples==0) return;

	//erase user memory flash
	FLASH_If_Erase(SAMPLE_ROM_START_ADDRESS);

	sampleMemory_setNumSamples(numSamples);

	//reserve space for sample info header
	SampleInfo info[50];
	uint32_t addr = 0;

	uint8_t i;
	for(i=0;i<numSamples;i++)
	{
		sd_setActiveSample(i);
		uint32_t len 	= sd_getActiveSampleLength();
		char* name = sd_getActiveSampleName();
		memcpy(info[i].name, name,3);
		info[i].offset 	= SAMPLE_ROM_START_ADDRESS + 4 + addr*4; //+1 because of num_samples
		info[i].size 	= len/2;

		uint32_t j;
		for(j=0;j<len;)
		{
			int16_t data[BLOCKSIZE];
//			uint16_t bytesRead;
//			bytesRead = sd_readSampleData(data, BLOCKSIZE);
			sd_readSampleData(data, BLOCKSIZE);
			volatile uint32_t add = 4+SAMPLE_ROM_START_ADDRESS + 4*addr; //*4 because we write uint32

			FLASH_If_Write(&add, (uint32_t*)data, BLOCKSIZE/2);

			j += BLOCKSIZE*2;
			addr += BLOCKSIZE/2;

		}
	}
	//write info header
	volatile uint32_t add = SAMPLE_INFO_START_ADDRESS ;
	FLASH_If_Write(&add, (uint32_t*)(info), numSamples*sizeof(SampleInfo)/4 + 1);

	spi_deInit();

}
Example #6
0
uint8 program_move(uint16 crc)
{ uint16 app_crc;
	uint16 cmp = 2;
	int t = 0;
	uint32_t addr_src = APP_ERCODE_ADDRESS;
	uint32_t addr_dst = APPLICATION_ADDRESS;
	
  FLASH_If_Init();
	FLASH_If_Erase(APP_ERCODE_ADDRESS);
	FLASH_If_Write((__IO uint32_t* )&addr_dst, (uint32_t*)addr_src ,(0x400/4*29));
	FLASH_Lock();
	app_crc = cal_crc16((uint8*)APPLICATION_ADDRESS, 0x400*29);
	if(crc == app_crc) return 0;
	return 1;
}
Example #7
0
void restoreConfiguration(void)
{	
	EAbox_st	EAboxInit;
	uint32_t paraStartAddress, paraEndAddress;
	
	paraStartAddress = PARA_START_ADDRESS;
	paraEndAddress = PARA_END_ADDRESS;
	memset(&EAboxInit, 0x0, sizeof(EAbox_st));
	EAboxInit.conf.magicNumber = MAGIC_FLAG;
	
	FLASH_If_Init();
	FLASH_If_Erase(paraStartAddress, paraEndAddress);		// 擦除16K 数据保存区;	
	FLASH_If_Write(&paraStartAddress, (void *)&EAboxInit, sizeof(eabox_config_t));
	FLASH_Lock();
}
Example #8
0
void restoreConfig(void)
{	
	config_t	config;
	net_para_st netPara;
	uint32_t paraStartAddress, paraEndAddress;
	paraStartAddress = PARA_START_ADDRESS;
	paraEndAddress = PARA_END_ADDRESS;
	
	getNetPara(&netPara,Station);
	memset(&config, 0x0, sizeof(config_t));
	config.magicNumber = MAGIC_FLAG;
	sprintf((char*)config.wifi_ssid , "MXCHIP_%s", netPara.mac+6);	
	sprintf((char*)config.wifi_key , "");	
	
	FLASH_If_Init();
	FLASH_If_Erase(paraStartAddress, paraEndAddress);		// 擦除16K 数据保存区;	
	FLASH_If_Write(&paraStartAddress, (void *)&config, sizeof(config_t));
	FLASH_Lock();
}
Example #9
0
void FlashConfig(void)
{
	if(FLASH_If_Erase(CONFIG_BASE_ADDRESS,NUMBER_OF_CONFIG_PAGES) == FLASHIF_ERASEKO)
	{
		UserPrintf("Error:flash config error\n");
	}
	else
	{
		uint16_t config_size = sizeof(SystemConfig)/sizeof(uint32_t) + 1; // 防止不能被4整除
		if(FLASH_If_Write(CONFIG_BASE_ADDRESS,(uint32_t *)&SystemConfig, config_size) == 0)
		{
			UserPrintf("Info:Flash success\n");
		}
		else
		{
			UserPrintf("Error:Flash error!Please retry\n");
		}
	}
}
Example #10
0
/**
  * @brief  Processes TFTP write request
  * @param  to: pointer on the receive IP address
  * @param  to_port: receive port number
  * @retval None
  */
static int IAP_tftp_process_write(struct udp_pcb *upcb, struct ip_addr *to, int to_port)
{
    tftp_connection_args *args = NULL;
    /* This function is called from a callback,
    * therefore interrupts are disabled,
    * therefore we can use regular malloc   */
    args = mem_malloc(sizeof *args);
    if (!args)
    {
#ifdef USE_LCD
        LCD_ErrLog("Memory error \n");
#endif
        IAP_tftp_cleanup_wr(upcb, args);
        return 0;
    }

    args->op = TFTP_WRQ;
    args->to_ip.addr = to->addr;
    args->to_port = to_port;
    /* the block # used as a positive response to a WRQ is _always_ 0!!! (see RFC1350)  */
    args->block = 0;
    args->tot_bytes = 0;

    /* set callback for receives on this UDP PCB (Protocol Control Block) */
    udp_recv(upcb, IAP_wrq_recv_callback, args);

    total_count =0;

    /* init flash */
    FLASH_If_Init();

    /* erase user flash area */
    FLASH_If_Erase(USER_FLASH_FIRST_PAGE_ADDRESS);

    Flash_Write_Address = USER_FLASH_FIRST_PAGE_ADDRESS;
    /* initiate the write transaction by sending the first ack */
    IAP_tftp_send_ack_packet(upcb, to, to_port, args->block);
#ifdef USE_LCD
    LCD_UsrLog("  State: Programming... \n");
#endif
    return 0;
}
Example #11
0
void restoreConfiguration(void)
{ 
  mxchipWNet_HA_st  mxchipWNet_HA_Init;
  uint32_t paraStartAddress, paraEndAddress;
  
  paraStartAddress = PARA_START_ADDRESS;
  paraEndAddress = PARA_END_ADDRESS;
  memset(&mxchipWNet_HA_Init, 0x0, sizeof(mxchipWNet_HA_st));
  mxchipWNet_HA_Init.conf.magicNumber = MAGIC_FLAG;
  mxchipWNet_HA_Init.conf.versionNumber = CONFIGURATION_VERSION;
  mxchipWNet_HA_Init.conf.dhcp_enable = 1;
  strcpy((char*)mxchipWNet_HA_Init.conf.sta_ssid, DEFAULT_STA_SSID);
  strcpy((char*)mxchipWNet_HA_Init.conf.sta_key, DEFAULT_STA_KEY);
  strcpy((char*)mxchipWNet_HA_Init.conf.uap_ssid, DEFAULT_UAP_SSID);
  strcpy((char*)mxchipWNet_HA_Init.conf.uap_key, DEFAULT_UAP_KEY);
  strcpy((char*)mxchipWNet_HA_Init.conf.server_domain, DEFAULT_REMOTE_ADDR);
  mxchipWNet_HA_Init.conf.server_port = DEFAULT_REMOTE_PORT;

  FLASH_If_Init();
  FLASH_If_Erase(paraStartAddress, paraEndAddress);  
  FLASH_If_Write(&paraStartAddress, (void *)&mxchipWNet_HA_Init, sizeof(mxchipWNet_HA_config_st));
  FLASH_Lock();
}
/**
  * @brief  Receive a file using the ymodem protocol with CRC16.
  * @param  p_size The size of the file.
  * @retval COM_StatusTypeDef result of reception/programming
  */
COM_StatusTypeDef Ymodem_Receive ( uint32_t *p_size )
{
  uint32_t i, packet_length, session_done = 0, file_done, errors = 0, session_begin = 0;
  uint32_t flashdestination, ramsource, filesize;
  uint8_t *file_ptr;
  uint8_t file_size[FILE_SIZE_LENGTH], tmp, packets_received;
  COM_StatusTypeDef result = COM_OK;

  /* Initialize flashdestination variable */
  flashdestination = APPLICATION_ADDRESS;

  while ((session_done == 0) && (result == COM_OK))
  {
    packets_received = 0;
    file_done = 0;
    while ((file_done == 0) && (result == COM_OK))
    {
      switch (ReceivePacket(aPacketData, &packet_length, DOWNLOAD_TIMEOUT))
      {
        case HAL_OK:
          errors = 0;
          switch (packet_length)
          {
            case 2:
              /* Abort by sender */
              Serial_PutByte(ACK);
              result = COM_ABORT;
              break;
            case 0:
              /* End of transmission */
              Serial_PutByte(ACK);
              file_done = 1;
              break;
            default:
              /* Normal packet */
              if (aPacketData[PACKET_NUMBER_INDEX] != packets_received)
              {
                Serial_PutByte(NAK);
              }
              else
              {
                if (packets_received == 0)
                {
                  /* File name packet */
                  if (aPacketData[PACKET_DATA_INDEX] != 0)
                  {
                    /* File name extraction */
                    i = 0;
                    file_ptr = aPacketData + PACKET_DATA_INDEX;
                    while ( (*file_ptr != 0) && (i < FILE_NAME_LENGTH))
                    {
                      aFileName[i++] = *file_ptr++;
                    }

                    /* File size extraction */
                    aFileName[i++] = '\0';
                    i = 0;
                    file_ptr ++;
                    while ( (*file_ptr != ' ') && (i < FILE_SIZE_LENGTH))
                    {
                      file_size[i++] = *file_ptr++;
                    }
                    file_size[i++] = '\0';
                    Str2Int(file_size, &filesize);

                    /* Test the size of the image to be sent */
                    /* Image size is greater than Flash size */
                    if (*p_size > (USER_FLASH_SIZE + 1))
                    {
                      /* End session */
                      tmp = CA;
                      HAL_UART_Transmit(&UartHandle, &tmp, 1, NAK_TIMEOUT);
                      HAL_UART_Transmit(&UartHandle, &tmp, 1, NAK_TIMEOUT);
                      result = COM_LIMIT;
                    }
                    /* erase user application area */
                    FLASH_If_Erase(APPLICATION_ADDRESS);
                    *p_size = filesize;

                    Serial_PutByte(ACK);
                    Serial_PutByte(CRC16);
                  }
                  /* File header packet is empty, end session */
                  else
                  {
                    Serial_PutByte(ACK);
                    file_done = 1;
                    session_done = 1;
                    break;
                  }
                }
                else /* Data packet */
                {
                  ramsource = (uint32_t) & aPacketData[PACKET_DATA_INDEX];

                  /* Write received data in Flash */
                  if (FLASH_If_Write(flashdestination, (uint32_t*) ramsource, packet_length/4) == FLASHIF_OK)                   
                  {
                    flashdestination += packet_length;
                    Serial_PutByte(ACK);
                  }
                  else /* An error occurred while writing to Flash memory */
                  {
                    /* End session */
                    Serial_PutByte(CA);
                    Serial_PutByte(CA);
                    result = COM_DATA;
                  }
                }
                packets_received ++;
                session_begin = 1;
              }
              break;
          }
          break;
        case HAL_BUSY: /* Abort actually */
          Serial_PutByte(CA);
          Serial_PutByte(CA);
          result = COM_ABORT;
          break;
        default:
          if (session_begin > 0)
          {
            errors ++;
          }
          if (errors > MAX_ERRORS)
          {
            /* Abort communication */
            Serial_PutByte(CA);
            Serial_PutByte(CA);
          }
          else
          {
            Serial_PutByte(CRC16); /* Ask for a packet */
          }
          break;
      }
    }
  }
  return result;
}
/**
  * @brief  Receive a file using the ymodem protocol.
  * @param  buf: Address of the first byte.
  * @retval The size of the file.
  */
int32_t Ymodem_Receive (uint8_t *buf)
{
    uint8_t packet_data[PACKET_1K_SIZE + PACKET_OVERHEAD], file_size[FILE_SIZE_LENGTH], *file_ptr, *buf_ptr;
    int32_t i, packet_length, session_done, file_done, packets_received, errors, session_begin, size = 0;
    uint32_t flashdestination, ramsource;

    /* Initialize flashdestination variable */
    flashdestination = APPLICATION_ADDRESS;

    for (session_done = 0, errors = 0, session_begin = 0; ;)
    {
        for (packets_received = 0, file_done = 0, buf_ptr = buf; ;)
        {
            switch (Receive_Packet(packet_data, &packet_length, NAK_TIMEOUT))
            {
            case 0:
                errors = 0;
                switch (packet_length)
                {
                /* Abort by sender */
                case - 1:
                    Send_Byte(ACK);
                    return 0;
                /* End of transmission */
                case 0:
                    Send_Byte(ACK);
                    file_done = 1;
                    break;
                /* Normal packet */
                default:
                    if ((packet_data[PACKET_SEQNO_INDEX] & 0xff) != (packets_received & 0xff))
                    {
                        Send_Byte(NAK);
                    }
                    else
                    {
                        if (packets_received == 0)
                        {
                            /* Filename packet */
                            if (packet_data[PACKET_HEADER] != 0)
                            {
                                /* Filename packet has valid data */
                                for (i = 0, file_ptr = packet_data + PACKET_HEADER; (*file_ptr != 0) && (i < FILE_NAME_LENGTH);)
                                {
                                    FileName[i++] = *file_ptr++;
                                }
                                FileName[i++] = '\0';
                                for (i = 0, file_ptr ++; (*file_ptr != ' ') && (i < FILE_SIZE_LENGTH);)
                                {
                                    file_size[i++] = *file_ptr++;
                                }
                                file_size[i++] = '\0';
                                Str2Int(file_size, &size);

                                /* Test the size of the image to be sent */
                                /* Image size is greater than Flash size */
                                if (size > (USER_FLASH_SIZE + 1))
                                {
                                    /* End session */
                                    Send_Byte(CA);
                                    Send_Byte(CA);
                                    return -1;
                                }
                                /* erase user application area */
                                FLASH_If_Erase(APPLICATION_ADDRESS);
                                Send_Byte(ACK);
                                Send_Byte(CRC16);
                            }
                            /* Filename packet is empty, end session */
                            else
                            {
                                Send_Byte(ACK);
                                file_done = 1;
                                session_done = 1;
                                break;
                            }
                        }
                        /* Data packet */
                        else
                        {
                            memcpy(buf_ptr, packet_data + PACKET_HEADER, packet_length);
                            ramsource = (uint32_t)buf;

                            /* Write received data in Flash */
                            if (FLASH_If_Write(&flashdestination, (uint32_t*) ramsource, (uint16_t) packet_length/4)  == 0)
                            {
                                Send_Byte(ACK);
                            }
                            else /* An error occurred while writing to Flash memory */
                            {
                                /* End session */
                                Send_Byte(CA);
                                Send_Byte(CA);
                                return -2;
                            }
                        }
                        packets_received ++;
                        session_begin = 1;
                    }
                }
                break;
            case 1:
                Send_Byte(CA);
                Send_Byte(CA);
                return -3;
            default:
                if (session_begin > 0)
                {
                    errors ++;
                }
                if (errors > MAX_ERRORS)
                {
                    Send_Byte(CA);
                    Send_Byte(CA);
                    return 0;
                }
                Send_Byte(CRC16);
                break;
            }
            if (file_done != 0)
            {
                break;
            }
        }
        if (session_done != 0)
        {
            break;
        }
    }
    return (int32_t)size;
}
Example #14
0
File: main.c Project: ButKamZ/MBLed
void firmware_erase_firmware_temp() {
    /* Enable flash writing */
    FLASH_If_Init();
    FLASH_If_Erase((uint32_t)FIRMWARE_TEMP_FIRST_PAGE_ADDRESS, (uint32_t)FIRMWARE_TEMP_LAST_PAGE_ADDRESS);
}
Example #15
0
File: main.c Project: ButKamZ/MBLed
/*
 *
 * Erase the new_fimware sector
 *
 */
void firmware_erase_new_firmware() {
    /* Enable flash writing */
    FLASH_If_Init();
    FLASH_If_Erase((uint32_t)NEW_FIRMWARE_FIRST_PAGE_ADDRESS, (uint32_t)NEW_FIRMWARE_LAST_PAGE_ADDRESS);
}