Using SysOverride

Example for fixing EEPROM driver issue in Tiny212 and Tiny412

Merlin
Administrator
Avatar
Gender:
Age: 24
Posts: 1402
Registered: 03 / 2005
Subject:

Using SysOverride

 · 
Posted: 15.11.2024 - 13:39  ·  #1
This is meant to be a tutorial in using SysOverride.

As a background, the EEPROM driver in Tiny212 and Tiny412 devices does not work properly. This unit uses the new SysOverride feature of the latest compiler version to fix the issue by replacing the faulty driver elements with correct versions.

Notice that the latest compiler version must be used and the project must be optimised. (But using AVRco without the optimiser on these devices is pretty much impossible anyway).

In the main program just add TINY_EEPROM to your uses list an make sure TINY_EEPROM is in your uses list.

Code
Unit TINY_EEPROM;
interface

uses;

const
type
var

implementation
type
const
{$IDATA}
var


procedure _CompleteEEWrite;
begin
  asm;
    ;LDS _ACCBLO, 1000h    ; NVMCTRLA
    ;CPI _ACCBLO, 013h     ; are we already in Erase and write mode?
    ;BREQ _PrepEEWriteExit ; yes - just write

    CALL     SYSTEM._EEpWaitReady
    LDI       _ACCBHI, 000h     ; CCP allow NVMCTRA to be changed
    LDI       _ACCBLO, 09Dh
    OUT       034h, _ACCBLO
    STS       1000h, _ACCBHI    ; NVMCTRLA

    CALL     SYSTEM._EEpWaitReady
    LDI       _ACCBHI, 03h     ;EEBRWR EEPROM Erase and Write Enable
    OUT       034h, _ACCBLO
    STS       1000h, _ACCBHI    ; NVMCTRLA
_PrepEEWriteExit:
  endasm;

end;

SysOverride WriteEEp8;
begin
  // pointer in Z
  // value in _ACCA
  asm;
    CALL     SYSTEM._EEpWaitReady
    ST        Z, _ACCA
    CALL      TINY_EEPROM._CompleteEEWrite
    RET
  endasm;
end;

SysOverride _WriteEEp16;
begin
  // pointer in Z
  // value in _ACCB, _ACCA and also in _ACCCALO and _ACCCAHI, for some reason
  asm;
    CALL     SYSTEM._EEpWaitReady
    ST        Z+, _ACCALO
    CALL      TINY_EEPROM._CompleteEEWrite
    ST        Z+, _ACCAHI
    CALL      TINY_EEPROM._CompleteEEWrite
    RET
  endasm;
end;

SysOverride _WriteEEp24;
begin
  // pointer in Z
  // value in _ACCB, _ACCA, _ACCCALO
  asm;
    CALL     SYSTEM._EEpWaitReady
    ST        Z+, _ACCB
    CALL      TINY_EEPROM._CompleteEEWrite
    ST        Z+, _ACCA
    CALL      TINY_EEPROM._CompleteEEWrite
    ST        Z+, _ACCALO
    CALL      TINY_EEPROM._CompleteEEWrite
    RET
  endasm;
end;

SysOverride _WriteEEp32;
begin
  // pointer in Z
  // value in _ACCB, _ACCA, _ACCCALO, _ACCCAHI  _ACCA and _ACCB are copies to _ACCBHI and _ACCBLO
  asm;
    CALL     SYSTEM._EEpWaitReady
    ST        Z+, _ACCB
    CALL      TINY_EEPROM._CompleteEEWrite
    ST        Z+, _ACCA
    CALL      TINY_EEPROM._CompleteEEWrite
    ST        Z+, _ACCALO
    CALL      TINY_EEPROM._CompleteEEWrite
    ST        Z+, _ACCAHI
    CALL      TINY_EEPROM._CompleteEEWrite
    RET
  endasm;
end;

SysOverride _WriteEEp64;
begin
  // pointer in Z
  // value in _ACCB, _ACCA, _ACCCALO, _ACCCAHI, _ACCCDLO, _ACCDHI, _ACCCELO, _ACCCEHI  _ACCA and _ACCB are copies to _ACCBHI and _ACCBLO
  asm;
    CALL     SYSTEM._EEpWaitReady
    ST        Z+, _ACCB
    CALL      TINY_EEPROM._CompleteEEWrite
    ST        Z+, _ACCA
    CALL      TINY_EEPROM._CompleteEEWrite
    ST        Z+, _ACCALO
    CALL      TINY_EEPROM._CompleteEEWrite
    ST        Z+, _ACCAHI
    CALL      TINY_EEPROM._CompleteEEWrite
    ST        Z+, _ACCDLO
    CALL      TINY_EEPROM._CompleteEEWrite
    ST        Z+, _ACCDHI
    CALL      TINY_EEPROM._CompleteEEWrite
    ST        Z+, _ACCELO
    CALL      TINY_EEPROM._CompleteEEWrite
    ST        Z+, _ACCEHI
    CALL      TINY_EEPROM._CompleteEEWrite
    RET
  endasm;
end;



initialization
end TINY_EEPROM.



just 'USE TINY_EEPROM' the unit to fix, certainly the word issue. I don't claim that it is the complete answer.

Remember, this is a community project now. I will do what I can but you must do your part too.

Denken Sie daran, dass es sich hier um ein Gemeinschaftsprojekt handelt. Ich werde tun, was ich kann, aber Sie müssen auch Ihren Teil dazu beitragen.

Regards


If you want to share your own drivers with the community please do so here.

Regards
Harry
Moderator
Avatar
Gender:
Location: zwischen Augsburg und Ulm
Age: 59
Posts: 2132
Registered: 03 / 2003
Subject:

Re: Using SysOverride

 · 
Posted: 16.11.2024 - 09:22  ·  #2
Hello Merlin,

why can't you fix the error directly in the compiler instead of building a solution around it?

Regards
Harry
Merlin
Administrator
Avatar
Gender:
Age: 24
Posts: 1402
Registered: 03 / 2005
Subject:

Re: Using SysOverride

 · 
Posted: 16.11.2024 - 09:48  ·  #3
1. This is meant as a simple tutorial for a more general approach that can be used in multiple other situations.

2. It is only for two specific devices that I happen to have read the data sheets for.

3. There is no guarantee that it works. I have no means of testing it.

4. You are a hardware engineer. Why don't you test it for all the Tinys, let me know what it works for and I will implement it.

As I have offered before.

Regards
Selected quotes for multi-quoting:   0

Registered users in this topic

Currently no registered users in this section

The statistic shows who was online during the last 5 minutes. Updated every 90 seconds.
MySQL Queries: 15 · Cache Hits: 13   64   77 · Page-Gen-Time: 0.024954s · Memory Usage: 2 MB · GZIP: on · Viewport: SMXL-HiDPI