Hi,
I am using the dev_msd_cdc_bm_twrk65f180m app as a starting example with the RAM Disk configuration as storage for the MSD.
The example is using the internal RAM as storage and want to modify the example to use the external ram of my development board.
I have the SDRAM driver working and can read and write to the external RAM in my main routine.
I have modified the disk_struct_t to accept a pointer to my external RAM instead of fix address in internal RAM.
typedef struct _disk_variable_struct
{
msd_handle_t app_handle;
uint32_t start_app;
uint16_t speed;
#if RAM_DISK_APP
/* disk space reserved */
//uint8_t storage_disk[DISK_SIZE];
uint8_t * storage_disk;
#endif
uint8_t disk_lock;
} disk_struct_t;
I have modified my scatter file to create a section in external RAM for my new bigger size array as follow:
__attribute__ ((section(".ext_ram"))) uint8_t storage_disk2[DISK_SIZE];
Then assign the array to pointer
...
msc_disk_init(&g_composite_device.msc_disk);
g_composite_device.msc_disk.storage_disk = storage_disk2;
...
By doing these simple changes I cant get the drive (MSD) to work (Doesnt show as drive). I would assume that it doesn't matter where the data goes unless there is something wrong when accessing the SDRAM controller inside the USB MSD callback function "Disk_USB_App_Class_Callback".
I have tried a several thing and can't get it to work, any help would be really appreciated.
Regards.
Hello,
Are you testing on Full Speed mode? I was able to create a basic example for TWR-K65F180M and dev_msd_disk_bm_twrk65f180m example (KSDK 1.3) and it worked well, this is what I did:
In disk.h, I modify TOTAL_LOGICAL_ADDRESS_BLOCKS_NORMAL to 1024 in order to use a 512kB disk size, also, storage_disk pointer was modified as you did:
#if RAM_DISK_USES_SDRAM
#define TOTAL_LOGICAL_ADDRESS_BLOCKS_NORMAL (1024)
#else
#define TOTAL_LOGICAL_ADDRESS_BLOCKS_NORMAL (48)
#endif
#if RAM_DISK_USES_SDRAM
uint8_t *storage_disk;
#else
uint8_t storage_disk[DISK_SIZE_NORMAL];
#endif
In hardware_init.c file, I added SDRAM initialization (taken from SDRAM example at <KSDK_1_3_PATH>\examples\twrk65f180m\driver_examples\sdramc):
#if RAM_DISK_USES_SDRAM
FB_Type* fbbase = g_fbBase[0];
#endif
#if RAM_DISK_USES_SDRAM
/* Change the clock DIV3*/
CLOCK_SYS_SetOutDiv3(2);
CLOCK_HAL_SetClkOutSel(SIM, kClockClkoutSelFlexbusClk);
/* Sets the Flexbus security level*/
SIM_HAL_SetFlexbusSecurityLevelMode(SIM,kSimFbslLevel3);
/* Enable the FB_BE_xx_yy signal in Flexbus */
CLOCK_SYS_EnableFlexbusClock(0);
FLEXBUS_HAL_SetMultiplexControlGroup2(fbbase,kFlexbusMultiplexGroup2_FB_BE_31_24);
FLEXBUS_HAL_SetMultiplexControlGroup3(fbbase,kFlexbusMultiplexGroup3_FB_BE_23_16);
FLEXBUS_HAL_SetMultiplexControlGroup4(fbbase,kFlexbusMultiplexGroup4_FB_BE_15_8);
FLEXBUS_HAL_SetMultiplexControlGroup5(fbbase,kFlexbusMultiplexGroup5_FB_BE_7_0);
/* Init sdram pins*/
configure_sdram_pins(0);
/* Init Sdram Clock*/
CLOCK_SYS_EnableSdramcClock(0);
#endif
(Be sure to include proper header: #include "fsl_flexbus_driver.h" and #include "fsl_flexbus_hal.h") And finally, SDRAM_Init is called (also, be sure to add fsl_sdram_Driver.c and fsl_sdram_driver.h from SDRAM example) in APP_Init function:
void APP_init(void)
{
#if RAM_DISK_USES_SDRAM
SDRAM_Init();
#endif
USB_PRINTF("Enter Testapp_init\n");
And storage disk is pointing to SDRAM start address:
#if RAM_DISK_USES_SDRAM
g_disk.storage_disk = (uint8_t *)SDRAM_START_ADDRESS;
#endif
USB_Class_MSC_Init(CONTROLLER_ID, &g_msd_config, &g_disk.app_handle);
After applying these changes, I was able to use SDRAM memory for my storage disk successfully.
Are you able to test this basic example?
Regards,
Isaac
Hi Isaac,
Thank you for the answer.
I have double checked everything mentioned below in my code and everything should be fine.
I am using the composite device example as a starting point.
I tested the SDRAM with the test code in the SDRAM example and no error is reported.
When I declare an array in internal ram like this:
uint8_t storage_disk2[DISK_SIZE];
And assign it later:
g_composite_device.msc_disk.storage_disk = storage_disk2;
It works, but as soon as I change to external RAM (only change):
g_composite_device.msc_disk.storage_disk = (uint8_t *)SDRAM_START_ADDRESS;
No MSD is detected by computer.
Could you send me your working example?
Regards,
Hello JS,
Please take in mind that i did the test on FS instead of HS (I am getting some errors when trying to access to SDRAM and USB is unable to send requested data in High Speed). Attach you can find all files that should replace dev_msd_disk_bm_twrk65f180m example's ones (<KSDK_1_3_PATH>\examples\twrk65f180m\demo_apps\usb\device\msd\bm\kds)
Hope this helps,
Regards,
Isaac
Thanks for the fast answer.
Is changing the usb only done in the disk init function? or I have to change it somewhere else.
void msc_disk_init(void *param)
{
g_msc_disk_ptr = (disk_struct_t*) param;
g_msc_disk_ptr->speed = USB_SPEED_FULL;
//g_msc_disk_ptr->speed = USB_SPEED_HIGH;
////g_msc_disk_ptr->speed = USB_SPEED_LOW;
}
There was not attachments to your mail.
Regards,
JS
Hello Js,
I uploaded a .zip file where all source and header files are shown. The speed for USB is changed here:
#ifndef HIGH_SPEED
#define HIGH_SPEED (0)
#endif
Regards,
Isaac