Love UECIDE? Why not consider supporting the development?

User registrations are now disabled on this site.

We have a new forum system

>> Click here to try it out. <<

Raspberry Pi Core

Raspberry Pi Core

Postby matt » Thu Nov 28, 2013 11:43 am

This week I have mostly been crafting my own UECIDE core for programming the Raspberry Pi directly on the Raspberry Pi.

I started with the arduPi library from Cooking Hacks, but TBH it's a nasty bit of code. Yes, it works, but stylistically it's horrendous. It's full of messy messy pointer arithmetic to get at all the registers, and it's just completely uninteligable.

So I have been writing my own code from scratch, only using their pointer code for pointers (har har).

It's much much cleaner, and I am using proper structs and unions for accessing the memory mapped register blocks. Eveything in it is OO driven - even the underlying GPIO driver is a C++ class. Much nicer :)

So far I have basic GPIO (digitalRead / digitalWrite / pinMode) working, and and working SPI library. Later on today I will be adding analogWrite for the hardware PWM port, and maybe even with software PWM for the non-hardware ports, and I need to add things like pulseIn(), shiftIn() / shiftOut(), etc.

For tone() I think I'm going to just have to use the proper audio output :D

But it works, so far. Compiling is done with the native GCC compiler already installed in raspbian, and when you "upload" the sketch to the board it executes it in a UXTerm with sudo (sudo is needed to access the hardware registers).

There's a version in the plugins at the moment, but it was a first attempt using arduPi's code, so ignore it. I'll push a proper preview version out later on.
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".
matt
Site Admin
 
Posts: 1317
Joined: Sun Jul 07, 2013 11:37 am
I use UECIDE on: Linux
 

Re: Raspberry Pi Core

Postby matt » Sun Dec 01, 2013 10:55 pm

After fighting for a day with Broadcom's so-called PWM module I have decided that it is a waste of silicon.

The problems:

There is no documentation

Yes, the PWM module itself is documented in the main reference documentation that documents all the peripherals and their registers. However the clock module isn't documented ANYWHERE, and the clock module is the main driving source for the PWM module. If you can't configure the clock module you can't use the PWM. There is one, yes ONE, piece of example source code for using the PWM to drive a servo, and it is very cryptically written and filled with "magic numbers" which no one knows what they do. There's also a couple of rather disturbing comments in the source, which brings me on to my next point:

It's unstable

It's about as reliable as the Eiffel Tower balancing on its tip with a morbidly obese Frenchman sat one one of the legs. One of the comments in the source code says:

// stop clock and waiting for busy flag doesn't work, so kill clock

That's encouraging... and it gets better:

// needs some time until the PWM module gets disabled, without the delay the PWM module crashs
usleep(10);

It crashes when you try to disable it unless you put in a delay. Great. That's just wonderful. Fills me with great desire to get it going... honest.

So I have tried and failed for a whole day to get it working as just normal basic PWM, and being really frustrated as every time I tried to do anything it crashed the PWM module and I had to reboot.

So I have given up.

Not on the whole core, but on the pitiful PWM facilities in this awful Broadcom chip. Instead I have implemented a purely software PWM system. And it's much better.

It gives reasonable PWM on every single GPIO pin.

It runs at about 350Hz, though it can go higher (350Hz is a value that gives nice smooth results).

It has low overhead, because it spends most of its time sleeping waiting for the next duty cycle period to elapse.

It runs in its own thread. Yes, the core is now multi-threaded. I have created a nice simple Thread library that you can also use to run multiple loop() functions in parallel.

Code: Select all
Thread t;

void setup() {
  t.execute(loop2);
  Console.begin();
}

void loop() {
  Console.println("Thread 1");
  delay(500);
}

void loop2() {
  Console.println("Thread 2");
  delay(1000);
}

As simple as that!

I'm just going to push out the latest version of this core for you to play with (note - it needs the compiler updating too, for the threads).
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".
matt
Site Admin
 
Posts: 1317
Joined: Sun Jul 07, 2013 11:37 am
I use UECIDE on: Linux
 
 

Return to Creating a Core

Who is online

Users browsing this forum: No registered users and 1 guest

cron