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

boards/cpu: Add GBA boot support to RIOT #19519

Merged
merged 2 commits into from
Apr 10, 2024

Conversation

Teufelchen1
Copy link
Contributor

@Teufelchen1 Teufelchen1 commented Apr 27, 2023

Contribution description

Hi! 🦦

After my draft showcasing threading & gpu acceleration support in #19430, this PR is the first step towards that goal.

Included are the following features:

  • Adding a board gba_cartridge. In the GBA-ecosystem, the CPU/SoC/etc. is always the same, however, cartridges might bring their own ROM, RAM, RTC, ... - This first gba_cartridge board doesn't add any features and is hence empty. The always required boot-rom is indirectly added via the cpu support. Here I need your help: If one wanted to add an other gba_cartridge_extra_ram, which features additional RAM (e.g. the Pokemon games do this!), the linker script needs to be adjusted. This script lies in the cpu folder. How could we model that in RIOT?
  • Adding the cpu arm7tdmi_gba. I choose this name as the GBA features an ARM7TDMI but with typical Nintendo limitations/changes. The support is very limited and this PR sets the focus on getting RIOT to build and boot. Here I need your help: What is the correct way to blacklist features that are not supported yet? e.g. Threading.
  • Startup assembly & GBA header. The GBA executes a BIOS before the flow of control is passed to RIOT. This BIOS checks the inserted cartridge if a specific header is present. This header includes, among other things, the Nintendo logo. This logo is included in this PR. From what I can see in the homebrew-scene, people don't care anymore (and so did the uCLinux people back in the day) and it is unlikely for Nintendo to pursue legal actions. However, we might skip the risk and ask the user to provide a valid header file themselves. Update: I removed the logo, most emulators do not check the logo anyway.
  • Adding a stdio framebuffer driver. In order to run the hello-world example, a stdio driver is needed. The included driver called stdio_fb renders text to the LCD screen of the GBA. It brings it's own font. Help: Does RIOT already have it's own font? Could/ Should this driver be generalized and moved to the other stdio drivers?
  • In periph_cpu.h, many GBA special purpose register are listed. Help: Is that the correct location for such defines? As for the names, I tried to stick to the common naming convention of the homebrew-scene, mostly influenced by the "devKit pro".

Testing procedure

Grab an emulator of your choice. E.g. mgba. Then:

cd RIOT/example/hello-world
BOARD=gba_cartridge make
mgba bin/gba_cartridge/hello-world.bin

Screenshot_2023-04-27_16-26-12

@github-actions github-actions bot added Area: boards Area: Board ports Area: build system Area: Build system Area: cpu Area: CPU/MCU ports Area: doc Area: Documentation Area: Kconfig Area: Kconfig integration labels Apr 27, 2023

