M68k port: tasks not running?

Hi all.

Continuing my Cisco router journey, Im working on a port for m68k. I have FreeRTOS running now, I can create tasks and start the scheduler, I see my tick interrupts firing, and I am calling into xTaskIncrementTick() from there.

But the tasks never seem to start after I start the scheduler. By this I mean that I have some code in each task that blips an IO line, but I never see these blips on my oscilloscope.

xTaskIncrementTick() always seems to return false as well.

Where could I start looking to figure out why the tasks are seemingly never started?

Code is here if anyone is able to help point me in the right direction: GitHub - tomstorey/FreeRTOS_m68k: Working on a port of FreeRTOS for m68k

Try to step through this function to see if the first task is starting correctly: FreeRTOS_m68k/portasm.S at master · tomstorey/FreeRTOS_m68k · GitHub

You can also step though the xTaskIncrementTick to see why it always returns false.


I don’t see the IO line being toggled, which should happen when the RTE instruction is executed because that should then start executing the tasks code and it’s the very first thing that should happen.

And I’m not getting any bus errors or otherwise odd behaviour or crashes that you might see if it was jumping off to some other random location.

Unfortunately I don’t really have a means of stepping through code right now as this is an entirely bare metal project, but I’m looking into options to be able to do this even if it means creating something myself. For now I’m getting away with toggling an IO line, but that will only get me so far.

Hi Tom - Hey the 68010 (and newer) interrupt stack frame is different from the original 68000 frame.

So just prior to putting the return address on the stack of a new task, I think you need to push a single 16-bit word, zero. See here:

That should help RTE do the right thing, and maybe your task code will actually run!

PS I can’t decide which is better, you trying to create a port for a CPU that predates FreeRTOS and many of its users, with no debugger, or the fact that the FreeRTOS team jumped in to help! Go Gaurav!

1 Like

oof! Thats a damn good catch! Completely overlooked the stack frame format…! :heart_eyes:

I do now see my tasks starting up, but after a couple of ticks Im getting bus errors.

Ive put some crude debugging capability into my serial bootloader to dump registers/stack frame/a bit of the stack on an exception, so this will help with debugging.

Ok. Port is now working. :slight_smile:

I had some issues with my context switching code which I think was leading to stack corruption. After adding some nesting control my tasks are running perfectly now.

edit: deleted my original repo and instead forked and added my code there: GitHub - tomstorey/FreeRTOS-Kernel: FreeRTOS kernel files only, submoduled into https://github.com/FreeRTOS/FreeRTOS and various other repos.

Jeff, I think I owe you a beer or two if we ever happen to meet up. :slight_smile:

I might have eventually got there and figured this out, but I think you saved me days and days and days of work.

Awesome you got it working. When I saw you were doing 68k I thought – he’s crazy. :grinning: And immediately I wanted to help! :crazy_face: I have a “seasoned” love of 68k/CPU32 stuff.

1 Like

I really do appreciate your help in pointing out that missing word, I still cant believe how much time and anguish that has saved!

It is a very nice architecture I must say!

Ive done a bit of work with Z80 as well (no, I wont try porting FreeRTOS to that, I promise), and for an 8 bit’er its a nice processor (I think so anyway), but the 68k really is very nice and Im quickly growing very fond of it, so I can understand why so many others love it too. Shame x86 won out in the end haha.

I have a few DIP64 68000’s in a tube packed away somewhere that Ive been wanting to do something with (kind of want to build a VME style system because the bus arbitration seems like an interesting challenge to do in some CPLDs), but this Cisco router just presented a nice opportunity to do something with a pre-built system, and its a good distraction from the goings on of the world at the moment.

Now I should formalise my documentation and notes of what Ive discovered of this router so far.

Is there any ports for 68376?
I would assume yes as its similar to 68332 (CPU32).
Where to find & what tool chains?

I have used my port on both 680x0 as well as CPU32 (68360) CPUs just fine.

You can find it here: GitHub - tomstorey/FreeRTOS-Kernel at new_task_switch

Just be sure to be on the new_task_switch branch as this contains a significatnt fix, but I havent yet merged it into master (Ive been debating whether I should maintain a full FreeRTOS fork, or only the port itself - Im leaning towards the later).

Toolchain wise, I have also been developing a cross compiler toolchain which I have also used successfully on 680x0 and CPU32 CPUs: GitHub - tomstorey/m68k_bare_metal: This repository contains my efforts to create an "idiot proof bare metal m68k cross compiler toolchain of sorts."

It uses GCC and I have tested it on a couple of different Linux distros and macOS. I believe it also works on Windows using WSL.

Feel free to PM me if you need assistance with either, I’ll try to help.

Thank you for your efforts. You may want to contribute your port here: GitHub - FreeRTOS/FreeRTOS-Kernel-Community-Supported-Ports


1 Like