Documentation for “Zerocat Chipflasher” as of Wed, 24 Jun 2026 07:28:14 +0200
Repository: git://zerocat.org/zerocat/projects/chipflasher.git
Version: v3.0.0-0-b445ef922
Branch: master

kick2.spin.nointerface.html

{{

______________________________________________________________________________
********************************************************* File starts here ***
Zerocat Chipflasher --- Flash free firmware, kick the Management Engine.

Copyright (C) 2020, 2021, 2022, 2024, 2025, 2026  Kai Mertens 

File kick2.spin --- The top object file for this firmware2 project.

This file is part of Zerocat Chipflasher.

See end of file for terms of use.

******************************************************************************
}}



{{


IMPORTANT NOTICE
================


* On PCBv1 aka board-v1, the SPI CE# line is pulled up via trimmer.

    Adjust a reasonable value, not too small.

* On PCBv2.0 aka board-v2.0, the SPI CE# line is pulled up via R23 and R10.

    These resistors are populated with 91 Ohm each, forming a pull-up
    value of 45.5 Ohm on the first series of devices, shipped in 2024 and
    earlier.

    That is too small!

    (On the chip flasher development board, this pull-up is set to
    47.62 Ohm, which works in test setups with hand-made wiring.)

    As a workaround, cut one end of R10 with a pince and twist the
    resistor aside, carefully. The remaining pull-up value is 91 Ohm
    (the value of R23), which should be a reasonable value for most use
    cases.

    In 2025, the PCB will provide sockets for R23 and R10, such that
    this pull-up can be adjusted. However, the formed resistor value
    must not be smaller than 42 Ohm, otherwise the Propeller pins 0 and
    1 will be damaged.

    These equations apply:

                    1                  1         1
        R_pull  =  ---  ,      x  =  -----  +  -----
                    x                 R23       R10

* On PCBv2.2 aka board-v2.2, the SPI CE# line is pulled up via trimmer,
  which is digitally monitored.

    In 2025, the PCBv2.2 candidate for FSF Respect Your Freedom (RYF)
    certification uses R23 and R10 as an offset for the trimmer, to
    protect Propeller pins even if the trimmer would be adjusted to zero.

    These equations apply:

                               1
        R_pull  =  R_trim  +  ---    ,
                               x

        R_trim  =  0..500 (approx.)  ,

                     1         1
             x  =  -----  +  -----
                    R23       R10

    The value of R_pull is displayed in the menu of `kick2-connect`.
    Upon change, the display should be refreshed by user's key input.

    A value of 91 Ohm is still considered as a reasonable value for
    many use cases, however, some targets require an adjustment.
}}



''
''
''# Included Compiler Configuration
# include "./kick2.spin.cfg"



''
''
''# Object Summary
OBJ     'This directive triggers the compiler to insert a summary.



''
''
''# Loaded Objects
                                                ''
        pcb             : "pcb"                 ''* PCB configuration object
        time            : "time"                ''* time object
        status          : "status"              ''* status object
#   ifdef _CFG_connect
        menu            : "menu"                ''* menu object
#   endif
#   ifdef _CFG_terminal
        menu            : "menu"                ''* menu object
#   endif
#   ifdef _CFG_flashrom
        serprog         : "serprog"             ''* serprog object
#   endif



''
''
''# Included Files



''
''
''# Constants
CON
        ''

        ''* LED Pins
        D1      = 15
        D2      = 14
        D3      = 13


        ''* System Speed
        _XINFREQ            = 5_000_000                         '_XINFREQ  --- External Crystal Frequency of 5MHz
        _CLKMODE            = XTAL1 + PLL16X                    '_CLKMODE  --- Low Speed Crystal x 16    = 80MHz
        '_CLKFREQ is calculated automatically from above settings


        ''* Basic Timing
        CYCL_MIN            = 381


        ''* Project's Memory Usage
        '
        'Reserve memory to avoid application failure during runtime.
        '_STACK and _FREE must sum up to under MAX_TOTAL longs.
        'Set _STACK and/or _FREE to maximum in order to get informative compile error.
        '
        MAX_TOTAL           = 8192                              'MAX_TOTAL
        MAX_STACK           = 4096                              'MAX_STACK
'        _STACK              = MAX_STACK                         'Test _STACK Maximum
'        _FREE               = MAX_TOTAL - MAX_STACK             'Test _FREE Maximum
#   ifdef _CFG_flashrom
        _STACK              = 1024                              '_STACK
        _FREE               = 1024                              '_FREE
#   else
        _STACK              = 150                               '_STACK
        _FREE               = 150                               '_FREE
#   endif



''
''
''# Functions


PUB     kick2 : statuscode | vboard, baudrate, cfg, RST_inhibit

        '' This is the Chipflasher's new firmware, coded in Spin/PASM.

        'get PCB configuration
        vboard := pcb.sample_pcbversion
        pcb.set_pcbversion(vboard)
        cfg := pcb.sample_pcbconfig
        pcb.set_pcbconfig(cfg)

        'init locals
        RST_inhibit := pcb.get_RST_INHIBIT
        baudrate := pcb.get_baudrate

        'init pins
        DIRA[RST_inhibit]~~
        DIRA[D1..D3]~~

        'hello world! (duration: 0.5s .. 3.6s)
        CASE baudrate
            38400:    statuscode := status#CODE_HELLO_38400
            57600:    statuscode := status#CODE_HELLO_57600
            230400:   statuscode := status#CODE_HELLO_230400
            OTHER:    statuscode := status#CODE_HELLO
        REPEAT vboard & $0f
            status.drive_LEDs(statuscode)

        'additional time window for initial resets: 3 seconds
        WAITCNT(CLKFREQ * 3 + CNT)

        'approximately 3.5s .. 6.6s after start: disable RST until we are done
        OUTA[RST_inhibit]~~                                 'disable pin RST
        statuscode := status#CODE_RST
        status.drive_LEDs(statuscode)                       'display status

        'start interface
#   ifdef _CFG_flashrom
        IF pcb.check_cable_SPI
            'start communication: try flashrom utility
            statuscode := serprog.start(vboard, cfg, baudrate)
        ELSE
            statuscode := status#CODE_CABLE
#   endif
#   ifdef _CFG_connect
        IF pcb.check_cable_SPI
            'start communication: try connect utility
            statuscode := menu.start(vboard, cfg, baudrate, menu#MENU_CONNECT)
        ELSE
            statuscode := status#CODE_CABLE
#   endif
#   ifdef _CFG_terminal
        IF pcb.check_cable_SPI
            'start communication: assume propeller terminal
            statuscode := menu.start(vboard, cfg, baudrate, menu#MENU_TERMINAL)
        ELSE
            statuscode := status#CODE_CABLE
#   endif
#   ifndef _CFG_flashrom
#       ifndef _CFG_connect
#           ifndef _CFG_terminal
        statuscode := status#CODE_INTERFACE
#           endif
#       endif
#   endif


        'end of program:
        '  display status at least three times in case RESn is active
        REPEAT 3
            status.drive_LEDs(statuscode)
        OUTA[RST_inhibit]~              'release RST inhibit
        REPEAT
            status.drive_LEDs(statuscode)



{{


******************************************************************************
Terms of Use:

Zerocat Chipflasher is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

Zerocat Chipflasher is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License along
with Zerocat Chipflasher.  If not, see <http://www.gnu.org/licenses/>.

************************************************************** End of File ***
}}