本帖最后由 hpdell 于 2017-12-16 14:43 编辑
请教下,使用tftP 升级固件,数据发送返回错误 ?
有谁知道是怎么回事莫 ??
使用 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[40],message[40], *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
");
__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
");
__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
"); // 问题就出在这里了 ?????????????????????
__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
");
__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...
");
__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[1]);
}
一周热门 更多>