FreeRTOS on HCS08

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

FreeRTOS on HCS08

44,285 Views
jeffw
Contributor I
I've ported FreeRTOS to HCS08, and the project targets the SARD and EVB boards. I'm working on making SMAC compatible with this project.

Steps

1. Download and install FreeRTOS 3.2.4: FreeRTOS
2. Download the attached zip file
3. Unpack it into a temporary directory.
4. Following the FreeRTOS directory structure, move the sub-folders into their correct places.
5. Open the RTOSDemo.mcp project in CW 3.1.
6. Deploy to a Freescale SARD or EVB.

FreeRTOS-3.2.4-HCS08_Files.zip
Message Edited by dkindler on 2009-08-20 02:33 PM
Labels (1)
0 Kudos
Reply
149 Replies

959 Views
Stipey75
Contributor I

Hi everybody,

 

i'm making my first steps withFreeRtos with Eclipse CW ( I'm new to thi IDE! :smileywink: ) and I'd like to port FreeRtos on HCS08QE64.

I know that it's not a simple question, but can anybody help me with a short list of the things i have to do with eclipse for the porting ( i'm using the black knght version found on this forum...)

 

Thanks a lot!!

0 Kudos
Reply

959 Views
BlackNight
NXP Employee
NXP Employee

Hello,

the easiest way is following:

- import all the Processor Expert components from the package you have mentioned (using menu Processor Expert > Import Package)

- restart eclipse in order to load all the newly imported components

- create a new project for QE64 and Processor Expert (menu Project > New bareboard project)

- From the component Library (menu Window > Show View > Processor Expert > Components Library) select the FreeRTOS component and add it to your project

- In the project panel, the new component will show up. All what you have to do now is to assign a timer for the RTOS ticks (e.g. for 10 ms), plus the SWI (software interrupt) vector (which will be somethign like Vswi for QE64)

- generate code (select the ProcessorExpert.pe file in the Project Panel) and select 'Generate Code'

- Build it

Of course you need to add your own custom code (creating tasks, starting scheduler, etc), see the QE128 port provided.

 

BK

0 Kudos
Reply

959 Views
Phaled
Contributor I

I need help for this party:

""******************************************************************************************

#ifdef BANKED_MODEL
        /*
         * Load the stack pointer for the task, then pull the critical nesting
         * count and PPAGE register from the stack.  The remains of the
         * context are restored by the RTI instruction.
         */
        #define portRESTORE_CONTEXT()    \
        {                                \
                extern volatile void * pxCurrentTCB;  \
                                                                           \
                __asm( "ldx pxCurrentTCB" );                               \
                __asm( "lds 0, x" );                                       \
                __asm( "pula" );                                           \
                __asm( "staa uxCriticalNesting" );                         \
                __asm( "pula" );                                           \
                __asm( "staa 0x30" ); /* 0x30 = PPAGE */                   \
        }

        /*
         * By the time this macro is called the processor has already stacked the
         * registers.  Simply stack the nesting count and PPAGE value, then save
         * the task stack pointer.
         */
        #define portSAVE_CONTEXT()   \
        {                            \
                extern volatile void * pxCurrentTCB;                     \
                                                                         \
                __asm( "ldaa 0x30" );  /* 0x30 = PPAGE */     \
                __asm( "psha" );                              \
                __asm( "ldaa uxCriticalNesting" );            \
                __asm( "psha" );                              \
                __asm( "ldx pxCurrentTCB" );                  \
                __asm( "sts 0, x" );                          \
        }
#else
        /*
         * These macros are as per the BANKED versions above, but without saving
         * and restoring the PPAGE register.
         */
        #define portRESTORE_CONTEXT() { \
                extern volatile void * pxCurrentTCB; \
                __asm( "LDHX pxCurrentTCB" ); \
                __asm( "LDHX 0, X" ); \
                __asm( "TXS" ); \
                __asm( "PULA" ); \
                __asm( "STA uxCriticalNesting" ) \
                __asm( "PULH" ) \
                __asm( "RTI" ); }

        #define portSAVE_CONTEXT() { \
                extern volatile void * pxCurrentTCB; \
                __asm( "LDA uxCriticalNesting" ); \
                __asm( "PSHA" ); \
                __asm( "TSX" ); \
                __asm( "STHX tempStackHolder1"); \
                __asm( "LDHX pxCurrentTCB"); \
                __asm( "LDA tempStackHolder1"); \
                __asm( "STA 0, X"); \
                __asm( "LDA tempStackHolder2"); \
                __asm( "STA 1, X"); }
