blippy
Posts: 123
Joined: Fri Nov 03, 2017 3:07 pm

Re: Circle - C++ bare metal environment (with USB)

Tue Nov 17, 2020 11:54 am

sean.lawless wrote:
Tue Nov 17, 2020 4:50 am
Circle is based on Linux so the USB host driver has a lot of Linux system dependencies, as you mentioned (hence Circle OS). .
I didn't know that Circle borrowed a lot from Linux. I had assumed it was a ground-up implementation.

My own dream goal is to have a kind-of "unikernel" that makes few assumptions about how the host application should work. It would be a highly decoupled system.

I'm not sure if that is ultimately attainable. As more functionality is added, it becomes increasingly reliant on surrounding infrastructure. One therefore ends up with a "framework" rather than a library.

There is an interesting project out there called Ultibo, which is built using Pascal. I tried it, and Pascal is not too bad, really. My disappointment is that seemed to have a pre-emptive scheduler, which will of course thwart attempts at any real-time processing.

An interesting approach seems to be Rumpkernel, which is the idea of running a kernel on top of NetBSD's anykernel. The idea is that the anykernel is a set of driver software. You then layer any flavour of kernel on top of that. NetBSD does, of course, provide its own kernel. This separation of layers strikes me as the way of doing it. I'm a little surprised that the idea hasn't caught on more. I hear that Andy Tanenbaum is porting his Minix3 kernel to the anykernel, for example.

On a different note, I am interested in buying your book. I'm very leery about the publisher, though. Having to agree to T&C's just to read a book puts me off, and I'm generally skeptical about cloud-based platforms. In my view, the majority of people aren't skeptical enough

rst
Posts: 497
Joined: Sat Apr 20, 2013 6:42 pm
Location: Germany

Re: Circle - C++ bare metal environment (with USB)

Tue Nov 17, 2020 2:34 pm

blippy wrote:
Tue Nov 17, 2020 11:54 am
sean.lawless wrote:
Tue Nov 17, 2020 4:50 am
Circle is based on Linux so the USB host driver has a lot of Linux system dependencies, as you mentioned (hence Circle OS). .
I didn't know that Circle borrowed a lot from Linux. I had assumed it was a ground-up implementation.

Indeed it is. Circle has a totally different concept, compared to Linux, with tightly coupled C++ classes. There are a number of drivers ported from Linux for Circle. The information for USB stack for the RPi 1-3 of course is widely based on the Linux driver, because there was only CSUD available as an alternative, when Circle started. The USB support for the RPi 4 has been developed from scratch. And yes, it is not that easy, to build Circle-based applications on non-Linux hosts, but it is possible with some adaptions to the Makefiles and scripts. Unfortunately I found no Make version 4.x for Windows, which is required to use all Circle functions.
I'm not sure if that is ultimately attainable. As more functionality is added, it becomes increasingly reliant on surrounding infrastructure. One therefore ends up with a "framework" rather than a library.

Indeed. That was the idea behind Circle, to provide a framework and the required infrastructure to develop bare-metal applications on the Raspberry Pi. BTW I wouldn't call it an OS, because it does not provide functions, which an OS normally has (e.g. loading programs). It's more like programming on a very fast micro-controller. ;)

sean.lawless
Posts: 55
Joined: Thu Jun 06, 2019 6:07 pm

Re: Circle - C++ bare metal environment (with USB)

Wed Nov 18, 2020 5:41 pm

blippy wrote:
Tue Nov 17, 2020 11:54 am
On a different note, I am interested in buying your book. I'm very leery about the publisher, though. Having to agree to T&C's just to read a book puts me off, and I'm generally skeptical about cloud-based platforms. In my view, the majority of people aren't skeptical enough
I typically agree, although after years of working with the team at Leanpub they have earned my trust.

Use the links below to directly download the first half of the book (sample) as a PDF, without signing up on Leanpub.

http://samples.leanpub.com/computersystems-sample.pdf
http://samples.leanpub.com/computersyst ... sample.pdf

If you would like to purchase outside of Leanpub you can send me a $10 payment on Paypal ([removed for security; IM me for my email address]) and I will email you the PDFs. If you want any format besides PDF you will have to use Leanpub.

Cheers,
Sean

rst
Posts: 497
Joined: Sat Apr 20, 2013 6:42 pm
Location: Germany

Re: Circle - C++ bare metal environment (with USB)

