[SOLVED] Executing program at the veeery begining

Post Reply
Sebas_Ledesma
Posts: 224
Joined: Thu Jun 08, 2017 2:49 am
languages_spoken: english
ODROIDs: C4, C2, C1+
Has thanked: 45 times
Been thanked: 19 times
Contact:

[SOLVED] Executing program at the veeery begining

Post by Sebas_Ledesma »

Hi:

What is the suggested way to execute a 'console' program at the very-very beggining of the boot process?

I'm using ubuntu minimalist:
Linux Mx2200min 4.9.277-75 #1 SMP PREEMPT Sun Aug 8 23:26:32 UTC 2021 aarch64 aarch64 aarch64 GNU/Linux
and I want to show "booting" in a OLED display (I dont use monitor).

Currently my "boot time" it's around 15 seconds (ie, the first image that I shows in the OLED display appears around 15 seconds after powering up) and I'm executing my app from /etc/rc.local.

Thanks in advance,
Sebas
Last edited by Sebas_Ledesma on Sat Dec 04, 2021 1:57 am, edited 1 time in total.

User avatar
rooted
Posts: 8875
Joined: Fri Dec 19, 2014 9:12 am
languages_spoken: english
Location: Gulf of Mexico, US
Has thanked: 743 times
Been thanked: 407 times
Contact:

Re: Executing program at the veeery begining

Post by rooted »

If the driver for the display is a module it can't display anything until this module is loaded, I would try compiling the kernel so the driver is built in.

Sebas_Ledesma
Posts: 224
Joined: Thu Jun 08, 2017 2:49 am
languages_spoken: english
ODROIDs: C4, C2, C1+
Has thanked: 45 times
Been thanked: 19 times
Contact:

Re: Executing program at the veeery begining

Post by Sebas_Ledesma »

I'm using a 256x64 pixels oled display (4 bpp) and I've made my own routines to draw into it (as the manufacturer provided a very spartan demo).

Image

So no driver needed, I only need SPI access and wiringPi to set the data/command pin.

User avatar
rooted
Posts: 8875
Joined: Fri Dec 19, 2014 9:12 am
languages_spoken: english
Location: Gulf of Mexico, US
Has thanked: 743 times
Been thanked: 407 times
Contact:

Re: Executing program at the veeery begining

Post by rooted »

SPI can still be a module, if you are using SPI dev it's most likely a module.

Code: Select all

zcat /proc/config.gz | grep CONFIG_SPI_SPIDEV
If it says "y" it's built in but if it says "m" it's a module.
These users thanked the author rooted for the post:
Sebas_Ledesma (Tue Oct 26, 2021 11:56 pm)

User avatar
odroid
Site Admin
Posts: 38352
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean
ODROIDs: ODROID
Has thanked: 2128 times
Been thanked: 1264 times
Contact:

Re: Executing program at the veeery begining

Post by odroid »

I think you need to analyze the time of whole booting procedures first.
If you have a USB-UART cable, try this command on your Linux PC and turn on your device.

Code: Select all

grabserial -v -d "/dev/ttyUSB0" -b 115200 -w 8 -p N -s 1 -e 30 -t -m "bl2_stage_init"
It will show you a list of time stamps from SoC boot ROM to rc.local executions.

I believe you can reduce a few seconds with some tweaks in u-boot and kernel configurations.
But a period of 10~12 seconds is still quite long for your equipment.
In that case, you might need to add/implement a SPI driver in u-boot to control the OLED device in very early stage. It will show a splash logo in 1~2 seconds surely.
I have no idea if there is any SPI things in the current u-boot or not though.
These users thanked the author odroid for the post:
Sebas_Ledesma (Wed Oct 27, 2021 4:01 am)

User avatar
tobetter
Posts: 8665
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: Many
Location: Paju, South Korea
Has thanked: 503 times
Been thanked: 1382 times
Contact:

Re: Executing program at the veeery begining

Post by tobetter »

Sorry for joining this thread late, let me add my understanding.

1. The OLED module on HC4 does not use SPI bus, but use I2C.
2. Since it uses I2C, not necessary to use WiringPi if you know how to communicate a device through /dev/i2c-0.
3. If you application can run on a linux console, you will need to add it to initramfs to start the app, I've not tried this with HC4 OS image yet.
4. In case if you like to display anything on OLED on booting earlier than Linux kernel start, you need to change U-Boot.