#endif

**********************************************************************

What's modification can i do to use banked_model for qe128 because this part is for HC9S12

 

0 Kudos
Reply

959 Views
BlackNight
NXP Employee
NXP Employee

Hello,

finally I have found some cycles to port FreeRTOS as well to the banked memory model of the S08.

I had not much time to test it, but it works with a task in banked memory.

Attached is a project demonstrating this on the DEMOQE (S08QE128) board with a blinking LED.

As always: provided 'as is' and without warranty.

 

The attached Processor Expert component supports S08 and ColdFire.

It is still on FreeRTOS 6.0.5. Let's see if I find time to integrate the 7.0 FreeRTOS.

 

BK

0 Kudos
Reply

959 Views
wrljet
Contributor II

I'm using Codewarrior 6.2 (with Processor Expert 3.09).

 

The Fat_FileSystem bean automatically uses an instance of the TimeDate bean.

 

I evidently don't have a license for the TimeDate bean.

Is there some way to use the Fat_FileSystem w/o the TimeDate bean?

 

Thanks,

Bill

0 Kudos
Reply

959 Views
BlackNight
NXP Employee
NXP Employee

Hello,

yes, right now the component is using the TimeDate component.

The date/time is needed for storing the date/time to the directory entries (e.g. if a file/date is changed).

What you could do:

Use the read-only option of the component (to have the FatFS in read only mode, then you do not need a date/time, but then you cannot write/create files). Probably this is not an option for you.

 

I see if I find time in the next days to have a 'TimeDate-free' version of the component.

 

BK

0 Kudos
Reply

959 Views
BlackNight
NXP Employee
NXP Employee

Hello,

ok, I have made now the TimeDate component optional in the FatFS implementation. Now you can disable it in the properties.

This means that you have to provide your own implemenation of

DWORD get_fattime (void);

in your application.

Below is the implemenation in diskio.c as reference, using the TimeDate component.

 

Best regards,

BK

 

%if %UseTimeDate='no'
#if 0 /* usage of DateTime component disabled in properties */
%endif

#if !_FS_READONLY
DWORD get_fattime (void) {
  /* 31-25: Year(0-127 org.1980), 24-21: Month(1-12), 20-16: Day(1-31) */
  /* 15-11: Hour(0-23), 10-5: Minute(0-59), 4-0: Second(0-29 *2) */
  /* Pack date and time into a DWORD variable */
  TIMEREC time;
  DATEREC date;

%if defined(RTC)
  (void)%@RTC@'ModuleName'%.GetTime(&time);                      %>40 /* get time information */
  (void)%@RTC@'ModuleName'%.GetDate(&date);                      %>40 /* get time information */
%else
  /* Get time and date information and store it in 'time' and 'date'.
     If not using the DateTime component, you need to implement your own method here.
   */
%endif
  return ((DWORD)(date.Year - 1980) << 25)
       | ((DWORD)date.Month << 21)
       | ((DWORD)date.Day << 16)
       | ((DWORD)time.Hour << 11)
       | ((DWORD)time.Min << 5);
}
#endif /*!_FS_READONLY*/

0 Kudos
Reply

959 Views
wrljet
Contributor II

BlackNight wrote:

Hello,

ok, I have made now the TimeDate component optional in the FatFS implementation. Now you can disable it in the properties.

This means that you have to provide your own implemenation of

DWORD get_fattime (void);

in your application.

Below is the implemenation in diskio.c as reference, using the TimeDate component.

 

Best regards,

BK



Thank you very much!

 

/Bill

 

0 Kudos
Reply

959 Views
wrljet
Contributor II

I would like to enable the FatFs string functions.

These are controlled by the _USE_STRFUNC equate in ffconf.h.

I don't see any way to change this from the FAT_FileSystem component.

 

Is there any way to enable this?

 

Thanks,

Bill

 

0 Kudos
Reply

959 Views
BlackNight
NXP Employee
NXP Employee

Thanks for bringing this up: I missed to provide a property for this (as so far I was not using that functionality).

I have extended now the FAT_FileSystem component with an additional property to cover this.

 

You can download the component from

http://www.steinerberg.com/EmbeddedComponents

