Close

Just thinking out loud

A project log for AVR-Laptop

Pushing an 8-bit MCU far beyond what it was designed for

vladimir-tsibrovVladimir Tsibrov • 10/09/2026 at 15:53•0 Comments

I have created 126 square meters of soil. I have created a device based on the ATmega2560 with a multitasking shell and a set of tasks. But every task needs memory to run. The ATmega2560 has only 8 KB of SRAM, and almost all of it is taken. So I need a lot more memory. Good thing I know the recipe: take external SRAM, a latch register, and hook it up to the XMEM interface.

Originally, I planned to add external memory in the next version of the device. And I already have a bunch of ideas for it: external memory, a bigger display, a separate controller for the display, maybe even a bus for external devices. But right now it feels like the current memory limitations don't let me call this version logically complete: the file manager is limited in path length and nesting depth; in some cases I even use the video buffer as a data buffer (when copying files, I read data from SD into the video buffer without drawing it to the display, then write it to a new file); the text editor with a tiny working buffer is just painful. So I'm considering freezing the current state as v1 and adding external memory as v1.1. All other major improvements will stay for the second version.

Also, adding external memory would let me move the video buffer (which takes 1 KB) into it. Access will be slower than with internal memory. But on the other hand, most screen changes are triggered by user actions (key presses) and aren't critical to redraw speed. Meanwhile, a whole kilobyte would be freed up in internal memory, which could be used for FreeRTOS task contexts (moving the contexts themselves to external memory is definitely not worth it).

The problem is that there's no room in the case for another board (memory and latch), so it has to grow. I could replace my 128×64 display with a 192×64 one — that goes well with enlarging the case and justifies it (a small display in a big case would look out of proportion). I already have such a display, but I haven't worked with it yet. Judging by the CS1, CS2, CS3 pins on its board, I suspect it's based on the KS0108: three of these controllers handle a 64×64 area of the display.

An important point — as far as I know, this controller draws pixels not horizontally (like my current ST7920), but vertically: the first byte draws a vertical column of 8 pixels, the second byte draws the column to its right, and so on to the end of the page. This differs from the memory layout of my video buffer — it's horizontal. So the question is: change the video buffer layout so it mirrors the display memory, but that would require changing all graphics functions, all the way up to XBM rendering and my video converter. Or keep the current layout and logic, but transpose the data when sending (or rather, before sending, so the ISR takes already-prepared bytes). I prefer the second option — if I can implement it with minimal overhead.

Another point — my dirty-line mechanism. In its current form it doesn't fit the way KS0108 works, since sending will be by pages, not by lines. Also, right now I have 64 lines, whereas this controller has 8 pages — that's too coarse for a dirty-region mechanism. Although I have 3 controllers, which gives a logical split into 3 physical zones of the display, i.e. that's already 24 dirty regions. Still coarse...

Regarding the three controllers and three CS lines — it would be interesting to test the idea of sending data alternately to each of them. That is, after sending a byte to the first controller, don't wait for it to become free, but check the readiness of the second and send a byte to it. Then the same with the third controller. Maybe this will minimize waiting time and speed up frame sending.

So adding XMEM turns into a series of serious improvements. But it also opens up new possibilities for the firmware and tasks. I already have the memory itself — HM628512BLFP-7, 512 kilobytes, which is far more than the ATmega2560 can address (64 KB). So I plan to do bank addressing and give each task its own 32 KB bank. Bank switching will happen on FreeRTOS context switch.

In short, I need tests. Lots of tests.

Discussions