FYI, https://wiki.odroid.com/odroid-hc4/appl ... d?s[]=oled
These users thanked the author tobetter for the post:
Sebas_Ledesma (Wed Oct 27, 2021 4:01 am)

User avatar
mctom
Posts: 782
Joined: Wed Nov 11, 2020 4:44 am
languages_spoken: english, polish
ODROIDs: N2+, Game Advance, a few XU4
Location: Gdansk, Poland
Has thanked: 81 times
Been thanked: 97 times
Contact:

Re: Executing program at the veeery begining

Post by mctom »

From HW perspective, if this is I2C indeed, one really simple and solid way would be to connect a tiny micro controller in parallel to I2C and power lines of the display. The micro controller would send the splash logo right after its own power-on, and then sleep forever.

This will work even before Linux boots and is still possible to do despite The Shortage. ;)
Punk ain't no religious cult, punk means thinking for yourself!

Maintainer of PiStackMon

User avatar
tobetter
Posts: 8665
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: Many
Location: Paju, South Korea
Has thanked: 503 times
Been thanked: 1382 times
Contact:

Re: Executing program at the veeery begining

Post by tobetter »

mctom wrote:
Tue Oct 26, 2021 4:17 pm
From HW perspective, if this is I2C indeed, one really simple and solid way would be to connect a tiny micro controller in parallel to I2C and power lines of the display. The micro controller would send the splash logo right after its own power-on, and then sleep forever.

This will work even before Linux boots and is still possible to do despite The Shortage. ;)
True, if one is not hesitate to add a tiny extra board and can manage small firmware to handle OLED and RTC for sure. :)

User avatar
odroid
Site Admin
Posts: 38352
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean
ODROIDs: ODROID
Has thanked: 2128 times
Been thanked: 1264 times
Contact:

Re: Executing program at the veeery begining

Post by odroid »

Relatively higher resolution OLED 256x64 dots with 4bit per pixel (16 grey level?) seems to have an SPI interface instead of I2C.

User avatar
mctom
Posts: 782
Joined: Wed Nov 11, 2020 4:44 am
languages_spoken: english, polish
ODROIDs: N2+, Game Advance, a few XU4
Location: Gdansk, Poland
Has thanked: 81 times
Been thanked: 97 times
Contact:

Re: Executing program at the veeery begining

Post by mctom »

Should be possible with SPI as well, especially if Odroid board stays in Hi-Z state before boot (which I expect to be the case).
No need to prepare sophisticated firmware, just dump data to SPI and go to sleep.

I know this is not what OP is asking for, but perhaps an alternative solution will spark some other idea to walk around the problem.
Punk ain't no religious cult, punk means thinking for yourself!

Maintainer of PiStackMon

Sebas_Ledesma
Posts: 224
Joined: Thu Jun 08, 2017 2:49 am
languages_spoken: english
ODROIDs: C4, C2, C1+
Has thanked: 45 times
Been thanked: 19 times
Contact:

Re: Executing program at the veeery begining

Post by Sebas_Ledesma »