(I have started to create a central repository for all the components: much easier than posting in different threads).

 

BK

 

0 Kudos
Reply

959 Views
wrljet
Contributor II

BlackNight wrote in part:
You can download the component from

http://www.steinerberg.com/EmbeddedComponents

(I have started to create a central repository for all the components: much easier than posting in different threads).

 


That's a very nice website.  Thank you for sharing your work on the components.

 

Bill

 

0 Kudos
Reply

959 Views
wrljet
Contributor II

BlackNight wrote:

Thanks for bringing this up: I missed to provide a property for this (as so far I was not using that functionality).

I have extended now the FAT_FileSystem component with an additional property to cover this.

 



Thank you, BlackNight, for the string functions change.

 

I have another situation, somewhat more serious.

I am sharing the SPI hardware among half a dozen devices.

I find that the FatFS code only calls SD_Card.Deactivate in one place, as the result of a sync call,

and never calls LeaveSD.

 

This causes the FatFS to maintain "ownership" of the SPI, and we will have to save and restore the SS for it

every other place I want to use the SPI.

 

Is that fixable?

 

Thanks, Bill

 

0 Kudos
Reply

959 Views
BlackNight
NXP Employee
NXP Employee

Hi Bill,

indeed, this is a bug :smileysad:.

Good news: of course it is fixable.

The Problem is fixed in ff_req_grant() and ff_rel_grant(): below is the code which is generated with the fixed component.

The fixed component (V1.114) is available on http://www.steinerberg.com/EmbeddedComponents/FAT_FileSystem now as well.

 

BK

 

 

int ff_req_grant (_SYNC_t sobj)
{
  /* FreeRTOS */
  if (FRTOS1_xSemaphoreTake(sobj, _FS_TIMEOUT) == pdTRUE) {
    SD1_Activate(); /* select memory device */
    return TRUE; /* success */
  } else {
    /* failed to get the sync object? */
    return FALSE; /* failure */
  }
}

void ff_rel_grant (_SYNC_t sobj)
{
  SD1_Deactivate(); /* un-select memory device */
  /* FreeRTOS */
  (void)FRTOS1_xSemaphoreGive(sobj);
}

0 Kudos
Reply

959 Views
wrljet
Contributor II

I have pulled down the new FAT_FileSystem component, and figured out I need to

enable the Reentrant property to get the new code.

 

But now I'm confused.  I'm not using the RTOS component along with this.

 

From looking over the generated code, it appears I can use any type I want for

the Handle type because it's going to be ignored in the various ff_cre_syncobj(), etc

routines.   Is this correct?

 

(keeping in mind I have only one thread/task)

 

Thanks,

Bill

 

0 Kudos
Reply

959 Views
BlackNight
NXP Employee
NXP Employee

I admit that I have used FatFS only with an RTOS. Good that you are using it in another context, that helps to improve things :smileyhappy:. I had to make some changes to the FAT_FileSystem and SD_Card components in order to work with your scenario.

There are two things:

a) The 'Reentrant' property controls the FatFS _FS_REENTRANT flag.

This controls the reentrancy of FatFS (not directly the parallel access of the SPI bus!). Enabling _FS_REENTRANT, you have two choices: use the RTOS to create a semaphore (e.g. FreeRTOS): this ensures that multiple tasks can access FatFS. If you are not using an RTOS, then you can provide a name for the lock handle (e.g. HANDLE or int, as in the properties) and do whatever you want with it. But this means that you need to provide your own implementation of ff_cre_syncobj(), ff_del_syncobj(), ff_req_grant() and ff_rel_grant().

b) parallel access to the SPI bus: that must be done on a lower level: on the SD card SPI access level. Still you need to implement in your application a synchronization method to avoid parallel bus access. This can be done with the OnActivate() and OnDeactivate() events in the SD_Card

 

I think in your case the best thing is:

- in the FatFS component, have 'User Sync Functions' (see below) set to 'no' with RTOS set to 'disabled': this will just call the lower level Activate() and Deactivate() methods.

- in the SD_Card component enable the events OnActivate() and OnDeactivate(). Implement your own synchronization method in the event callback for these (events.c)

What happens: FatFS will use ff_cre_syncobj(), ff_del_syncobj(), ff_req_grant() and ff_rel_grant(), and they will call the SD card Activate() and Deactivate(). And your user code will make sure in the event callbacks that nobody is accessing the SPI bus in parallel.

 