Tue Nov 24, 2020 9:54 pm

With the new Circle release 43.2 it is now possible to build all Circle sample programs on Windows without modification on build scripts or make-files. Details are available in the file doc/windows-build.txt in the project.

aj22r
Posts: 3
Joined: Sat May 27, 2017 1:40 pm

Re: Circle - C++ bare metal environment (with USB)

Mon Nov 30, 2020 5:48 pm

Thanks for this amazing project! I have already made a working shoutcast webradio player that outputs to I2S on a Pi Zero W. The only thing missing is bluetooth to use the Pi Zero W as an A2DP source. Have you looked at this https://github.com/bluekitchen/btstack? It already has a port for the raspberry pi but only linux, not bare metal. I've been trying to port it to circle for a while now, but it is a massive pain to get it all hooked up and working.

rst
Posts: 497
Joined: Sat Apr 20, 2013 6:42 pm
Location: Germany

Re: Circle - C++ bare metal environment (with USB)

Tue Dec 01, 2020 3:10 pm

aj22r wrote:
Mon Nov 30, 2020 5:48 pm
Thanks for this amazing project! I have already made a working shoutcast webradio player that outputs to I2S on a Pi Zero W. The only thing missing is bluetooth to use the Pi Zero W as an A2DP source. Have you looked at this https://github.com/bluekitchen/btstack? It already has a port for the raspberry pi but only linux, not bare metal. I've been trying to port it to circle for a while now, but it is a massive pain to get it all hooked up and working.

Thanks! Your project sounds very interesting. There has been rudimentary BT support earlier in Circle, but it was stopped, because of legal problems with the BT specs, which can only be used by members of the BT SIG. Sorry, but currently I do not have any plans to support BT again in Circle.

rst
Posts: 497
Joined: Sat Apr 20, 2013 6:42 pm
Location: Germany

Re: Circle - C++ bare metal environment (with USB)

Tue Dec 01, 2020 6:52 pm

Thanks to @MikeDB, I was able to test the CM4 on a CM4IO board with Circle. Generally it is working well. But there is still some work to do. I tried the internal xHCI controller of the BCM2711 and it is detected with the "otg_mode=1" setting in config.txt, but unfortunately it does not found an USB hub. The Gigabit Ethernet controller does not connect to the PHY. Probably a problem with the Circle driver yet.

cleverca22
Posts: 2880
Joined: Sat Aug 18, 2012 2:33 pm

Re: Circle - C++ bare metal environment (with USB)

Tue Dec 01, 2020 9:06 pm

rst wrote:
Tue Dec 01, 2020 6:52 pm
Thanks to @MikeDB, I was able to test the CM4 on a CM4IO board with Circle. Generally it is working well. But there is still some work to do. I tried the internal xHCI controller of the BCM2711 and it is detected with the "otg_mode=1" setting in config.txt, but unfortunately it does not found an USB hub. The Gigabit Ethernet controller does not connect to the PHY. Probably a problem with the Circle driver yet.
i believe the CM4 is using a different PHY from the rpi4b, so it will need new drivers

aj22r
Posts: 3
Joined: Sat May 27, 2017 1:40 pm

Re: Circle - C++ bare metal environment (with USB)

Tue Dec 01, 2020 10:04 pm

rst wrote:
Tue Dec 01, 2020 3:10 pm
aj22r wrote:
Mon Nov 30, 2020 5:48 pm
Thanks for this amazing project! I have already made a working shoutcast webradio player that outputs to I2S on a Pi Zero W. The only thing missing is bluetooth to use the Pi Zero W as an A2DP source. Have you looked at this https://github.com/bluekitchen/btstack? It already has a port for the raspberry pi but only linux, not bare metal. I've been trying to port it to circle for a while now, but it is a massive pain to get it all hooked up and working.

Thanks! Your project sounds very interesting. There has been rudimentary BT support earlier in Circle, but it was stopped, because of legal problems with the BT specs, which can only be used by members of the BT SIG. Sorry, but currently I do not have any plans to support BT again in Circle.
I've abandoned bluetooth for now and instead decided to write a driver for the enc28j60 to be able to use ethernet on the pi zero for one of my projects. I thought it would be easy and i would be done in a few hours but instead i went through even more hours of debugging and reflashing the sd card than when i was trying to implement BT. For some reason commenting out or changing the order of CLogger::Get()->Write being called completely changes the behaviour of the program. And also when CNetDevice::SendFrame gets called too much(?) for example when the pi sends a file over tftp the entire CNetDevice hangs and doesn't receive/send any more packets (CNetDevice::ReceiveFrame is still being polled though). Have you experienced any of this when writing the wlan or usb ethernet driver?

