FRDM-K20_MSD_HOST mcuOnEclipse with KDS and IAR: how to configure, where is task?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

FRDM-K20_MSD_HOST mcuOnEclipse with KDS and IAR: how to configure, where is task?

918 Views
Cdn_aye
Senior Contributor I

Hi

I used PE to change processors to the MK20DX256ZVLL10 in the Host File System, FRDM-K20_MSD_HOST from the mcuOnEclipse site and then followed Erich's tutorial on using IAR to load and debug the project and it worked correctly. I had to use my original lcf file and disable PE generating a new Processor_Expert.lcf. Now I can use both the Segger and IAR I-Jet probes.

That is the background, here is the question I hope someone can assist me with.

1)There are defines in the FRTOS1.h file relating to which type of processor is being used. Is this variable being set in a header file, or is there code to read a processor register and automatically set the processor type? We use the M4 but the original project I think was an M0. This will effect the NVIC and other register offsets. I can't find where to set this correctly. Where do I set this variable?

2) In FreeRTOS I would expect a task to be started but I can't hit the shell task breakpoint. Is there a define to control what task starts?

3) Where to I put a breakpoint to see if the file system is working? I don't seem to get into the shell. I have to use the semi-hosting mode and terminal IO window because we have a custom designed board and no UART output. But I don't see any output. This could be an IAR setup error so I will look that up, but where would be a good point to check that the USB is attached and that the MFS is mounted?

4) I am not sure that we are using the correct cpu in some of the defines as explained above, I do see the leds blink but that is in the startup. But no terminal IO appears and I can't see where the task execution goes after the startup is finished. Normally there would be a task scheduler, again I don't know if this is a define issue or the code is dying somewhere. Is there any defines or documentation on how to setup the program to test the file functions? I read through the documentation folder but can# see only device specific information.

Thanks


Robert

/////////////////////////////////////////////

Are there any other

/* macro to identify CPU: 0 for M0+ and 4 for M4 */
#if configCPU_FAMILY_IS_ARM_M0(configCPU_FAMILY)
#define FREERTOS_CPU_CORTEX_M 0 /* Cortex M0+ core */
#elif configCPU_FAMILY_IS_ARM_M4(configCPU_FAMILY)
#define FREERTOS_CPU_CORTEX_M 4 /* Cortex M4 core */
#elif configCPU_FAMILY_IS_ARM_M7(configCPU_FAMILY)
#define FREERTOS_CPU_CORTEX_M 7 /* Cortex M7 core */
#endif

5 Replies

553 Views
BlackNight
NXP Employee
NXP Employee

Hi Robert,

1) there is a FRTOS1config.h header file which contains extra configuration items to configure the RTOS beyond what is in the standard FreeRTOSConfig.h, things like for extra architectures (FreeRTOSConfig.h only covers a single architecture) or compilers. For IAR and the K20 you should have the following set FRTOS1config.h:

#define configCOMPILER                            configCOMPILER_ARM_IAR

#define configCPU_FAMILY                          configCPU_FAMILY_ARM_M4

2) FreeRTOS starts the highest priority task first. So set a breakpoint in you highest priority task. Alternatively you could step through the vTaskStartScheduler() code until it does the context switch.

3) I would set a breakpoint in the USB interrupt service routine. This one should fire if you have USB communication.

4) see 1) for the defines. I recommend that you do some LED blinking/etc before starting the scheduler so you know things are working. The other point is that the interrupts only get enabled with starting the scheduler, so typically you cannot use any peripherals with interrupts before that point. Have you enabled the stack overflow hook? it could be that your application is stuck there?

I hope this helps,

Erich

553 Views
Cdn_aye
Senior Contributor I

Hi Erich

I added the two defines you mentioned, but I do not hit the USB breakpoints.

I also added 

#define PEX_RTOS_START 1

I could not find where it was defined, so I defined it as a test, I am not sure this is necessary as per my comments below.

I think the problem is I do not see a call to

void APP_Run(void) {
HOST_Init();
SHELL_Init();
FRTOS1_vTaskStartScheduler();
}

Without this I don't think anything will start. I have looked through the macros and C files but do not see where this is ever called. I thought I saw IAR say something about a start function that was removed because it was not needed, but that start was just a copy down of ROM to RAM for variables etc. And I think that IAR does that in their start.s. 

Yes, I did check the LEDs and they are working. The last thing I see before the darkness falls is 

  #ifdef PEX_RTOS_START
PEX_RTOS_START(); /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
endif‌

