OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 3650|回复: 2

请教下,使用 tftp 升级固件,获取数据失败 ?

[复制链接]

260

主题

810

帖子

0

精华

金牌会员

Rank: 6Rank: 6

积分
1898
金钱
1898
注册时间
2012-10-28
在线时间
357 小时
发表于 2017-12-16 14:35:38 | 显示全部楼层 |阅读模式
5金钱
本帖最后由 hpdell 于 2017-12-16 14:43 编辑

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

tftp.png

有谁知道是怎么回事莫 ??  

使用 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\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[1]);
}

正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165537
金钱
165537
注册时间
2010-12-1
在线时间
2117 小时
发表于 2017-12-16 20:51:42 | 显示全部楼层
回复

使用道具 举报

260

主题

810

帖子

0

精华

金牌会员

Rank: 6Rank: 6

积分
1898
金钱
1898
注册时间
2012-10-28
在线时间
357 小时
 楼主| 发表于 2017-12-16 20:56:21 | 显示全部楼层

有没有关于这方面的历程或者文件介绍啊 ?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-6-13 21:07

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表