Author Topic: Flash Writing  (Read 5095 times)

0 Members and 1 Guest are viewing this topic.

SirCmpwn

  • Guest
Flash Writing
« on: October 17, 2010, 10:48:25 am »
Hello,
KnightOS's flash writing routines are not working, and I need some help with them.  Here is the code, any help would be appriciated:
Code: [Select]
WriteFlashByte:
    push hl
    push af
    ld bc, ProgramRoutineEnd - ProgramFlashRoutine
    call AllocateExecutableMem ; Allocates executable RAM, accepts BC as size, outputs hl is pointer to free RAM
    ex hl, de
    push de
    ld hl, ProgramFlashRoutine
    ldir
    pop de
    pop af
    pop hl
    ex hl, de
    ld bc, WriteFlashRet
    push bc
    ;di
    ;halt
    jp (hl)
    WriteFlashRet:
    ret
ProgramFlashRoutine:
; a = value, hl = address
; Flash program sequence
; This is being done according to how the datasheet says it should be done.
; The standard interrupt must not trigger during this sequence or the flash chip
; will not get the write command.
; At 6MHz, one clock cycle will be 167ns
; At 15MHz, one clock cycle will be 67ns
    ex hl, de
    push af
    push hl
    di
    ; reset bus (not needed by the books)
    ;ld    a, 0F0h
    ;ld    (4000h), a
    ; First bus cycle---unlock
    ld    a, 0AAh
    ld    (4AAAh), a
    ; Second bus cycle---unlock
    ld    a, 55h
    ld    (4555h), a
    ; Third bus cycle---write command
    ld    a, 0A0h
    ld    (4AAAh), a
    ; Fourth bus cycle---program data
    pop    hl
    pop    af
    ld    (hl), a
; Wait for data to be good
; "During the Embedded Program Algorithm, an attempt to read the devices will
; produce the complement of the data last written to DQ7. Upon completion of the
; Embedded Program Algorithm, an attempt to read the device will produce the
; true data last written to DQ7"
; "DQ5 will indicate if the program or erase time has exceeded the specified
; limits (internal pulse count).  If this occurs, reset the device with command
; sequence."---Fujitsu documentation
programWaitLoop:
    ld    b, a
    ld    a, 0FDh        ; This checks for the CLEAR key.
    out    (1), a        ; If pressed, it aborts.
    in    a, (1)
    cp    0BFh
    jr    z, abortProgram
    xor    (hl)
    bit    7, a
    ld    a, b
    jr    z, programDone
    bit    5, (hl)
    jr    z, programWaitLoop
abortProgram:
    ld    a, 0F0h
    ld    (4000h), a
    ret
programDone:
    ei
    ret
ProgramRoutineEnd:
EDIT: Figured it out, my test data was setting bits x.x
« Last Edit: October 17, 2010, 11:44:45 am by SirCmpwn »

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Flash Writing
« Reply #1 on: October 17, 2010, 12:08:35 pm »
Nice to see you got it working :)
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

SirCmpwn

  • Guest
Re: Flash Writing
« Reply #2 on: October 17, 2010, 12:10:09 pm »
Thanks.  Now I need to erase sectors and make the filesystem KFS compliant and the kernel will be done :)

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Flash Writing
« Reply #3 on: October 17, 2010, 12:11:39 pm »
Good luck! I'm going to have to deal with this stuff at some point with the new TI-Boy (really looking forward to it, yarrr :P)
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

SirCmpwn

  • Guest
Re: Flash Writing
« Reply #4 on: October 17, 2010, 12:12:13 pm »
Fun stuff :P

Offline matthias1992

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 408
  • Rating: +33/-5
    • View Profile
Re: Flash Writing
« Reply #5 on: October 17, 2010, 01:51:01 pm »
Thanks.  Now I need to erase sectors and make the filesystem KFS compliant and the kernel will be done :)
Nice to see the 'Kernelstage' near completion! I hope you will release some info about the kernel once it is done?
MASM xxxxxxxxxx aborted | SADce ====:::::: 40% -Halted until further notice| XAOS =====::::: 50% -Units done| SKYBOX2D engine ========== 100% -Pre-alpha done. Need to  document it and extend |

~Those who dream by day are cognizant of much more than those who dream by night only. -Sir Edgar Allen Poe-

SirCmpwn

  • Guest
Re: Flash Writing
« Reply #6 on: October 17, 2010, 01:53:39 pm »
I'll release the whole damn thing when its done :)

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55942
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Flash Writing
« Reply #7 on: October 17, 2010, 02:59:45 pm »
Nice, some code to steal... er I mean glad you got it figured out. I remember some flash unlocking discussion before at http://ourl.ca/3587 and http://ourl.ca/4818 but I haven't checked the topics in a long while
Now active at https://discord.gg/cuZcfcF (CodeWalrus server)

SirCmpwn

  • Guest
Re: Flash Writing
« Reply #8 on: October 17, 2010, 03:19:50 pm »
Ah, flash unlocking is easy, this is actual raw flash control.  This code writes to flash.

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: Flash Writing
« Reply #9 on: October 17, 2010, 04:12:04 pm »
DJ, actually, when you write your own OS, you don't even have to do any hacks to unlock flash. You are the OS, you are TI, you can do whatever you want. As long as the code is on page $7D, just a few commands and flash is unlocked.
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55942
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Flash Writing
« Reply #10 on: October 18, 2010, 02:29:00 am »
Oh nice :D
Now active at https://discord.gg/cuZcfcF (CodeWalrus server)