odroid wrote:
Tue Oct 26, 2021 4:34 pm
Relatively higher resolution OLED 256x64 dots with 4bit per pixel (16 grey level?) seems to have an SPI interface instead of I2C.
Yes, this oled has a parallel interface (that I'm not using), and SPI inteface.
I'm opening "/dev/spidev0.0"

Code: Select all

void spi_WriteCmd(int fd, unsigned char cmd) {
	if (fd==-1) {
		return;
	}
	digitalWrite(MY_SPI_DC, 0); // Poner PIN data/cmd en 0

	int ret;
	uint8_t tx[] = {cmd};
	struct spi_ioc_transfer tr;

	memset(&tr, 0, sizeof(tr));
	tr.tx_buf = (unsigned long)tx;
	tr.rx_buf = (unsigned long)0;
	tr.len = ARRAY_SIZE(tx);
	tr.speed_hz = spiSpeed;
	tr.bits_per_word = bits;
	tr.delay_usecs = 0;
	tr.cs_change = 0;

	ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
	if (ret < 0)
		fprintf(stderr, "%s: can't send SPI message\n", __func__);

	digitalWrite(MY_SPI_DC, 1); /* */

}

void spi_WriteData(int fd, unsigned char data) {
	if (fd==-1) {
		return;
	}

	digitalWrite(MY_SPI_DC, 1); // Poner PIN data/cmd en 1
	int ret;
	uint8_t tx[] = {data};
	struct spi_ioc_transfer tr;

	memset(&tr, 0, sizeof(tr));
	tr.tx_buf = (unsigned long)tx;
	tr.rx_buf = (unsigned long)0;
	tr.len = ARRAY_SIZE(tx);
	tr.speed_hz = spiSpeed;
	tr.bits_per_word = bits;
	tr.delay_usecs = 0;
	tr.cs_change = 0;

	ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
	if (ret < 0)
		fprintf(stderr, "%s: can't send SPI message\n", __func__);
}
Perhaps I can avoid the wiringPi to set data/command line and use an ioctl command.

Sebas_Ledesma
Posts: 224
Joined: Thu Jun 08, 2017 2:49 am
languages_spoken: english
ODROIDs: C4, C2, C1+
Has thanked: 45 times
Been thanked: 19 times
Contact:

Re: Executing program at the veeery begining

Post by Sebas_Ledesma »

rooted wrote:
Tue Oct 26, 2021 1:36 pm
SPI can still be a module, if you are using SPI dev it's most likely a module.

Code: Select all

zcat /proc/config.gz | grep CONFIG_SPI_SPIDEV
If it says "y" it's built in but if it says "m" it's a module.
I can confirm that spi driver it's a module (using Ubuntu 20.04, with kernel 4.9.277-75)

Code: Select all

CONFIG_SPI_SPIDEV=m

User avatar
rooted
Posts: 8875
Joined: Fri Dec 19, 2014 9:12 am
languages_spoken: english
Location: Gulf of Mexico, US
Has thanked: 743 times
Been thanked: 407 times
Contact:

Re: Executing program at the veeery begining

Post by rooted »

If you include the module in initrd it will get loaded earlier and the screen should activate sooner.
These users thanked the author rooted for the post:
Sebas_Ledesma (Thu Oct 28, 2021 12:09 am)

Sebas_Ledesma
Posts: 224
Joined: Thu Jun 08, 2017 2:49 am
languages_spoken: english
ODROIDs: C4, C2, C1+
Has thanked: 45 times
Been thanked: 19 times
Contact:

Re: Executing program at the veeery begining

Post by Sebas_Ledesma »

thanks for all replies.
While trying the U-boot path, I'm also trying the /etc/init.d method.
I'm using as reference this post viewtopic.php?t=30848

So, I created a "oledsplash" script, made it executable and copied into /etc/init.d

Code: Select all

#! /bin/sh
### BEGIN INIT INFO
# Provides:          oledsplash
# Required-Start:
# Required-Stop:
# Should-Start:      
# Default-Start:     S
# Default-Stop:
# X-Start-Before:    bootmisc
# Short-Description: Show custom splashscreen
# Description:       Show custom splashscreen
### END INIT INFO


do_start () {

    /usr/bin/mx_booting
    exit 0
}

case "$1" in
  start|"")
    do_start
    ;;
  restart|reload|force-reload)
    echo "Error: argument '$1' not supported" >&2
    exit 3
    ;;
  stop)
    # No-op
    ;;
  status)
    exit 0
    ;;
  *)
    echo "Usage: oledsplash [start|stop]" >&2
    exit 3
    ;;
esac

:
I can manually execute it with 'sudo /etc/init.d/oledsplash'
/usr/bin/mx_booting it's a very simple program that opens /dev/spidev0.0 and uses the ioctl to send the pixels.

ie:

Code: Select all

