hpdell 发表于 2017-12-16 14:36:43

请教下,使用tftP 升级固件,数据发送返回错误 ?

本帖最后由 hpdell 于 2017-12-16 14:42 编辑

请教下,使用tftP 升级固件,数据发送返回错误 ?
tftp 使用的 是 tftpd32.452 这个版本的


有谁知道是怎么回事莫 ??
使用 http 更新固件,完全正常
static void IAP_tftp_recv_callback(void *arg, struct udp_pcb *upcb, struct pbuf *pkt_buf,                        const ip_addr_t *addr, u16_t port){tftp_opcode op;struct udp_pcb *upcb_tftp_data;err_t err;
uint32_t i;char filename,message, *ptr;
/* create new UDP PCB structure */upcb_tftp_data = udp_new();if (!upcb_tftp_data){    /* Error creating PCB. Out of Memory*/
    printf("Can not create pcb 1\r\n");    __LTDC_drv->LTDC_DispStringAt(12, 180,                                   LCD_COLOR_RED,                                   LCD_COLOR_WHITE,                                   &FontAscii8x16,                           (const uint8_t *)"Can not create pcb 1");    return;}
/* bind to port 0 to receive next available free port *//* NOTE:This is how TFTP works.There is a UDP PCB for the standard port* 69 which al transactions begin communication on, however, _all_ subsequent* transactions for a given "stream" occur on another port*/err = udp_bind(upcb_tftp_data, IP_ADDR_ANY, 0);if (err != ERR_OK){    /* Unable to bind to port */
    printf("Can not create pcb 2\r\n");    __LTDC_drv->LTDC_DispStringAt(12, 200,                                   LCD_COLOR_RED,                                   LCD_COLOR_WHITE,                                   &FontAscii8x16,                           (const uint8_t *)"Can not create pcb 2");    return;}
op = IAP_tftp_decode_op(pkt_buf->payload);if (op != TFTP_WRQ)   // op 实际返回的值为 1,而这个 TFTP_WRQ 定义的为2 ,{    /* remove PCB */
    printf("Bad TFTP opcode \r\n");                      // 问题就出在这里了 ?????????????????????    __LTDC_drv->LTDC_DispStringAt(12, 200,                                   LCD_COLOR_RED,                                   LCD_COLOR_WHITE,                                   &FontAscii8x16,                           (const uint8_t *)"Bad TFTP opcode");    udp_remove(upcb_tftp_data);}else{

    ptr = pkt_buf->payload;    ptr = ptr +2;    // extract file name info     i= 0;    while (*(ptr+i)!=0x0)    {      i++;    }    strncpy(filename, ptr, i+1);
    printf("IAP using TFTP \r\n");
    __LTDC_drv->LTDC_DispStringAt(12, 220,                                   LCD_COLOR_RED,                                   LCD_COLOR_WHITE,                                   &FontAscii8x16,                           (const uint8_t *)"IAP using TFTP");
    sprintf(message, "File: %s",filename);
    printf("State: Erasing...\r\n");    __LTDC_drv->LTDC_DispStringAt(12, 240,                                   LCD_COLOR_RED,                                   LCD_COLOR_WHITE,                                   &FontAscii8x16,                           (const uint8_t *)message);   
    __LTDC_drv->LTDC_DispStringAt(12, 260,                                   LCD_COLOR_RED,                                   LCD_COLOR_WHITE,                                   &FontAscii8x16,                           (const uint8_t *)"State: Erasing...");   

    // Start the TFTP write mode    IAP_tftp_process_write(upcb_tftp_data, addr, port);}pbuf_free(pkt_buf);}

/*** @brief Returns the TFTP opcode * @param buf: pointer on the TFTP packet * @retval None*/static tftp_opcode IAP_tftp_decode_op(char *buf){return (tftp_opcode)(buf);}

feixiang20 发表于 2018-5-19 02:10:10

查看软件是否被正确解压,升级包中的TFTP升级软件是否已经开启运行,升级页面的文件名是否和解压后文件夹中的文件名相同
页: [1]
查看完整版本: 请教下,使用tftP 升级固件,数据发送返回错误 ?