Shop OBEX P1 Docs P2 Docs Learn Events
C to assembly that runs directly on a COG — Parallax Forums

C to assembly that runs directly on a COG

I am at the cusp of starting in on another project at work and would like to use the Propeller I chip as the microcontroller in the device. In my mind, it makes perfect sense to use it since it is extremely flexible and is much more capable than the ATMEGA/ATXMEGAs that we have been using previously. It is also really fast to program for since I don't have to go poking through datasheets to see if peripherals have overlapping pins or to figure out how to configure a peripheral.

My past experience is that the Propeller was hard to sell to an engineering team because it doesn't operate the same as the MCUs that people are used to. (It doesn't have peripherals/interrupts) Several months ago I evaluated a couple of compilers for the Propeller to see how they have changed since the last time I evaluated them. I was pleased to see that they have come a long way since I last did that about a decade ago. One problem that I saw though is that I am still stuck writing my peripherals in PASM. That is fine for me since I have experience with assembly language but the average programmer would rather eat tacks I think. The tests that I did seemed to indicate that the compilers were generating code that had a small kernel in the COG which loaded an instruction from the HUB and then executed it. If I could compile things from C/C++ to run directly in a COG then I think that things would be a lot less scary for the other programmers at work and would be efficient enough that peripherals could be written in those languages.

The two compilers that I evaluated were Flex GUI and Simple IDE. Is it possible in either of those to compile to run directly in a COG? I couldn't figure out how to do it.

Comments

  • RossHRossH Posts: 5,336

    It's going back a few years now, but I seem to remember that one of the C compilers could indeed generate cog code for the P1. Perhaps it was GCC?

  • PropGCC has an option to specify the COG memory model. I thinks the option is -mcog, but check the documentation if that doesn't work.

  • ersmithersmith Posts: 5,900
    edited 2021-11-27 14:48

    Both PropGCC (the compiler for SimpleIDE) and FlexSpin (the compiler for FlexProp) are able to compile functions to run in COG memory. Unfortunately, I don't think the capability is well exposed in the GUIs. Definitely it isn't for FlexProp (you pretty much have to edit the command line to add --code=cog, and if you want to build multiple different C files to run in different COGs you'll have to do this in separate steps with custom command lines).

    I'm not as familiar with SimpleIDE but I do seem to recall that there was a .cogc extension used for C code designed to run in COGs. There's a bit of discussion about .cogc at https://github.com/parallaxinc/propgcc-docs/blob/master/doc/InDepth.md .

    It's also worth pointing out that both FlexSpin and PropGCC are able to cache small bits of code into COG memory automatically (this is called FCACHE in the documentation) so you may not actually need to compile your code to "native" COG code, the default large memory model (LMM) plus cache may be fast enough for your needs.

  • SimpleIDE has a "Propeller GCC Demos" directory that contains two programs that use a .cogc file to provide driver code. The C-VGA directory has a file named vga.cogc that provides a VGA driver written in C that runs in a cog. The toggle directory contains a sub-directory named cog_c_toggle. It has a small cogc driver that toggles multiple pins.

  • RossHRossH Posts: 5,336
    edited 2021-11-28 00:46

    @ersmith said:
    It's also worth pointing out that both FlexSpin and PropGCC are able to cache small bits of code into COG memory automatically (this is called FCACHE in the documentation) so you may not actually need to compile your code to "native" COG code, the default large memory model (LMM) plus cache may be fast enough for your needs.

    Yes, I think this is a better way to go. I once implemented a cog mode in LCC for use in Catalina, but it ended up with too many limitations to be much use - you had to write your C code knowing in advance which bits were going to be compiled in cog mode, whereas with FCACHE you get can most of the benefit of executing at cog speeds without having to plan to use it in advance.

    However, I never could figure out a good rule to decide whether or not to automatically FCACHE code - and getting it wrong means you can even end up slowing down your code instead of speeding it up (due to the overheads of loading it into the FCACHE) so in Catalina you have to do it manually. However, I may revisit that. Not so much for use on the P1, but for the P2 where loading code into the cog is faster, and you also have more cog RAM available. This makes FCACHE much more attractive.

  • DavidZemonDavidZemon Posts: 2,973
    edited 2021-11-28 20:50

    @"Jack Buffington",

    If you're a fan of CMake and/or JetBrains CLion, you may have an interest in PropWare. It makes using PropGCC with modern tools much more friendly. Optionally, you can also choose to use any combination of the HALs that come with a PropWare distribution (some C, some C++).

    In particular, the "CMake Reference" page lists the file extensions that will be compiled with -mcog.

  • Jack Buffington,

    You might want to consider using the Propeller 2 which has features more common with other microcontrollers compared to the P1.

    The P2 hardware has only recently been finalized so the software tools and documentation are still a Work in Progress.
    The P2 Forum is quite active though and a number of people are working on compilers for other programming languages.

Sign In or Register to comment.