void spi_WriteCmd(int fd, unsigned char cmd) {
	if (fd==-1) {
		return;
	}
	//digitalWrite(MY_SPI_DC, 0); // Poner PIN data/cmd en 0
    /*gpio_lineWrite(fdGpio, 68, 0);
    my_NanoSleep(1000);
    gpio_lineRead(fdGpio, 68);*/
    my_sysfs_gpio_Write(IO_SPI_DC, 0);

	int ret;
	uint8_t tx[] = {cmd};
	struct spi_ioc_transfer tr;

	memset(&tr, 0, sizeof(tr));
	tr.tx_buf = (unsigned long)tx;
	tr.rx_buf = (unsigned long)0;
	tr.len = ARRAY_SIZE(tx);
	tr.speed_hz = spiSpeed;
	tr.bits_per_word = bits;
	tr.delay_usecs = 0;
	tr.cs_change = 0;

	ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
	if (ret < 0)
		fprintf(stderr, "%s: can't send SPI message\n", __func__);

//	digitalWrite(MY_SPI_DC, 1);
//    gpio_lineWrite(fdGpio, 68, 1);
//    gpio_lineRead(fdGpio, 68);
}
I'm not longer using wiringPi to set the data/command bit for the spi communications, instead I switched to sysfs.

Observation #1 the original post viewtopic.php?t=30848 used the inserv command that it's no available in my distro.

After rebooting:
service --status-all

Code: Select all

 [ - ]  alsa-utils
 [ + ]  atd
 [ - ]  console-setup.sh
 [ + ]  cpufrequtils
 [ + ]  cron
 [ + ]  dbus
 [ + ]  fake-hwclock
 [ - ]  hwclock.sh
 [ - ]  keyboard-setup.sh
 [ + ]  kmod
 [ + ]  lighttpd
 [ + ]  loadcpufreq
 [ - ]  mpd
 [ + ]  network-manager
 [ - ]  oledsplash
 [ - ]  pppd-dns
 [ + ]  procps
 [ - ]  pulseaudio-enable-autospawn
 [ + ]  rsyslog
 [ + ]  ssh
 [ + ]  udev
 [ + ]  unattended-upgrades
 [ - ]  x11-common
but nothing was showed in the display.

And sudo systemctl status oledsplash

Code: Select all

● oledsplash.service - LSB: Show custom splashscreen
     Loaded: loaded (/etc/init.d/oledsplash; generated)
     Active: inactive (dead)
       Docs: man:systemd-sysv-generator(8)
Then I did sudo systemctl status oledsplash
and it correctly showed the text on the oled, and after that:
sudo systemctl status oledsplash

Code: Select all

