This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C129,usb_host_msc问题求助



用tm4c129的例程usb_host_msc例程在自己板子上实现读写U盘遇到错误,每次写数据的时候就跳入fault,跟踪调试也看不出结果。求有经验的人说一下,我的部分电路图如下。只用了usb0_dm,usb0_dp引脚,其他的未用。补充一句,之前在tm4c123上面也改过,是正常的。

 

 

 

 

 

初始化USB引脚代码:

 ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOL);   

ROM_GPIOPinTypeUSBAnalog(GPIO_PORTL_BASE, GPIO_PIN_6 | GPIO_PIN_7);

 

 

FIL fil;
FRESULT res; 
switch(g_eState)
{
  case STATE_DEVICE_ENUM:
  {
    res = f_open(&fil,"File.txt",FA_CREATE_ALWAYS|FA_WRITE);
    if(res!=FR_OK)
    {
    }
    res = f_write(&fil,temp_data,1,0);
    f_sync(&fil);
    res = f_close(&fil);
  }

case .....


执行代码,在 f_write(&fil,temp_data,1,0); 这一句跳入fault错误。如果注视掉这一句可以正常创建文件。调试跟踪发现在f_write函数里面在下面这一句死掉,求指导问题出在什么地方。

res = validate(fp);      /* Check validity */

 

  • 你好,

          楼主代码中对f_write()函数的使用可能有问题。最后一个参数楼主赋值为0,而在f_write()函数中下面的语句对该空指针做了赋值,

          *bw = 0; /* Clear write byte counter */

          所以只要给最后一个参数赋一个非空值应该就可以了,如

    unsigned int count;

    ......

     res = f_write(&fil,temp_data,3,&count);

    ......

  • 果然是这个问题,没注意,之前在123上是可以的,ti的技术支持果然细。另外用了几天129还是挺好用的,虽然片上flash速度低了点,但是勾上内联选项,减少了跳转,速度还是快。