The USB OTG module in Kinetis parts uses a Buffer Descriptor Table (BDT) in system memory to manage USB endpoint communications, the BDT is a a 512-byte buffer and there are 3 registers in USB module to contain the base address for it, and it must be 512-byte aligned otherwise there would be issue during transfer.
In USB stack ver 4.1.1, some Kinetis old parts like K60N512, K20D72M have the demo project basked on CodeWarrior ARM compiler, and in khci_kinetis.c, bdt is defined as following:
#define _BDT_RESERVED_SECTION_
#if(defined _BDT_RESERVED_SECTION_)
#ifdef __CWCC__
#pragma define_section usb_bdt ".usb_bdt" RW
__declspec(usb_bdt) uint_8_ptr bdt;
but since the base address is defined as below:
#define BDT_BASE | ((uint_32*)(bdt)) |
so the bdt definition is not correct , and we have to change it as below:
#define _BDT_RESERVED_SECTION_
#if(defined _BDT_RESERVED_SECTION_)
#ifdef __CWCC__
#pragma define_section usb_bdt ".usb_bdt" RW
__declspec(usb_bdt) uint_8 bdt[512];//uint_8_ptr bdt;
and the definition for usb_dbt section can be found in MK20X256_flash.lcf.
with above modification, we can make the demo of "msd_mfs_generic" work well as expected.
Please kindly refer to the following result got from TWR-K20D72M.
FAT demo
Waiting for USB mass storage to be attached...
Mass Storage Device Attached
******************************************************************************
* FATfs DEMO *
* Configuration: LNF Enabled, Code page =1258 *
******************************************************************************
******************************************************************************
* DRIVER OPERATION *
******************************************************************************
Initializing logical drive 0...
Initialization complete
-----------------------------------------------------------------------------
getting drive 0 attributes...............
Logical drive 0 attributes:
FAT type = FAT16
Bytes/Cluster = 2048
Number of FATs = 2
Root DIR entries = 512
Sectors/FAT = 250
Number of clusters = 63858
FAT start (lba) = 36
DIR start (lba,clustor) = 536
Data start (lba) = 568
...
127716 KB total disk space.
127624 KB available.
-----------------------------------------------------------------------------
******************************************************************************
* DRECTORY OPERATION *
******************************************************************************
Directory listing...
----A 2014/04/16 17:25 32253 tek00000.png
----A 2014/04/16 17:34 31451 tek00001.png
----A 2014/07/04 14:57 20549 tek00002.png
DR--- 2010/12/25 23:30 0 DIRECT~1
D---- 2010/01/01 00:00 0 DIRECT~2
3 File(s), 84253 bytes total
2 Dir(s)
-----------------------------------------------------------------------------
Directory listing...
----A 2014/04/16 17:25 32253 tek00000.png
----A 2014/04/16 17:34 31451 tek00001.png
----A 2014/07/04 14:57 20549 tek00002.png
DR--- 2010/12/25 23:30 0 DIRECT~1
D---- 2010/01/01 00:00 0 DIRECT~2
3 File(s), 84253 bytes total
2 Dir(s)
-----------------------------------------------------------------------------
CWD: 0:/
Directory listing...
D---- 2010/01/01 00:00 0 .
D---- 2010/01/01 00:00 0 ..
D---- 2010/01/01 00:00 0 sub1
0 File(s), 0 bytes total
3 Dir(s)
CWD: 0:/Directory_1
-----------------------------------------------------------------------------
DR--- 2010/12/25 23:30 0 Directory_1
DR--- 2010/12/25 23:30 0 Directory_1
-----------------------------------------------------------------------------
Rename <sub1> to <sub1_renamed> and move it to <Directory_2>
Directory listing...
D---- 2010/01/01 00:00 0 .
D---- 2010/01/01 00:00 0 ..
D---A 2010/01/01 00:00 0 SUB1_R~1
0 File(s), 0 bytes total
3 Dir(s)
-----------------------------------------------------------------------------
Delete Directory_1/sub1_renamed
Directory listing...
D---- 2010/01/01 00:00 0 .
D---- 2010/01/01 00:00 0 ..
0 File(s), 0 bytes total
2 Dir(s)
******************************************************************************
* FILE OPERATION *
******************************************************************************
File size = 0
File size = 52
File size = 103
File size = 152
File size = 199
-----------------------------------------------------------------------------
Line 1: Write data to file uses f_write function
Line 2: Write data to file uses f_printf function
Line 3: Write data to file uses f_puts function
Line 4: Write data to file uses f_putc functionûöF¬
â•:7Rz}™ yzjw8¸×áÀ—»ÃйòÍ
ä‹Hïk¨Wã½c'
²7këÞÑ%VrC×»Ô¼ÒSÈÑèR+NjD¡¾òû>ú3‰SËþo^ÎI Pë±ñ‰þ/Directory_1[1]
-----------------------------------------------------------------------------
----A 2010/01/01 00:00 199 New_File_1.dat
-R--A 2010/12/25 23:30 199 New_File_1.dat
----A 2010/12/25 23:30 199 New_File_1.dat
-----------------------------------------------------------------------------
Rename <New_File_1.dat> to <File_Renamed.txt>
Directory listing...
D---- 2010/01/01 00:00 0 .
D---- 2010/01/01 00:00 0 ..
----A 2010/12/25 23:30 199 FILE_R~1.TXT
1 File(s), 199 bytes total
2 Dir(s)
-----------------------------------------------------------------------------
Truncate file <File_Renamed.txt>
Current file pointer: 0
File pointer after seeking: 102
File size = 102
-----------------------------------------------------------------------------
Line 1: Write data to file uses f_write function
Line 2: Write data to file uses f_printf function
-----------------------------------------------------------------------------
Delete <File_Renamed.txt>
Directory listing...
D---- 2010/01/01 00:00 0 .
D---- 2010/01/01 00:00 0 ..
0 File(s), 0 bytes total
2 Dir(s)
*------------------------------ DEMO COMPLETED ------------------------ *
******************************************************************************
The same issue IAR tools, when user build the stack with IAR, bdt is defined as below:
Since there is no section defined as usb_bdt, it would be pointed to 0x00000000 where internal flash is, so would cause bus error issue. It is fixed after changing the definition as the following:
#elif defined __IAR_SYSTEMS_ICC__ | |
#pragma segment = "usb_bdt" |
#pragma data_alignment = 512
__no_init static uint_8 bdt[512] @ "usb_bdt";
Hope that helps,
B.R
Kan
Hi Kan_LI,
I'm asking if my issue bellow is not linked with this note above?
https://community.nxp.com/message/848331?commentID=848331#comment-848331
But I'm not able to know if I'm concerned by this note??...
I'm on the K70 120m, with KDS, and MQX 4.1.1
Thank