which runs the scheduler, hence why I added the define PEX_RTOS_START

But I think this subverts my purpose because in APP_Run the scheduler is also called, but first HOST_Init(), then SHELL_Init() which seems critical to me.

Normally I would expect to see a task started and then control passed to the RTOS so I don't understand APP_Run() since it exits or where it should be called. How is the Shell command retained if it exits?

Thanks for the help again.

Robert

0 Kudos

553 Views
Cdn_aye
Senior Contributor I

Hi Erich

I removed the define

#define PEX_RTOS_START 1

and added

APP_Run(); // **rwl, added to run cli, and mfs init

to main.c after the PE_low_level_init();

I am still concerned about the RTOS integration (I don't see any tasks to run other than the OS scheduler) but I can run the USB init now.

I had to patch the component CLS1 in order to get the menu to appear. I put in a bypass to use the semihosted output/input. But it works as far as outputting and input of simple commands. I just don't know what the commands should be.

1) Is there a way in your system to output to the debugger or any other Terminal I/O if we don't have a dedicated uart connection? As soon as the code is regenerated, the changes will be lost/have to be restored. I am also not sure that some key functionality has been bypassed by my changes as well.

2) I don't know what to put into the parser to get the system to check execute commands to validate the file system. For example copy a file or create a directory. Are there a list of inputs I can try?

I think the system is almost there but I can't really test it as yet.

Thanks for the help.

Robert

0 Kudos

553 Views
BlackNight
NXP Employee
NXP Employee

Hi Robert,

1) There is the CLS1_SetStdio() which you can use to configure any kind of input/output (standard I/O) channel. You can use it even to read/write things to an SD card or to send things over a wireless communication channel if you have these available. Removing PEX_RTOS_START should not be necessary.

2) instead of using the parser system (which is at a very high level), I recommend that you open a file say from a task to check the functionality, or list a directory. You certainly can use the shell to do this too.

Erich

0 Kudos

553 Views
Cdn_aye
Senior Contributor I

Hi Erich

I bypassed the CLSI and used the following:

In Host_Init() I tried both

#define ONLY_HOST 1 & 0

If defined as 1, I see the Blue LED turn on which I think is idle, but I never see it attach or be interfaced, and it is in an infinite loop, which I understand would not be in final code. But I never see it function normally. There are no events enabled in any of the FsMSD1, USB1, FAT1 components, so that would explain none of the events registering. I did not change any of the component properties apart from pin changes for the k20dx256 processor. But I can see that the USB is not mounted. The system fails when it tries to mount the volume.

When defined as 0, HOST_Init() runs without detecting any errors and creates a Task  HostTask, then exits with a success status (it doesn't get trapped in the for(;;;), however I do not see any of the normal USB fcns like Attach, happen. Below is the code sequence I tried. I was not sure if I needed the HOST_Init, because I thought I saw if the USB was not mounted then the FsMSDI would mount the USB drive. The code is hanging in ff.c in FAT1_mount, it tries to read sector 0, but by this point it is all wrong because the volume is not mounted. It dies in check_fs when it tries to load the boot record.

pastedImage_109.png

I attached the USB0.c file that shows the PE settings. PE really is a remarkable system in how it documents everything so clearly and regenerates the settings with accurate comments each time a component changes. Much better than extracting programming comments from a header file that are usually inaccurate and not well maintained.

Thanks again for the advice and help.

Robert

/* Write your code here */
/* For example: for(;;) { } */

// APP_Run(); // **rwl, added to run cli, and mfs init
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
HOST_Init();
if (FAT1_Init()!=ERR_OK) {
printf("Failed FatFS initialization!\r\n");
return;
}

if (FAT1_mount(&fileSystemObject, (const TCHAR*)"0", 1) != FR_OK) { /* mount file system */
printf((unsigned char*)"Failed FatFS initialization!\r\n");
return;
}
/* write file */
printf((const unsigned char*)"Creating test.txt...\r\n");
if (FAT1_open(&fp, "./test.txt", FA_CREATE_ALWAYS|FA_WRITE)!=FR_OK) {
printf((const unsigned char*)"*** Failed creating file!\r\n");
return ERR_FAILED;
}
/* write text */
if (FAT1_write(&fp, "Hello world ", sizeof("Hello world ")-1, &bw)!=FR_OK) {
printf((const unsigned char*)"*** Failed writing string!\r\n");
(void)FAT1_close(&fp);
return ERR_FAILED;
}
FRTOS1_vTaskStartScheduler();
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

0 Kudos