Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fully tested for aarch64 OS without a bus error #289

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

meesokim
Copy link

aarch64 architecture is for 64bit OS.
It doesn't allow the 32bit compiler option like -marm -mabi=aapcs-linux -mhard-float -mfloat-abi=hard
So I've replaced them to 64bit compiler option.
Unfortunately BCM2835_TIMER_BASE is not an aligned 64bit address. Therefore we can use 64bit address directly.
It's fixed by calculating upper 32bit and lower 32bit value respectively.
There is no more any bus error after applying this patches.

aarch64 architecture is for 64bit OS.
It doesn't allow the 32bit compiler option like -marm -mabi=aapcs-linux -mhard-float -mfloat-abi=hard
If only the architecture is not aarch64, it follows the existing compiler option, otherwise drop unacceptable options.
spi.cpp
tick.h
display.h
spi.cpp
spi.h
volatile uint64_t *systemTimerRegister = 0;

#endif
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if instead of the above, it would work to do

#if __aarch64__
typedef uint64_t __attribute__((aligned(4))) timer_uint64_t;
#else
typedef uint64_t timer_uint64_t;
#endif

volatile timer_uint64_t *systemTimerRegister = 0;

This will tell the compiler that systemTimerRegister points to something that is only 32-bit aligned, and it should then automatically generate the appropriate 32-bit load and stores on its own.

After that, the other #ifdef __aarch64__s would not be necessary below?

Copy link
Author

@meesokim meesokim Jan 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've applied your patch on the following 64bit OS.
"Linux raspberrypi 5.15.84-v8+ #1613 SMP PREEMPT Thu Jan 5 12:03:08 GMT 2023 aarch64 GNU/Linux"

But it makes same bus error.

bcm_host_get_peripheral_address: 0x3f000000, bcm_host_get_peripheral_size: 16777216, bcm_host_get_sdram_address: 0xc0000000
BCM core speed: current: 400000000hz, max turbo: 400000000hz. SPI CDIV: 6, SPI max frequency: 66666667hz
Initializing display
bcm2835 library version: 10071 (0x00002757)
Creating SPI task thread
InitSPI done
Bus error

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, bummer. That would have been sweet if that had worked.

@juj
Copy link
Owner

juj commented Jan 31, 2023

Looks like some unrelated commit slipped into the PR tree?

systemTimerRegister = (volatile uint64_t*)((uintptr_t)bcm2835 + BCM2835_TIMER_BASE + 0x04); // Generates an unaligned 64-bit pointer, but seems to be fine.
#endif
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe

// On 32-bit Pi, we can perform an unaligned 64-bit pointer access to read the timer for a micro-optimization, but on 64-bit Pi reading in 32-bit parts is needed.
#if __aarch64__
  systemTimerRegister = (volatile uint32_t*)
#else
  systemTimerRegister = (volatile uint64_t*)
#endif
systemTimerRegister = (volatile uint32_t*)((uintptr_t)bcm2835 + BCM2835_TIMER_BASE + 0x04);

?

@@ -5,11 +5,14 @@
#include <unistd.h>

// Initialized in spi.cpp along with the rest of the BCM2835 peripheral:
#if __aarch64__
extern volatile uint32_t *systemTimerRegister;
#define tick() (*systemTimerRegister+((uint64_t)(*(systemTimerRegister+1))<<32))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe

#define tick() (systemTimerRegister[0] | ((uint64_t)systemTimerRegister[1] << 32))

?

@lolax80
Copy link

lolax80 commented Jun 6, 2023

Does a 64bit Version of rcp-ili9341 will come?

@samveen
Copy link
Contributor

samveen commented Aug 1, 2023

@meesokim would you please seperate out the kedei_trash stuff out into a seperate PR, so that we users can test this more easily?

@Keniis0712
Copy link

I cloned it and built, but it still caused a bus error:

bcm_host_get_peripheral_address: 0x3f000000, bcm_host_get_peripheral_size: 16777216, bcm_host_get_sdram_address: 0xc0000000
BCM core speed: current: 250000000hz, max turbo: 400000000hz. SPI CDIV: 6, SPI max frequency: 66666667hz
Allocated DMA channel 7
Allocated DMA channel 1
Enabling DMA channels Tx:7 and Rx:1
Bus error

I'm sure there wasn't any compile error and this was the only question

@maxgdn
Copy link

maxgdn commented Jan 10, 2024

I cloned it and built as well, but also get a bus error:

sudo apt-get install libraspberrypi-dev raspberrypi-kernel-headers
lscpu
Architecture:            aarch64
  CPU op-mode(s):        32-bit, 64-bit
  Byte Order:            Little Endian
CPU(s):                  4
lsb_release -a
No LSB modules are available.
Distributor ID:	Debian
Description:	Debian GNU/Linux 12 (bookworm)
Release:	12
Codename:	bookworm
cmake -DWAVESHARE35B_ILI9486=ON -DSPI_BUS_CLOCK_DIVISOR=25 -DDMA_TX_CHANNEL=9 -DDMA_RX_CHANNEL=6 -DSTATISTICS=0 ..
bcm_host_get_peripheral_address: 0xfe000000, bcm_host_get_peripheral_size: 25165824, bcm_host_get_sdram_address: 0xc0000000
BCM core speed: current: 232527000hz, max turbo: 500000000hz. SPI CDIV: 25, SPI max frequency: 20000000hz
Allocated DMA channel 9
Allocated DMA channel 6
Enabling DMA channels Tx:9 and Rx:6
Bus error

This is off of the newest Raspbian Lite install.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants