3
\$\begingroup\$

I'm trying to make a small microcomputer from individual parts, but I'm having a hard time understanding how to load code onto the processor to be able to run it and do something.

Attached is my schematic so far (Schematic X1 Project), it is very messy and maybe not well designed as I am new to this. Since it is so messy, the rundown is that the CPU external memory and data pins are connected to the two RAM chips, there is one IO pin from the CPU connected to an LED.

enter image description here

My goal is to learn how to run machine code to make this LED power on. Other than those pins, I have some chip select pins for the RAM and then I have all the power pins hooked up with the correct voltages. I really do not understand how I am supposed to get machine code onto my CPU and make it run it, can anyone help?

If it helps, here is the CPU datasheet (LPC2212_2214) and the RAM datasheet (CY7C1299BN).

If anyone can help, that would be amazing.

\$\endgroup\$
16
  • 8
    \$\begingroup\$ Why do you need or have the external RAM there? The MCU can blink a LED just fine without it. Except with a missimg resistor for the LED, the LED can be damaged, so actually, it can't blink it just fine. What's the purpose of this device? Frankly, the schematics are quite unreadable, that's not how you should be drawing schematics. \$\endgroup\$
    – Justme
    Jan 24 at 7:10
  • 6
    \$\begingroup\$ that is a wiring diagram, not a schematic diagram. \$\endgroup\$
    – jsotola
    Jan 24 at 8:24
  • 5
    \$\begingroup\$ Bear in mind: you're talking about a MCU (Microcontroller) not a MPU or CPU (Microprocessor) Generally, (There are exceptions) the difference is an MPU does not have any integrated memory, for example the Zilog Z80. You run your code by loading it onto memory ICs, hooking them up to the Z80, and then the Z80 will run the code on the chips. MCUs have internal memory that is programmed. MCUs do not really need external memory like your schematic shows, and it adds a lot of typically unnecessary complexity. If you want external memory, you may want to redesign around an MPU. (Such as the Z80) \$\endgroup\$
    – Shades
    Jan 24 at 14:14
  • 5
    \$\begingroup\$ The complete absence of passive components should be a big warning sign that this schematic is not anywhere near the review stage yet. \$\endgroup\$
    – Lundin
    Jan 24 at 15:17
  • 13
    \$\begingroup\$ @Jeremys556 I think you are in a "you don't know what you don't know" situation here. Based on context, it seems like you are early in your electronics journey. I don't mean to discourage you, but what you are describing is way more than you are likely to be able to handle at this point. I would highly recommend you start with a class or tutorials, working on simpler circuits. Something like an Arduino will cost you very little and is a great platform to start learning on. It's understandable that you want to build what you want to build, but you need to build a foundation of knowledge first. \$\endgroup\$
    – notloc
    Jan 24 at 23:39

5 Answers 5

22
\$\begingroup\$

You use an in-circuit serial programmer (ICSP), debugger, or JTAG that sits between your computer's USB port and your board. You lay out the board so the programmer connects to the board and microcontroller based on the microcontroller manual. You posted the datasheet. It's far too small to tell you everything about the processor. There's a much larger 1000+ page manual someone where for it. Getting the programming wiring correct makes or break your board. There are few workarounds here if something goes wrong.

EDIT: Courtesy of @bracco23: https://www.nxp.com/docs/en/user-guide/UM10114.pdf

That said, you've skipped a bunch of important steps:

You generally pick the JTAG or ICSP, IDE, and compiler BEFORE or at the same time that you choose your processor. This tends to make or break what processor you can use. In some cases, the available programmer, IDE, and compiler for the microcontroller you choose are unaffordable.

You also pick the processor AFTER seeing the manual so you know if the documentation is actually well written enough that you actually want to work with it, to get a handle on whether your skills are developed enough to be able to use the processor, and to see if the peripherals work the way you want them to work. But from your post it looks like you have never seen the manual.

At this point there is an extremely high chance this project will fail. You chose the processor and began laying out the board without first examining the manual, or considering the programmer or IDE. On top of that you skipped straight to use using external RAM.

Use netnames, not an unverifiable mess of point-to-point wires in your schematic.