- I have uploaded the new FatFS component to the website:

http://www.steinerberg.com/EmbeddedComponents/FAT_FileSystem/ (V1.115)

http://www.steinerberg.com/EmbeddedComponents/SD_Card (V1.149)

 

I hope that works for you?

Thanks!

BK

0 Kudos
Reply

959 Views
wrljet
Contributor II

I want to talk to a non-DOS partition I have created on an SD card.

I want to use this space as just a large Flash.

 

Once I know the LBA of the start of data for this partition, should it be possible to

read and write "sectors" on the SD card, using the disk_read() and disk_write()

routines in diskio.c?

 

I'd like to do this at the same time the FatFs system has a file open in the FAT partition

on the SD card.  Is there some way to do this without upsetting the state FatFs knows

to be current either on the SD itself, or in the FatFs and diskio modules?

 

Thoughts?

 

Bill

 

0 Kudos
Reply

959 Views
wrljet
Contributor II

wrljet wrote:

I want to talk to a non-DOS partition I have created on an SD card.

I want to use this space as just a large Flash.

 

Once I know the LBA of the start of data for this partition, should it be possible to

read and write "sectors" on the SD card, using the disk_read() and disk_write()

routines in diskio.c?

 

I'd like to do this at the same time the FatFs system has a file open in the FAT partition

on the SD card.  Is there some way to do this without upsetting the state FatFs knows

to be current either on the SD itself, or in the FatFs and diskio modules?

 

Thoughts?

 

Bill

 


FWIW, I did this and it works.  I created a non-DOS partition on the SD card with Linux.

I can read and write to it and not interfere with what the FatFS stuff is doing at the sam time.

 

Bill

 

0 Kudos
Reply

959 Views
Francois
Contributor I

Hello,

 

I'm new with FreeRTOS and I'm trying to run it on DZ32 (and perhaps after on QE8)

I use CW 5.9.0, I've upgraded to PE 3.09 and installed FreeRTOS component 7.0.2.

I'we build a simple basic project with 2 tasks but it crashes when using heap in

*pvPortMalloc (the software doesn't uses prvHeapInit.

 

My question is :

1) Do I have to declare somewhere location and size of the heap ?

I've never worked with heap If I look in map file, I only have xHeap for 1024 bytes located somewhere in RAM)

 

2) Does heap must be located just after the stack ?

 

Thank you for help

fran cois

0 Kudos
Reply

959 Views
BlackNight
NXP Employee
NXP Employee

Hello,

FreeRTOS is using the heap both for the stack and everything else the RTOS is using (queues, semaphore, etc).

 

Not sure what you mean with "it crashes": if you run out of heap, then you should get the 'out of memory' hook called.

If you are using the Processor Expert FreeRTOS component, then you can enable that event, and place a breakpont there (then you know who is causing this).

1 K of heap should not be a problem as long as your 2 task are not using too much stack space.

 

Question 1) The heap size (and heap method) is defined in the FreeRTOS Processor Expert component (see attached screenshot), and reflected inside the FreeRTOSConfig.h:

#define configTOTAL_HEAP_SIZE           ((size_t)(3000))

Question 2) As FreeRTOS is using the heap internally both for stack and everything else, the location of the heap does not matter.

 

Hope this helps,

BK

0 Kudos
Reply

959 Views
Francois
Contributor I

Thank you very much for your help.

 

Crashes means that I have ILLEGAL_BP (suspect access to non RAM area)

in *pvPortMalloc() but I suspect that it occurs because prvHeapInit( ) has not be invoked

(I don't know why ?)

In my example, heap size was fixed to 1024 bytes and in the map file 1274 bytes are used

and reserved. I can go up to 0x0600 bytes, but I have the same problem.

(on the DZ32, I've only 2048 bytes of RAM ....)

 

With best regards

fran cois

0 Kudos
Reply

959 Views
BlackNight
NXP Employee
NXP Employee

Hello,

prvHeapInit() is automatically called on the first call of malloc (if the heap has not been initialized):

(see code of pvPortMalloc()):

                if( xHeapHasBeenInitialised == pdFALSE )
                {
                        prvHeapInit();
                        xHeapHasBeenInitialised = pdTRUE;
                }

 

Which memory scheme are you using?

Scheme 2?

 

Best regards,

BK

prvHeapInit
0 Kudos
Reply