● oledsplash.service - LSB: Show custom splashscreen
     Loaded: loaded (/etc/init.d/oledsplash; generated)
     Active: active (exited) since Mon 2021-11-29 23:35:12 UTC; 3s ago
       Docs: man:systemd-sysv-generator(8)
    Process: 2436 ExecStart=/etc/init.d/oledsplash start (code=exited, status=0>

Nov 29 23:35:07 Mx2200min systemd[1]: Starting LSB: Show custom splashscreen...
Nov 29 23:35:12 Mx2200min oledsplash[2442]: SPI mode: 0
Nov 29 23:35:12 Mx2200min oledsplash[2442]: SPI bits per word: 8
Nov 29 23:35:12 Mx2200min oledsplash[2442]: SPI speed: 5000000 Hz (5.00 MHz)
Nov 29 23:35:12 Mx2200min oledsplash[2442]: Inicializando display
Nov 29 23:35:12 Mx2200min systemd[1]: Started LSB: Show custom splashscreen.
Questions:
- Any alternative to "insserv" used in the original example?
- When it's sysfs avalable? I've tried also user-space gpio but not very sucesfully.

TIA
Sebas

User avatar
tobetter
Posts: 8665
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: Many
Location: Paju, South Korea
Has thanked: 503 times
Been thanked: 1382 times
Contact:

Re: Executing program at the veeery begining

Post by tobetter »

I would suggest another way using Systemd Unit instead of puting the script to /etc/init.d". From the link, you can take file ".service" and replace then line ExecStart with your app.
https://github.com/tobetter/odroid-home ... ay.service

Copy the file into /etc/systemd/system, then run systemctl enable odroid-homecloud-display, this will aftect on next booting.

Obviously the service file should be renamed to your own.
These users thanked the author tobetter for the post:
Sebas_Ledesma (Tue Nov 30, 2021 11:05 pm)

Sebas_Ledesma
Posts: 224
Joined: Thu Jun 08, 2017 2:49 am
languages_spoken: english
ODROIDs: C4, C2, C1+
Has thanked: 45 times
Been thanked: 19 times
Contact:

Re: Executing program at the veeery begining

Post by Sebas_Ledesma »

Thanks.

As suggested: I've created a 'boot-splash.service', copied it into /etc/systemd/system:

Code: Select all

sudo cp -p  boot-splash.service /etc/systemd/system
then enabled with

Code: Select all

sudo systemctl enable boot-splash.service
My boot-splash.service it's defined as:

Code: Select all

[Unit]
Description=Boot oled splash

[Service]
Type=simple
ExecStart=/usr/bin/mx_booting

[Install]
WantedBy=local-fs.target
I've initially defined WantedBy=multi-user.target
then used WantedBy=sysinit.target
and finally WantedBy=local-fs.target

and used
systemd-analyze plot > systemd.svg
to analyze and didnt notice difference between the 3 variants (attached picture).

Note: i did a

Code: Select all

sudo systemctl dissable boot-splash.service
before doing

Code: Select all

sudo systemctl enable boot-splash.service
with the new version of the service.

I'm looking at initrd as alternative.


Sebas

Sebas_Ledesma
Posts: 224
Joined: Thu Jun 08, 2017 2:49 am
languages_spoken: english
ODROIDs: C4, C2, C1+
Has thanked: 45 times
Been thanked: 19 times
Contact:

Re: Executing program at the veeery begining

Post by Sebas_Ledesma »

systemd-boot-splash.pdf
(47.55 KiB) Downloaded 4 times

User avatar
tobetter
Posts: 8665
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: Many
Location: Paju, South Korea
Has thanked: 503 times
Been thanked: 1382 times
Contact:

Re: Executing program at the veeery begining

Post by tobetter »

Sebas_Ledesma wrote:
Wed Dec 01, 2021 12:46 am
systemd-boot-splash.pdf
Nice.... :D

Can you introduce what SPI display you are running with C4, please?

Sebas_Ledesma
Posts: 224
Joined: Thu Jun 08, 2017 2:49 am
languages_spoken: english
ODROIDs: C4, C2, C1+
Has thanked: 45 times
Been thanked: 19 times
Contact:

Re: Executing program at the veeery begining

Post by Sebas_Ledesma »

I'm using an SSD3122 in 256 x 64 pixels mode with 16 luma levels (4bpp).
The controller can be used with parallel interface or SPI.
The proyect started with C2 and then we moved to C4.
With the C4 the spi hardware allowed to faster communications: 500 Khz speed in C2 vs 5Mhz in C4.
We also tested 10Mhz and seems to be fine.
Initially I've writed directly to the OLED display, now I've updated my code to use an internal frame buffer, so now i do (for example):

Code: Select all

void screen0(int fd) { 
    oled_BeginPaint();
    oled_Clear(fd);
    oled_puts(fd, 52, 32, "www.solidynePRO.com");
    oled_puts(fd, 20, 48, "Built: " __DATE__ " " __TIME__);
    oled_EndPaint(); //draws

    oled_putsInvertedWide(fd, 0, 0, "SOLIDYNE  MX2200"); //draws directly to spi, as this is an old function that dont yet support deffered (buffered) drawing.
}
with:

Code: Select all

void oled_BeginPaint() {
    oled_deferredPaint =1;
}

void oled_EndPaint()  {
    oled_Repaint(globalOledfd);
    oled_deferredPaint = 0;
}

void oled_Repaint(int fd) {
    oled_SetX(fd, 0);
    oled_SetY(fd, 0);

    spi_WriteCmd(fd, 0x5C); // Write RAM, verificar si es necesario
    int y;
    for (y = 0; y < 8; y++) {
		spi_WriteDataN(fd, vram+(y*1024), 1024);
    }
}

In the other hand, last night I've remembered that I have 2 (two) files servers that runs Ubuntu (and I was the one that installed both :D )
So I will use one of them to build u-boot.

User avatar
tobetter
Posts: 8665
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: Many
Location: Paju, South Korea
Has thanked: 503 times
Been thanked: 1382 times
Contact:

Re: Executing program at the veeery begining

Post by tobetter »

Is it like this?
https://www.alibaba.com/product-detail/ ... 17816.html

I expected there is a driver for SSD1322 in 4.9 kernel branch, apparently it's not. :(

Sebas_Ledesma
Posts: 224
Joined: Thu Jun 08, 2017 2:49 am
languages_spoken: english
ODROIDs: C4, C2, C1+
Has thanked: 45 times
Been thanked: 19 times
Contact:

Re: Executing program at the veeery begining

Post by Sebas_Ledesma »

It's pretty the same but IIRC correctly from another chinese manufacturer .
As I say we started the project with C2 wich uses an older kernel, and then moved to C4 with the basic oled working.
I will be good to have SSD1322 support in the kernel, so we can use a standard API and not have to implement our own.

User avatar
tobetter
Posts: 8665
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: Many
Location: Paju, South Korea
Has thanked: 503 times
Been thanked: 1382 times
Contact:

Re: Executing program at the veeery begining

Post by tobetter »

Sebas_Ledesma wrote:
Wed Dec 01, 2021 2:06 am
It's pretty the same but IIRC correctly from another chinese manufacturer .
As I say we started the project with C2 wich uses an older kernel, and then moved to C4 with the basic oled working.
I will be good to have SSD1322 support in the kernel, so we can use a standard API and not have to implement our own.
Thanks, I've found one linke for SSD1322 driver. Strangly this not in 4.9 kernel or upstream branch. :)
https://github.com/Combitech/simcom-lin ... sd1322fb.c

Sebas_Ledesma
Posts: 224
Joined: Thu Jun 08, 2017 2:49 am
languages_spoken: english
ODROIDs: C4, C2, C1+
Has thanked: 45 times
Been thanked: 19 times
Contact:

Re: [SOLVED] Executing program at the veeery begining

Post by Sebas_Ledesma »

WIth your help at viewtopic.php?f=202&t=43612 I was able to add my code to the u-boot and use SPI. Now the 'Solidyne' logo shows very quickly (around 1~2 secs) when powering up :D :D :D

User avatar
tobetter
Posts: 8665
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: Many
Location: Paju, South Korea
Has thanked: 503 times
Been thanked: 1382 times
Contact:

Re: [SOLVED] Executing program at the veeery begining

Post by tobetter »

Sebas_Ledesma wrote:
Sat Dec 04, 2021 3:39 am
WIth your help at viewtopic.php?f=202&t=43612 I was able to add my code to the u-boot and use SPI. Now the 'Solidyne' logo shows very quickly (around 1~2 secs) when powering up :D :D :D
How quickly finished it!!
Congratulation!!

User avatar
mad_ady
Posts: 9974
Joined: Wed Jul 15, 2015 5:00 pm
languages_spoken: english
ODROIDs: XU4, C1+, C2, C4, N1, N2, H2, Go, Go Advance
Location: Bucharest, Romania
Has thanked: 631 times
Been thanked: 780 times
Contact:

Re: [SOLVED] Executing program at the veeery begining

Post by mad_ady »

@Sebas_Ledesma perhaps you can share your changes, so that maybe uboot can display useful messages on HC4 in a future update... :)