rst
Posts: 497
Joined: Sat Apr 20, 2013 6:42 pm
Location: Germany

Re: Circle - C++ bare metal environment (with USB)

Wed Dec 02, 2020 10:51 am

cleverca22 wrote:
Tue Dec 01, 2020 9:06 pm
i believe the CM4 is using a different PHY from the rpi4b, so it will need new drivers

It must be something like that. I'm trying to get the internal xHCI controller of the CM4 running first and will come back to this later.

rst
Posts: 497
Joined: Sat Apr 20, 2013 6:42 pm
Location: Germany

Re: Circle - C++ bare metal environment (with USB)

Wed Dec 02, 2020 11:12 am

aj22r wrote:
Tue Dec 01, 2020 10:04 pm
For some reason commenting out or changing the order of CLogger::Get()->Write being called completely changes the behaviour of the program.

Yes, the logger changes the timing, especially when it writes to the screen and scrolls. You should enable the REALTIME system option in include/circle/sysconfig.h. This reduces this effect very much. You will not see logger messages, generated from IRQ handlers, then any more.
And also when CNetDevice::SendFrame gets called too much(?) for example when the pi sends a file over tftp the entire CNetDevice hangs and doesn't receive/send any more packets (CNetDevice::ReceiveFrame is still being polled though). Have you experienced any of this when writing the wlan or usb ethernet driver?

No, but I worked only with network drivers over USB high-speed (480 Mbps) or with internal queues, read and written using DMA. That's much quicker than SPI. Transferring a 1500 byte Ethernet frame at 12 Mbps SPI clock takes 1 millisecond, which is relatively long, compared to the other interfaces. You may need some mechanism, so that not many frames are transferred in a row to/from the controller. This is implemented in lib/net/netdevlayer.cpp. Perhaps it is already enough to add the following after each SendFrame() and ReceiveFrame() (in line 115 and 121):

Code: Select all

CScheduler::Get ()->Yield ();

cleverca22
Posts: 2880
Joined: Sat Aug 18, 2012 2:33 pm

Re: Circle - C++ bare metal environment (with USB)

Wed Dec 02, 2020 11:18 am

rst wrote:
Wed Dec 02, 2020 11:12 am
aj22r wrote:
Tue Dec 01, 2020 10:04 pm
For some reason commenting out or changing the order of CLogger::Get()->Write being called completely changes the behaviour of the program.

Yes, the logger changes the timing, especially when it writes to the screen and scrolls.
the impact of scrolling could be greatly reduced if you make use of the HVS

https://github.com/librerpi/rpi-open-fi ... ocs/hvs.md
https://blog.benjdoherty.com/2019/05/21 ... pberry-Pi/
https://github.com/librerpi/lk/blob/vc4 ... /hvs/hvs.c

though the mailbox framebuffer also allows the same tricks, but with less flexibility

basically, allocate a framebuffer that is maybe 2x the height of the screen, and just change the y offset to move the entire framebuffer up/down, without having to move the contents

using the HVS directly, would make the wrap-around simpler, because you can display the tail and head of the image as 2 layers
while the mailbox api doesnt allow such wrap-around at the tail of the buffer

HVS drivers would also open up the ability to do sprites: https://www.youtube.com/watch?v=JFmCin3EJIs
that demo video was done with baremetal arm based on LK

rst
Posts: 497
Joined: Sat Apr 20, 2013 6:42 pm
Location: Germany

Re: Circle - C++ bare metal environment (with USB)

Wed Dec 02, 2020 3:32 pm

cleverca22 wrote:
Wed Dec 02, 2020 11:18 am
the impact of scrolling could be greatly reduced if you make use of the HVS

That's interesting. Currently I have some other work items, but when this is done, I will have a closer look on HVS. Thanks for info!

cleverca22
Posts: 2880
Joined: Sat Aug 18, 2012 2:33 pm

Re: Circle - C++ bare metal environment (with USB)

Wed Dec 02, 2020 3:57 pm

