Arduino And Eforth


Download Arduino And Eforth PDF/ePub or read online books in Mobi eBooks. Click Download or Read Online button to get Arduino And Eforth book now. This website allows unlimited access to, at the time of writing, more than 1.5 million titles, including hundreds of thousands of titles in various foreign languages.

Download

Arduino and EForth


Arduino and EForth

Author: Chen-Hanson Ting

language: en

Publisher: Independently Published

Release Date: 2018-11-08


DOWNLOAD





All these years, I have been looking for microcontroller platforms on which I can teach people how to program in the FORTH language. I designed a training course I called Firmware Engineering Workshop. I could train an open minded engineer to program in FORTH in about a week, with a reasonable capable platform, i.e., a microcontroller evaluation board with a FORTH operating system loaded. Good platforms are expansive, and low-cost platforms are inadequate. What I did was to grab any microcontroller board at hand and used it. It did not work well because what I taught could not be easily replicated by people at home. People got frustrated when they could not reproduce results I demonstrated. Then, I found the Arduino Uno Board. The microcontroller evaluation board I need must have a microcontroller with reasonable capabilities. An 8-bit microcontroller with a fast clock is adequate. 16-bit of 32-bit microcontrollers are of course much better. The board must have at least 8 KB of ROM memory and 1 KB of RAM memory. It must also have a USART port to communicate with a terminal emulator on a host PC. Any other I/O devices will be icings on the cake. The more the better. Arduino Uno has all of the components I listed above. It is also inexpensive, costing only $29. It uses ATmega328P, a very interesting microcontroller which has 32 KB of flash memory, enough to host a FORTH operating system, 2 KB of RAM and many I/O devices to build substantial applications. Arduino Uno also has a USB port which connects to a PC and an USART device in ATmega328P. This serial interface is necessary for a FORTH system so that you can run and program ATmega328P interactively from a terminal emulator on the PC - as the complete Forth is on the chip. Arduino Uno is a lovely machine. You connect it through a USB cable to your PC, and you can program it to do many interesting things. Its microcontroller ATmega328P, running at 16 MHz, is very capable of running many interesting applications. The template of a sketch, which is the software in Arduino 0022, captures the essence of firmware programming in casting user applications in two statements: setup() and loop(). It eliminates all the syntactic statements required by a normal C program and exposes to you only the core of an application. However, Arduino software insulates you from the intricate nature of ATmega328P microcontroller, its instruction set, and its I/O devices. Instead, you are given a library of useful routines which are used to build applications. The insulation initially helps you to program the microcontroller in a C-like high level programming language. However, being an 8 bit microcontroller, ATmega328P in C language will run out of gas when application demands performance. At this point, you will have to get down to the bare metal to push ATmega328P to its limit. Then, you have to learn its instruction set and all its I/O devices, and perhaps program it in assembly language. The best alternative approach is to program ATmega328P in the FORTH language. FORTH exposes ATmega328P to you. You can interactively examine its RAM memory, its flash memory, and all the I/O devices surrounding the CPU. You can incrementally add small pieces of code, and test them exhaustively. An interactive programming and debugging environment greatly accelerates program development, and ensures the quality of the program. Since 1990, I have been promoting a simple FORTH language model called eForth. This model consists of a kernel of 30 primitive FORTH commands which have to be implemented in machine instructions of a host microcontroller, and 190 compound FORTH commands constructed from the primitive commands and other compound commands. By isolating machine dependent commands from machine independent commands, the eForth model can be easily ported to many different microcontrollers. This model is ported to ATmega328P, and the result is the 328eForth system.

EForth as Arduino Sketch


EForth as Arduino Sketch

Author: Chen-Hanson Ting

language: en

Publisher:

Release Date: 2020-05-14


DOWNLOAD





eForth as an Arduino Sketch Last year I decided to retire from electronics and microcontrollers. So I cleaned out my study and my garage, gave away all my tools and spare parts. I realized that I should not be a hardware engineer. I am only a programmer, and should just work on software. Then, when I visited my brother in Denver last summer, I saw that my niece was working on a couple of Arduino Boards. On an Arduino board, there was a microcontroller in a DIP socket! That was very interesting. When I came back, I bought a couple of Arduino Uno Boards, and have been working on them since. I had to buy back tools and many electronic parts and ate my vow to stay away from hardware. Arduino Uno is a lovely, small, cheap, and readily accessible microcontroller board. The operating system and the programming environment Arduino 0022 is a good match to the Arduino Uno Board. Through a single USB cable, you can upload programs from a PC to Arduino Uno, and then communicate with the Uno through the same cable using RS232 protocol. You write programs in C language as sketches in Arduino 0022, and the sketches are compiled and then uploaded to the ATmega328P microcontroller on Arduino Uno for execution. Sketches are C programs greatly simplified to the point that you just have to fill lines of code in the two following routines: setup() loop() All intricacies and complications in the C language and its associated compiler and linker are taken care of by the Arduino 0022 system. No wonder Arduino is such a huge success. FORTH is a programming language much better suited for microcontrollers than C. FORTH is really a programming language with a built-in operating system. It has an interpreter and a compiler so that you can write programs in small modules and interactively test and debug them. You can build large applications quickly and debug them thoroughly. FORTH also gives you access to all the hardware components in the microcontroller and all of the IO devices connected to the microcontroller. So, I ported a very simple FORTH model, 328eForth, over to the ATmega328P microcontroller. It was written in AVR assembly language, and had to be assembled in the AVR Studio 4 IDE from Atmel Corp, and then uploaded to ATmega328P through a separated AVRISP mkll programming cable. Once 328eForth is uploaded to ATmega328P, it can communicate with the PC through the Arduino USB cable. BUT, 328eForth cannot be uploaded through the USB cable, because Arduino 0022 requires a bootloader pre-loaded in the ATmega328P to upload sketches, and 328eForth must use the bootloader section of flash memory in ATmega328P to store commands which writes new code into the application section of the flash memory at run-time. For the serious FORTH programmer, a 328eForth system gives you the ultimate control over the ATmega328P microcontroller. For the much larger Arduino user community, we need a FORTH implementation which is compatible with the Arduino 0022 system. Here is my solution: ceForth_328. It is written in C as a sketch. It can be compiled and uploaded by Arduino 0022. Once it is uploaded to the Atmega328P microcontroller, it communicates with the PC through the Arduino USB cable. However, new FORTH commands are compiled only into the RAM memory in ATmega328P. You have only about 1.5 KB of RAM memory to store new commands, and when you turn off Arduino Uno, these new commands are lost. In spite of these limitations, ceForth_328 is still a very useful system. You can learn FORTH and use if to evaluate Arduino Uno for various applications. You can also use it to learn about the ATmega328P microcontroller, because it allows you to read and to write all the IO registers. Find the sketch and soon more at https: //wiki.forth-ev.de/doku.php/projects:430eforth: start#arduino_uno_und_arduino_nano

Irreducible Complexity


Irreducible Complexity

Author: Chen-Hanson Ting

language: en

Publisher: Independently Published

Release Date: 2019-05


DOWNLOAD





eForth - Contents - 1.1 Moore's Law Marches On Moore's Law marches on, and more and more circuits are crowded into microcontrollers. In the last 15 years, I had programmed many ARM chips, and had watched with amazement the progress of the ARM chips. My approach had always been to port an eForth system onto the chips and tried to make the best use of the chips. Here are some of the ARM chips I put eForth on. 2001: Nintendo's GameBoyAdvance had an ARM7TDMI chip in it. It had 32 KB of RAM. No flash. It had lots of external flash and RAM for games. 2004: ADuC7024 from Analog Devices had 62 KB of flash and 8 KB of RAM, and lots of IO devices, including ADC and DAC. I built a ForthStamp based on it, a really nice single chip stamp size computer. 2008: AT91SAM7x256 from Atmel. It had 64 KB of flash and 16 KB of RAM, and lots of IO devices. A couple of years ago, I told my friends in the Silicon Valley FIG and Taiwan FIG that I had to really retire from Forth programming. I did, and worked peacefully on translating Bach's cantatas from German to Chinese, and putting Tang poems into Schubert's songs, and many other things I had neglected all the years. Then, last month, a friend in Taiwan FIG sent me this ForthDuino Board, which was used to control a laser cutting machine to make PC boards. It had footprints of IO sockets of Arduino board and MSP430 LaunchPad. It is intended to suck in all applications from Arduino and LaunchPad. I was told that the ARM chip on ForthDuino is the same one used in the STM32F4Discovery Kit. Looking up the STM32F407 chip, I was shocked to see so much memory, and so many IO devices. 1 MB of flash and 192 KB of RAM. It is a Wow chip, and in desperate need of a good eForth system. So. I re-open my workbench, unpacked my tools, download all necessary IDE and programming toolchains. But, the world has changed since I stopped watching. Keil is still there, but its toolchain became uVision5. STM32F4 is no longer an ARM chip. It is a Cortex M4 chip. There is no ARM in STM32F4. All that's left is a THUMB, and a really big THUMB. The first shock was that I could not use the ARM directive in the assembler. The assembler generated lots of error messages if you do ARM. It is much happier if you use the THUMB directive. Then, the RSC instruction disappeared. Reading the ARM assembler manual carefully, I found that ARM.Holdings is phasing out the ARM instruction set, and replacing it with the THUMB2 instruction set. It gave up the beautiful RISC architecture, and reverted to the ugly CISC architecture we all despised. I missed the simple serial COM port in PC. The USB is so much harder to deal with. You don't know what's going on. You must have faith on the USB drivers given to you. There is no simple example to guide me, to start my exploration. The Demo project provided with STAM32F4-Discovery Kit is a huge package with 7 folders and 31 files. There is no clear entry point. I spent 3 weeks wandering around in the hardware and software maze, looking for an entry point. The great breakthrough came when I realized that I only had to set up the reset vector correctly, everything would work smoothly from that point on. Throw away all the header files, init files, device driver files. I only need one assembly file to do what I have to do. Since STM32F4 is no longer an ARM7 chip. It is not necessary to keep the name in my eForth implementations. I planned and completed 3 versions of eForth for this chip: STM32eforth v7.01 The eForth dictionary resides in flash memory, and executes from flash memory. It is upgraded to align with the eForth2 model, with subroutine tread model and fully optimized for performance. STM32eforth v7.10 The eForth dictionary resides in flash memory. Flash memory is remapped to the virtual memory in Page 0. eForth executes from Page 0 memory.