Sebas_Ledesma
Posts: 224
Joined: Thu Jun 08, 2017 2:49 am
languages_spoken: english
ODROIDs: C4, C2, C1+
Has thanked: 45 times
Been thanked: 19 times
Contact:

Re: [SOLVED] Executing program at the veeery begining

Post by Sebas_Ledesma »

I don't know what display uses the HC4 but here are some points.

I initially started with the intention to use the spi hardware / spi driver, this would me allow to make bulk transfers. I used this strategy when started the development in C2. In C2 there was a small gain both in CPU consumption and oled drawing, but still was slow as the SPI it's software implemented. I even did bit-banging and the result was pretty the same. So we designed the oled update routines to be optimized (ie: vumeters are updated differentially).
When we moved to C4, the new hardware allowed to use 5Mhz (we even tested 10Mhz and seems good), so the drawing increased dramatically (and CPU consumption decreased).
So that was my intention when moving to the u-boot, but I was having trouble using the SPI, perhaps more time investigating would solve it, so I've retourned with my old bit-banged SPI routine.

The main trouble here was to correctly identify what was the id of each PIN.
ie: the SPI Reset Pin it's the PIN #18 in the J2 connector, it's the pin 5 in WiringPi, it's the GPIO 477 in sysfs, i-dont-remeber-what-pin-is in user-space gpio, and when working in u-boot it's another different number :D GPIOEE(GPIOX_1)