rst wrote:
Wed Dec 02, 2020 3:32 pm
cleverca22 wrote:
Wed Dec 02, 2020 11:18 am
the impact of scrolling could be greatly reduced if you make use of the HVS

That's interesting. Currently I have some other work items, but when this is done, I will have a closer look on HVS. Thanks for info!
when using 1:1 mode, you basically just generate a list of packets, each containing:
  • width/height of the image
  • x/y to render at
  • pixel format
  • if either axis is being flipped
  • stride
  • physical address (same dma rules as normal vc stuff, 0xc000_0000 based for pi2 and up)
  • an optional alpha override
and then the HVS will render every image in the list
the only real limits are the total amount of dedicated ram the list must fit within, and the memory bandwidth of the HVS to fetch all the data, its being fetched on the fly, as it generates each scanline

aj22r
Posts: 3
Joined: Sat May 27, 2017 1:40 pm

Re: Circle - C++ bare metal environment (with USB)

Wed Dec 02, 2020 5:11 pm

rst wrote:
Wed Dec 02, 2020 11:12 am

You may need some mechanism, so that not many frames are transferred in a row to/from the controller. This is implemented in lib/net/netdevlayer.cpp. Perhaps it is already enough to add the following after each SendFrame() and ReceiveFrame() (in line 115 and 121):
The problem was actually that the ENC28J60 was holding the INT line low which meant that the BCM2835 wasn't receiving any more gpio interrupts on that pin. The solution was to add a while(!m_IntPin.Read()) loop into the IRQ handler. Everything now seems relatively stable with a few dropped connections every now and then. A bigger problem however is apparently a race condition in CNetQueue. After some time of running, m_RxQueue.Enqueue in the IRQ handler seems to get called at the same time as m_RxQueue.Dequeue in ReceiveFrame which leads to this:
Image

rst
Posts: 497
Joined: Sat Apr 20, 2013 6:42 pm
Location: Germany

Re: Circle - C++ bare metal environment (with USB)

Wed Dec 02, 2020 7:09 pm

aj22r wrote:
Wed Dec 02, 2020 5:11 pm
A bigger problem however is apparently a race condition in CNetQueue. After some time of running, m_RxQueue.Enqueue in the IRQ handler seems to get called at the same time as m_RxQueue.Dequeue in ReceiveFrame which leads to this:
assertion failed in netqueue.cpp(129) ...

CNetQueue is normally not meant to be used from an IRQ handler. If you really need this, replace TASK_LEVEL with IRQ_LEVEL in this line.

rst
Posts: 497
Joined: Sat Apr 20, 2013 6:42 pm
Location: Germany

Re: Circle - C++ bare metal environment (with USB)

Thu Dec 03, 2020 10:27 am

cleverca22 wrote:
Wed Dec 02, 2020 3:57 pm
when using 1:1 mode, you basically just generate a list of packets, each containing:
  • width/height of the image
  • x/y to render at
  • pixel format
  • if either axis is being flipped
  • stride
  • physical address (same dma rules as normal vc stuff, 0xc000_0000 based for pi2 and up)
  • an optional alpha override
and then the HVS will render every image in the list
the only real limits are the total amount of dedicated ram the list must fit within, and the memory bandwidth of the HVS to fetch all the data, its being fetched on the fly, as it generates each scanline

Thanks! I have to see, if this fits into Circle. I don't want to make the screen output too complicated, given that most applications use their own screen routines or GUIs and there is also accelerated graphics support for the RPi 1-3.

rst
Posts: 497
Joined: Sat Apr 20, 2013 6:42 pm
Location: Germany

Re: Circle - C++ bare metal environment (with USB)

Fri Dec 04, 2020 11:02 pm

rst wrote:
Wed Dec 02, 2020 10:51 am
cleverca22 wrote:
Tue Dec 01, 2020 9:06 pm
i believe the CM4 is using a different PHY from the rpi4b, so it will need new drivers

It must be something like that. I'm trying to get the internal xHCI controller of the CM4 running first and will come back to this later.

The CM4 is using PHY address 0, instead of 1, which is used by RPi 4B and 400. The driver is the same. The internal xHCI controller is working now too. Remains the eMMC access, which is not working at the moment with the RPi 4B EMMC2 driver.

styro
Posts: 12
Joined: Tue Nov 10, 2015 8:37 pm

Re: Circle - C++ bare metal environment (with USB)

Tue Feb 09, 2021 8:01 pm

