How to program e.g. a Grand Central with FreeRTOS or even bare metal?

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Post Reply
User avatar
hakane
 
Posts: 2
Joined: Thu Jul 04, 2024 1:05 pm

How to program e.g. a Grand Central with FreeRTOS or even bare metal?

Post by hakane »

Hello!

This is my first post, I apologize in advance if this is either described in loads of places or just simply a stupid question, but as I couldn't find any info I thought I'd give this forum a try.

An attempt to summarize

Is it possible to program e.g. a Grand Central in C, on an RTOS like FreeRTOS (or even bare metal) – and if that experiment fails, to be able to revert it to CircuitPython?

If so, are there any good guides on how to do that?


For those who like more details

I am trying to create a fairly large number of square waves, to be used in an old organ (that's why I bought the Grand Central, actually, because of the many GPIO pins). Initially I tried a naive approach by just looping: checking the time at the start of each loop and then toggling the pin depending on how long time that had passed since I last toggled it. This kinda worked, but with some weird sound artifact; I didn't investigate this (just guessed that it might have to do with the timing not being precise enough), but instead I found the module pwmio and figured I'd struck gold. It seems to do exactly what I want, but I can only start it on 12 pins. I have searched for info, apparently that's something that happens under the hood on that chip (at least I think it was because of the chip).

So, at this point in my life, I'm happy that I found a solution, but frustrated that I will have to buy an additional four boards to get the organ like I want it – especially since I suspect that if I'd done this in C, I could've gotten far more tones out of the chip.

Now, this is me guessing! I don't know that for sure. But I am a software developer, and even though I haven't dug into the pwmio code (or the SAMD51 data sheet for that matter!) enough to understand what the problem is, I think it's not a too wild guess that on such a powerful chip, with nothing else to do but toggle a few pins high/low on fairly low frequencies, that basic C programming might provide a better result (not "better" as in better square waves, but as in more than only twelve) – or in other words, that the marvellous abstraction layer that CircuitPython provides comes with some computational and/or resource related cost.

The problem is that even though I am a developer, and even though I've worked with embedded the last 15 years or so, I am also a bit worn out at the moment, and repairing this old home organ is something I do for fun – that's precisely why I went with CircuitPython, actually, because I like Python and wanted to get it to work quickly. One could argue that in that case I should just buy four more boards and move on, but as I said, it's kinda frustrating since I have a feeling I could get more out of this with proper C.

So, is there an easy to understand guide that explains how to set the board up for FreeRTOS development, and then back to CircuitPython?


Best regards,
Håkan

User avatar
dastels
 
Posts: 16382
Joined: Tue Oct 20, 2015 3:22 pm

Re: How to program e.g. a Grand Central with FreeRTOS or even bare metal?

Post by dastels »

To switch back to using CircuitPython, you just reinstall the CircuitPython UF2 firmware file. See https://learn.adafruit.com/welcome-to-c ... cuitpython.

FreeRTOS I don't know, but programming in C++ using Arduino you are programming on the bare metal. There's some libraries and enough framework to get the board configured & running, as well as call setup() and loop() appropriately. Start reading at https://learn.adafruit.com/adafruit-grand-central/setup.

Dave

User avatar
hakane
 
Posts: 2
Joined: Thu Jul 04, 2024 1:05 pm

Re: How to program e.g. a Grand Central with FreeRTOS or even bare metal?

Post by hakane »

Thank you! I'll give Arduino a try!

Post Reply
Please be positive and constructive with your questions and comments.

Return to “Metro, Metro Express, and Grand Central Boards”