I've asked a co-worker for a hand and with an oscillscoper we noticed that even the 'SPI command/DATA' wasn't moving. After we discovered that we found that the bug was solved with this:

Code: Select all

#define MY_SPI_RESET GPIOEE(GPIOX_1)  //477 //pin 18
#define MY_SPI_MOSI  GPIOEE(GPIOX_8)  //484  //pin 19, Master Output, Slave Input
#define MY_SPI_DC  GPIOEE(GPIOX_2) //478    //pin 22, command/DATA
#define MY_SPI_CS  GPIOEE(GPIOX_10) // 486    //pin 24, Chip Select, tambien denominado Slave Select.
#define MY_SPI_SCLK  GPIOEE(GPIOX_11) // 487  //pin 23
After that the function mySpiWrite from viewtopic.php?p=339294#p339294
started to work.

I know that the bit-banged version of mySpiWrite it's not as faster as using the driver/hardware but as it doesnt depend of them we can move the call to our 'oled_logo();' from board_late_init() to board_init(); and that allowed to gain a little more time.

I didnt ported any complex drawing routing like 'oled_puts', 'oled_drawLine', 'oled_fillBlock', not even I'm trying to load the .bmp from the file system (I have to learn how u-boot does that), instead to keep my code to minimum I've used a Byte array that holds the information of the pixels of the logo, so after initializing the display I just send byte per byte the 'bmp' and that's all.

Code: Select all

int oled_showlogo(void) {

	debug("oled_showlogo: Hola mundo!");
	
	if (gpio_request(MY_SPI_RESET, "MY_SPI_RESET")!=0)
		debug("oled_showlogo: No pude obtener MY_SPI_RESET");
	if (gpio_request(MY_SPI_MOSI, "MY_SPI_MOSI")!=0)
		debug("oled_showlogo: No pude obtener MY_SPI_MOSI");
	if (gpio_request(MY_SPI_DC, "MY_SPI_DC")!=0)
		debug("oled_showlogo: No pude obtener MY_SPI_DC");
	if (gpio_request(MY_SPI_CS, "MY_SPI_CS")!=0)
		debug("oled_showlogo: No pude obtener MY_SPI_CS");
	if (gpio_request(MY_SPI_SCLK, "MY_SPI_SCLK")!=0)
		debug("oled_showlogo: No pude obtener MY_SPI_SCLK");

	gpio_direction_output(MY_SPI_RESET, 1);
	gpio_direction_output(MY_SPI_MOSI, 0);
	gpio_direction_output(MY_SPI_DC, 0);
	gpio_direction_output(MY_SPI_CS, 0);
	gpio_direction_output(MY_SPI_SCLK, 0);
	
	oled_Init();	
	udelay(500000); //0.5 secs delay
	mySpiWrite(0, 0xa7); // send command "Inverse Display"
	udelay(500000); //0.5 secs delay
	mySpiWrite(0, 0xa6); // send command "Normal Display"

	gpio_free(MY_SPI_RESET);
	gpio_free(MY_SPI_MOSI);
	gpio_free(MY_SPI_DC);
	gpio_free(MY_SPI_CS);
	gpio_free(MY_SPI_SCLK);

return 0;
}
These users thanked the author Sebas_Ledesma for the post (total 3):
mctom (Sat Dec 04, 2021 7:02 am) • tobetter (Sat Dec 04, 2021 9:23 am) • odroid (Mon Dec 06, 2021 9:35 am)

User avatar
rooted
Posts: 8875
Joined: Fri Dec 19, 2014 9:12 am
languages_spoken: english
Location: Gulf of Mexico, US
Has thanked: 743 times
Been thanked: 407 times
Contact:

Re: [SOLVED] Executing program at the veeery begining

Post by rooted »

Thank you for sharing your findings Sebas.

Post Reply

Return to “Ubuntu”

Who is online

Users browsing this forum: No registered users and 0 guests