\$\endgroup\$
9
  • 4
    \$\begingroup\$ +1 I've seen programmers for microcontrollers cost upwards of $300, not even accounting for any IDE or compilers needed. This is an important consideration to point out \$\endgroup\$
    – Shades
    Jan 24 at 14:23
  • \$\begingroup\$ for completeness, because it was like one google away, here is the manual: nxp.com/docs/en/user-guide/UM10114.pdf given it's an ARM processor the project might still be good, there might be support with readily available compilers and IDE \$\endgroup\$
    – bracco23
    Jan 24 at 14:29
  • 3
    \$\begingroup\$ @Shades: You can certainly spend that money on a nice in-circuit programmer/debugger/trace (think logic analyzer for processor internal events) interface compatible with that MCU, but for just programming you can do it with an SWD interface in the <$15 range. \$\endgroup\$
    – Ben Voigt
    Jan 24 at 16:55
  • 4
    \$\begingroup\$ I appreciate most of the answer (maybe you could add a suggestion for an alternative, simpler CPU for OP's learning), but berating OP or suggesting that the project will be a failure is not useful. Not everyone approaches technical topics in a straight line or can look back on a systematic education, and provided OP is not doing this for money nothing is wrong with trying stuff out until a brick wall is hit (which OP has done obviously). \$\endgroup\$
    – AnoE
    Jan 25 at 10:14
  • 3
    \$\begingroup\$ @AnoE I don't really see a problem with the processor itself. The first one I used was similar. It's more that the OP started using it without looking at materials to allow them to judge whether or not they could use it. \$\endgroup\$
    – DKNguyen
    Jan 25 at 14:16
19
\$\begingroup\$

Designing a board from scratch like this, with a CPU you haven't used before, can be difficult, and probably won't work.

When working with a new CPU, the safest approach is to get hold of an off-the-shelf board with that CPU and a USB-based programming interface; most manufacturers provide low-cost evaluation boards for their CPUs, together with all the necessary software tools for programming and debugging.

Once you have got that working, you can design your own board by copying the parts of the evaluation board circuitry, or simply incorporate the evaluation board in your design, and just add on the peripherals you want.

\$\endgroup\$
11
  • 4
    \$\begingroup\$ +1. That's how I do it. Sometimes, the redesign winds up in orbit. And one time, when I couldn't get a usable evaluation board, I also couldn't get the processor to work in my system, and couldn't figure out why. \$\endgroup\$
    – John Doty
    Jan 24 at 14:20
  • \$\begingroup\$ Do you have any mpu that you would recommend? I’m looking for something very cheap \$\endgroup\$
    – Jeremys556
    Jan 24 at 14:52
  • 1
    \$\begingroup\$ @Jeremys556 Expense will be determined by the programmer and IDE/compiler cost since you are only working with a few processors. Cost per processor is nearly irrelevant here, even if it's a $50USD processor. \$\endgroup\$
    – DKNguyen
    Jan 24 at 14:55
  • 1
    \$\begingroup\$ Specific product recommendations are discouraged on this site, since they become obsolete very quickly, but ARM-based STM32 devices are very popular with professionals and hobbyists alike, and you can get a simple evaluation board for around $10; it can be in Dual-In-Line format, to be plugged into a breadboard, for simplicity in adding your own peripherals. \$\endgroup\$
    – jayben
    Jan 24 at 15:10
  • 1
    \$\begingroup\$ @Lundin Well, although I kinda feel dirty for mentioning this and I certainly wouldn't recommend it for any design going to end up in a product of any sort, there's a staggering variety of STM32 "clones" or "fakes" on the market (the former are typically called XYZ32 for various three-letter combinations XYZ, the latter are just suspiciously cheap "STM32" parts bought from all sorts of online marketplaces). They typically differ from the real deal in subtle and hard-to-debug ways, but should be capable enough of making a LED blink. \$\endgroup\$
    – TooTea
    Jan 24 at 17:38
5
\$\begingroup\$

I would recommend an 8-bit microcontroller

If you are trying to develop a complete microcontroller solution from scratch, I would recommend looking at some 8-bit microcontrollers like the PIC 8-bit series from Microchip or an AVR8 from the former Atmel, now owned by Microchip, line. An ATTiny85 can give you some basic I/O to play with and not require any external components beyond a single-rail power supply. I would certainly recommend staying away from any microcontroller that requires multiple power rails to begin with. You will still need some kind of external programmer for this project, but they can be found cheap enough for these chips.

The ATTiny85 can be powered directly from a 3V CR2032 battery. It also comes in a 8-pin DIP package that is easy to breadboard out for simple circuits. If you want to hook up a button or an LED to it, you just need an extra resistor as the only other component and you may not even need that for the button case. You can also find various cheap evaluation boards that include a programmer circuit with these microcontrollers and then you just need a USB cable to connect it to the computer. That cable can also provide power. Here's a simple circuit with a button and LED:

ATTiny85 schematic with button and LED

The full project for it goes over the details.

\$\endgroup\$
6
  • 2
    \$\begingroup\$ The code in that example hurts my eyes! \$\endgroup\$
    – Peter M
    Jan 25 at 14:27
  • 1
    \$\begingroup\$ Note that such a chip is way too weak to work like an N64 and in fact even weaker than a Game Boy. Which is not to say you can't make some games anyway. Certainly the ATTiny and ATMega chips are very popular with electronics hobbyists. \$\endgroup\$
    – user253751
    Jan 25 at 16:40
  • 1
    \$\begingroup\$ @spamove Good eye! Yes, I've corrected it. It's a 2x4 or 8-pin package. \$\endgroup\$
    – penguin359
    Jan 26 at 1:28
  • \$\begingroup\$ @user253751 He said his goal is to write machine code to blink an LED. Also, based on what I see for his current skill level, I think even a GameBoy is a bit beyond this current project for now. \$\endgroup\$
    – penguin359
    Jan 26 at 12:43
  • \$\begingroup\$ @penguin359 Yikes... no indentation? I feel you bro. Last time I've seen code like that was from a biochemist who did not believe in "software engineering". He treats source code the way we treat compiled binary - only useful for the machine to run his programs. His real "source code" are actually formulas and notes written on paper compiled on a bunch of (at that point very valuable) notebooks. We actually "backup" his work by periodically photocopying his notebooks. I had to insist on having a small team of devs do the coding for him. \$\endgroup\$
    – slebetman
    Jan 26 at 12:54
1
\$\begingroup\$

Intel 8080 I am more aware of supported direct memory access (DMA), yielding the data, address and control (read/write) buses to external device that could program the memory and then pass the programmed RAM back to CPU.

In these days there are computers like Raspberry PI that have GPIO connector with a number of digital outputs. It may be possible to use the Raspberry as a programming device that outputs data, address and all control signals required to implement DMA. These GPIO pins can even be switched between input and output, and switching address pins into input when not in DMA mode would allow CPU to work.

\$\endgroup\$
3
  • \$\begingroup\$ You could also make an EPROM emulator - a device that acts like a ROM chip - from that kind of computer (probably best done with an arduino or Pi Pico, a full Pi is not so good at hard realtime...) \$\endgroup\$ Jan 25 at 15:59
  • \$\begingroup\$ The execution speed is probably not so important but if Pi cannot handle the role of the memory chip real time you may need to implement the waiting logic (used to be available in these old CPUs). \$\endgroup\$
    – h22
    Jan 25 at 16:03
  • \$\begingroup\$ Overtaxing it could have weird side effects ... software for 8 bit CPUs tended to be VERY dependent on exact timings :) \$\endgroup\$ Jan 25 at 16:08
0
\$\begingroup\$

For older style CPUs and Microcontrollers:

Check if someone already wrote a program called a "monitor" or "ROM monitor" for the CPU type you are working with. Program this into the CPU (by ICSP with a modern microcontroller, by putting it into an EPROM or NOR FLASH with "full" CPUs and old school MCUs. Add basic serial capabilities (a UART if there is none in the processor, and level converters and/or USB converters if needed). Also add some RAM (static is easiest) if there is none in the CPU/MCU (or the CPU is harvard architecture and cannot modify its own internal program RAM easily). Read the documentation for the monitor program regarding how to configure it for the hardware setup you have. This will act as a very basic "operating system" which you can interact with using a terminal emulator (eg putty) to upload and run compiled programs.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.