static void clearScreen(void)
{
memset(GBA_VRAM, 0x00, 240 * 160 * 2);
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's use a define for width and height, we can likely reuse this code for other displays.

Why the * 2? Is this double-buffering or do we have 16 bit/pixel?

(I don't see any flip buffer / commit command - how (often) is the framebuffer sent to the display?)

Copy link
Contributor Author

@Teufelchen1 Teufelchen1 May 4, 2023

Choose a reason for hiding this comment

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

I added the define for the screen size, got lost during refactoring oops.
The * 2 is indeed because of 15 bit/pixel yes, 15 - at least in the display-mode selected for stdio_fb. The graphic options/settings/modes are impressive for such a little device. When a proper "gpu driver" is added in the future (not in this PR), this will probably get a rework. I hence just added a comment for now.

There is no dedicated flip, the gpu redraws the current memory in the buffer automatically with ~60FPS. Ideally, you would wait for h-blank and then update the buffer, otherwise you'll get tearing. In this first PR, I just accepted that. :) By the way, the GBA can also do double-buffering if you ask nicely.

cpu/arm7tdmi_gba/include/cpu.h Outdated Show resolved Hide resolved
cpu/arm7tdmi_gba/include/cpu_conf.h Outdated Show resolved Hide resolved
cpu/arm7tdmi_gba/include/cpu_conf.h Outdated Show resolved Hide resolved
Comment on lines 96 to 80
/**
* @brief Stack size used for the interrupt (ISR) stack
* @{
*/
#ifndef ISR_STACKSIZE
#define ISR_STACKSIZE (400)
#endif
/** @} */

/**
* @brief Stack size used for the fast interrupt (FIQ) stack
* @{
*/
#define FIQ_STACKSIZE (64)
/** @} */

/**
* @brief Stack size used for the supervisor mode (SVC) stack
* @{
*/
#define SVC_STACKSIZE (400)
/** @} */

/**
* @brief Stack size used for the user mode/kernel init stack
* @{
*/
#define USR_STACKSIZE (4096)
Copy link
Contributor

Choose a reason for hiding this comment

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

If you find more things that should rather be in arm7_common (because you copied them verbatim from lpc23xx) better move them there instead of creating a copy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the file. I don't think it can be moved to arm7_common as the GBA differs a lot - I yet have to figure out how to translate "technical hardware description" into config file ;-) e.g. I changed most stacks to zero bytes as the GBA won't have these stacks (except the ISR, thats just not implemented yet).

cpu/arm7tdmi_gba/include/periph_cpu.h Outdated Show resolved Hide resolved
@github-actions github-actions bot added the Platform: ARM Platform: This PR/issue effects ARM-based platforms label May 4, 2023
@MrKevinWeiss
Copy link
Contributor

image

Very nice, easy to setup and load... Would we add an emulator into RIOT as well?

@MrKevinWeiss
Copy link
Contributor

you may squash if you want!

@Teufelchen1 Teufelchen1 force-pushed the feat/gba branch 2 times, most recently from 18efd72 to 95daad1 Compare March 27, 2024 11:10
@MrKevinWeiss MrKevinWeiss added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Mar 27, 2024
@MrKevinWeiss
Copy link
Contributor

you may squash if you like. I also don't know about this introduce Makfile.default on this PR... might be a bit much (though a good idea).

@riot-ci
Copy link

riot-ci commented Mar 27, 2024

Murdock results

✔️ PASSED

06c4cbb */Makefile.ci: Add gba_cartridge

Success Failures Total Runtime
10045 0 10045 11m:54s

Artifacts

@MrKevinWeiss
Copy link
Contributor

Ahh you are also getting the rust failure...

@MrKevinWeiss
Copy link
Contributor

also don't know about this introduce Makfile.default on this PR

Ahh seems like it is already a thing in RIOT (I learn something new everyday)

Copy link
Contributor

@MrKevinWeiss MrKevinWeiss left a comment

Choose a reason for hiding this comment

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

Not that I understand the internals of the GBA or the assembly but I believe @Teufelchen1 will be responsible for this and what I do know looks good. I tested it previously and saw it running. If murdock passes I think it is fine! ACK!

@Teufelchen1 Teufelchen1 added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Mar 28, 2024
@Teufelchen1 Teufelchen1 added this pull request to the merge queue Mar 28, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 28, 2024
@Teufelchen1 Teufelchen1 added this pull request to the merge queue Mar 29, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 29, 2024
@Teufelchen1 Teufelchen1 added this pull request to the merge queue Mar 29, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 29, 2024
@github-actions github-actions bot added Area: tests Area: tests and testing framework Area: examples Area: Example Applications labels Mar 30, 2024
@MrKevinWeiss MrKevinWeiss added this pull request to the merge queue Mar 30, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 30, 2024
@MrKevinWeiss
Copy link
Contributor

if you rebase I bet it will pass now :)

@benpicco benpicco added this pull request to the merge queue Apr 10, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 10, 2024
@Teufelchen1
Copy link
Contributor Author

Rebased + removed periph_pm from the provided features in a fixup. This should work now... x.x

@Teufelchen1 Teufelchen1 added this pull request to the merge queue Apr 10, 2024
Merged via the queue into RIOT-OS:master with commit 8791e67 Apr 10, 2024
25 checks passed
@maribu
Copy link
Member

maribu commented Apr 10, 2024

🎉

@MrKevinWeiss MrKevinWeiss added this to the Release 2024.04 milestone Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: boards Area: Board ports Area: build system Area: Build system Area: cpu Area: CPU/MCU ports Area: doc Area: Documentation Area: examples Area: Example Applications Area: Kconfig Area: Kconfig integration Area: tests Area: tests and testing framework CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: ARM Platform: This PR/issue effects ARM-based platforms
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants