.. index:: common programs, programs, see, dump calltrace,exception,exception handling,debugging,hardfaults .. _common-programs: Common Programs =============== Describes programs supplied with every Mecrisp-Stellaris Release. These are located in "mecrisp-stellaris-X.X.X/common". This page is a work in progress .... All the programs below are loaded the usual way via a :ref:`serial terminal` assembler-m0.txt ---------------- bitlog.txt ---------- blocks.txt ---------- calltrace.txt ------------- charcomma.txt ------------- conditional.txt --------------- disassembler-m0.txt ------------------- Disassembles Cortex M0 Words into Assembly Language. Useful for optimising your Words etc. Calling Word(s) ^^^^^^^^^^^^^^^ * see :: : three-plus 3 + ; ok. 3 three-plus . 6 ok. see three-plus 20000342: B500 push { lr } 20000344: 3603 adds r6 #3 20000346: BD00 pop { pc } ok. disassembler-m3.txt ------------------- Same as disassembler-m0.txt but for the Cortex M3 dump.txt -------- Reads (dumps) bytes or regions of memory. Calling Word(s) ^^^^^^^^^^^^^^^ * dump16 ( address -- dump 16 bytes of memory ) * dump ( address range -- dump memory ) :: 0 dump16 00000000 : 30 03 00 20 49 37 00 00 D9 35 00 00 D9 35 00 00 | 0.. I7.. .5...5.. | 0 $30 dump 00000000 : 30 03 00 20 49 37 00 00 D9 35 00 00 D9 35 00 00 | 0.. I7.. .5...5.. | 00000010 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ........ ........ | 00000020 : 00 00 00 00 00 00 00 00 00 00 00 00 03 36 00 00 | ........ .....6.. | 00000030 : 00 00 00 00 00 00 00 00 03 36 00 00 B7 35 00 00 | ........ .6...5.. | $30 $50 dump 00000030 : 00 00 00 00 00 00 00 00 03 36 00 00 B7 35 00 00 | ........ .6...5.. | 00000040 : 03 36 00 00 03 36 00 00 03 36 00 00 03 36 00 00 | .6...6.. .6...6.. | 00000050 : 03 36 00 00 27 36 00 00 4B 36 00 00 71 36 00 00 | .6..'6.. K6..q6.. | 00000060 : 03 36 00 00 03 36 00 00 03 36 00 00 03 36 00 00 | .6...6.. .6...6.. | 00000070 : 93 36 00 00 B7 36 00 00 DB 36 00 00 FD 36 00 00 | .6...6.. .6...6.. | 00000080 : 21 37 00 00 03 36 00 00 03 36 00 00 03 36 00 00 | !7...6.. .6...6.. | editor.txt ---------- examples.txt ------------ experimental/ ------------- floored-divide.txt ------------------ fonts/ ------ .. _flash-notes: Flash ----- Error Message ^^^^^^^^^^^^^ Wrong address or data for writing flash ! Originates from ? ^^^^^^^^^^^^^^^^^ flash.s in your MCU source directory Causes ^^^^^^ 1. Are you trying to write into the area reserved for the dictionary because that is not allowed and will print that error. The Forth core address range is set :ref:`here` 2. Is the address even ? it must be divisible by 2. 3. Does the data at the Flash memory address contain all $FFFFFFFF which is the erased state. If a location has already been written to then the flash controller will raise this error. To write new data into a previously written flash location, the whole sector must be erased first. .. note:: Flash sector(s) at the end of the flash area can be set aside from the reserved Mecrisp-Stellaris dictionary area with some core mods. This will provide a scratch pad area you can write to outside of Mecrisp-Stellaris at the expense of reduced dictionary space. For instance the F407 has 128KB available at sector 11, or the F103 (bluepill) has 2K in its last sector. graphics-unicode-8x16.txt ------------------------- graphics-unicode-8x8.txt ------------------------ graphics.txt ------------ longcomment.txt --------------- mecrisp-registergenerator/ -------------------------- multitask.txt ------------- nvic.txt -------- profiler.txt ------------ prompt.txt ---------- pseudorandom.txt ---------------- quotations.txt -------------- registergenerator/ ------------------ romans.txt ---------- sine.txt -------- sqrt.txt -------- svd2forth-v2/ ------------- .. index:: Unhandled Interrupt 00000003 !,dump calltrace,exception,exception handling .. _exceptions: Exceptions ---------- .. note:: This EXCEPTION article was written using a ST32F103C8 MCU (Cortex-M3) for the examples and testing. * An EXCEPTION is defined in the ARM specification as "a condition that changes the normal flow of control in a program" * An EXCEPTION is similar to a INTERRUPT. * Cortex-M has many EXCEPTIONS and they generally occur when something bad happened, such as reading a memory location that doesn't exist. * The registers that deal with EXCEPTIONS reside in the ARM "Core Peripherals" System control block (SCB) peripheral and common across all Cortex-M models. * SCB_ICSR @ $E000ED04 the "Interrupt control and state register" is relevant here. * For STM32F103 see ST Micro Document PM0056, page 129/156 .. image:: pics/cortex-m-exceptions.jpg .. _debugging: Debugging ^^^^^^^^^ The Word "Calltrace.txt" attempts to list the cause of the EXCEPTION and also prevents the dreaded "Unhandled Interrupt 00000003 !" message printing endlessly until the MCU is reset. Requires ~~~~~~~~ mecrisp-stellaris-x.x.x/common/calltrace.txt from your Mecrisp-Stellaris release tarball. .. warning:: calltrace.txt searches for the closest dictionary entry points to the addresses on the return stack and may give random results for values that aren't return addresses. It is assumed that the programmer can decide from context which ones are correct. Implementation ~~~~~~~~~~~~~~ The "irq-fault" INTERRUPT must be configured to call the Word "ct-irq" in your program. When a EXCEPTION occurs, this attempts to show the cause. :: ' ct-irq irq-fault ! Example; Terminal Entry ~~~~~~~~~~~~~~~~~~~~~~~ This EXCEPTION was contrived by attempting to read non-existent memory at the Terminal. This is a very common occurrence during development. :: $100000 @ . Result ~~~~~~ :: Unhandled Interrupt 00000003 ! [1 ] 0000006E 00100000 Calltrace: 00000000 0000C0DD calltrace-handler 00000001 FFFFFFF9 00000002 00001824 @ 00000003 00000220 --- MS RA 2.5.1 tpmod --- 00000004 00001824 @ 00000005 00000020 00000006 FEFBAFF7 00000007 00004683 interpret 00000008 00001824 @ 00000009 01000000 init.calltrace 0000000A 0000BF2D redstack.prompt 0000000B 000046DD quit .. note:: The MCU is HALTED at this point and will require a RESET as most EXCEPTIONS are not recoverable. Description ~~~~~~~~~~~ 1. The "HardFault" EXCEPTION #3 was raised 2. The stack contents are dumped, note the "00100000" which I had entered before the EXCEPTION was raised. 3. Calltrace was run (from the previously loaded "calltrace.txt") 4. Some additional irrelevant information was also printed as per the warning above. Customisation ~~~~~~~~~~~~~ A printout of the SCB_ICSR (at $E000ED04) register has been added to calltrace.txt for additional information. .. image:: pics/f103-scb_icsr.jpg :: 1000000 @ . Unhandled Interrupt 00000003 ! [1 ] 0000006E 000F4240 Calltrace: SCB_ICSR:$0400F803 3322222222221111111111 10987654321098765432109876543210 00000100000000001111100000000011 00000000 0000A73D calltrace-handler 00000001 FFFFFFF9 00000002 00001824 @ 00000003 00000220 --- MS RA 2.5.1 tpmod --- 00000004 00001824 @ 00000005 00000020 00000006 FEFBAFF7 00000007 00004683 interpret 00000008 00001824 @ 00000009 01000000 init.calltrace 0000000A 0000A56D redstack.prompt 0000000B 000046DD quit Example; Program Execution ~~~~~~~~~~~~~~~~~~~~~~~~~~ In this example the Word "cause-exception" is executed. :: : cause-exception ( -- ) 1000000 @ . ; Code ~~~~ :: getid cause-exception getid-STM32F103CB-data getid-GD32F103-data xml Result ~~~~~~ :: Unhandled Interrupt 00000003 ! [0 ] 00000000 Calltrace: SCB_ICSR:$0400F803 3322222222221111111111 10987654321098765432109876543210 00000100000000001111100000000011 00000000 0000A73B calltrace-handler 00000001 FFFFFFF9 00000002 000F4200 init.calltrace 00000003 00000000 00000004 20000DDE cause-exception 00000005 00000000 00000006 FEFBAFF7 00000007 00004683 interpret 00000008 20000DE6 cause-exception 00000009 01000000 init.calltrace 0000000A 0000A56D redstack.prompt 0000000B 000046DD quit Description ~~~~~~~~~~~ 1. The "HardFault" EXCEPTION #3 was raised 2. The stack contents are dumped, note the listing of the cause "cause-exception" after "calltrace-handler" is triggered making the reason for the EXCEPTION easy to find. 3. Calltrace was run (from the previously loaded "calltrace.txt") 4. Some additional irrelevant information was also printed as per the warning above. .. seealso:: :ref:`Bugs or Benefits?`