Hello,
i am switching to a raspi 4B and the newest version (43.3) of circle and been hit by a snag....
Trying to get SPI working and build 23-simplespi, 64bit for Raspi4B 2GB and get very strange output (see attached pictures).
It seems that only 2 bytes per 8bytes transmission get sent. While trying around i sendend multiple smaller transmissions (2Byte), then it started sending the value only after calling 2-4 m_SPIMaster.WriteRead (but only 2Bytes of it where sent). Beside this odd behaviour the transmitted Values are somehow fluctuating...
All the best, stay safe and Many thanks for any help
Attachments
spisimple_out_8_TEST_DATA_LENGTH.jpg
spisimple_out_8_TEST_DATA_LENGTH.jpg (75.96 KiB) Viewed 369 times
spisimple_out_4_TEST_DATA_LENGTH.jpg
spisimple_out_4_TEST_DATA_LENGTH.jpg (21.44 KiB) Viewed 369 times
spisimple_out.jpg
spisimple_out.jpg (56.62 KiB) Viewed 369 times

rst
Posts: 497
Joined: Sat Apr 20, 2013 6:42 pm
Location: Germany

Re: Circle - C++ bare metal environment (with USB)

Tue Feb 09, 2021 10:08 pm

@styro That's really strange. I tried to reproduce the problem, but everything worked fine here with SPI_MASTER_DEVICE 0 and TEST_DATA_LENGTH 2, 4 and 8 (image) on a RPi 4B 1.1 2GB:

spisimple-8-bytes.png
spisimple-8-bytes.png (20.41 KiB) Viewed 351 times

Is TEST_DATA_LENGTH the only modification to the sample program, you did? Which firmware version are you using?

styro
Posts: 12
Joined: Tue Nov 10, 2015 8:37 pm

Re: Circle - C++ bare metal environment (with USB)

Wed Feb 10, 2021 9:29 am

Hi rst
Many Thanks for Your answer, i reloaded & setted up circle again, et voilà, it seems to work!
all the best!

styro
Posts: 12
Joined: Tue Nov 10, 2015 8:37 pm

Re: Circle - C++ bare metal environment (with USB)

Fri Feb 19, 2021 12:36 pm

Hi There,
hope You are all well.
An other snag on the way to functionality ... for the Raspi4 i got this screen:
https://www.pi-shop.ch/5-800x480-tft-ra ... y-pi-3b-3b and under raspian it works out of the box (picture& touch) and with circle the screen works, but the touch not :-(
the 28-touchscreen example loads, and shows the attached error-screen...
the recognised 3 touches where wrong (the display wasnt touched) and then it dies.
Since it works under raspian, i suppose there is a incompatibility with the circle touch driver, does somebody have a hint or 2 about the touch-interface and where/how to poke around?
same screen, other problem... the contrast is much better when viewed upsidedown :shock: ....
with LVGL its not possible flip the screen, and hacking the driver to flip the bits wouldent work with DMA and would probably result in bad performance.... is there a way to turn the screen-content 180°?
Anyway, many, many thanks for the help and constantly improving circle, its really great to build nice things with it!
all the best
styro
Attachments
touch-error2.jpg
touch-error2.jpg (27.25 KiB) Viewed 168 times

styro
Posts: 12
Joined: Tue Nov 10, 2015 8:37 pm

Re: Circle - C++ bare metal environment (with USB)

Fri Feb 19, 2021 3:45 pm

The Display-Rotation was an easy fix with
display_lcd_rotate=2
in config.txt, sorry for bothering with that....

rst
Posts: 497
Joined: Sat Apr 20, 2013 6:42 pm
Location: Germany

Re: Circle - C++ bare metal environment (with USB)

Fri Feb 19, 2021 6:23 pm

@styro Thanks for appreciating Circle. I tested the official 7" RPi touchscreen again with a RPi 4B and Circle and it worked well. Unfortunately this is the only touchscreen, I do have here for testing and that's why it is the only one, which is supported by Circle. Probably your touchscreen behaves slightly different and the Circle driver cannot handle this.

DFL1973
Posts: 1
Joined: Thu Feb 25, 2021 9:06 pm

Re: Circle - C++ bare metal environment (with USB)

Thu Feb 25, 2021 9:10 pm

Hey rst, great work, thanks for sharing.

Is it possible to use the FAT with an external SD card connected to the GPIO?

Return to “Bare metal, Assembly language”