+ Post New Thread
Results 1 to 7 of 7
  1. #1
    Member level 2
    Points: 987, Level: 7

    Join Date
    Jun 2010
    Location
    Home
    Posts
    50
    Helped
    26 / 26
    Points
    987
    Level
    7

    how replace a function in data & program memory during running my code.(Using MikroC)

    i have 2 function for example d1() and d2().d1() burned in program memory.i want to replace d1() function that d2() take his memory location.but main() remain old one.d2() will use a bootloader to take place the d1(). 1 thing more that in actual programming name of the both functions will same.i have some queries.
    1- did it work i mean main() will call d2() normally.
    2- Did any one do that, during runing the program, write the data/program memory.
    its basically self flash writing kind of thing.Pic 18f have that ability.

    •   AltAdvertisment

        
       

  2. #2
    Super Moderator
    Points: 254,930, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    44,424
    Helped
    13527 / 13527
    Points
    254,930
    Level
    100

    Re: how replace a function in data & program memory during running my code.(Using Mik

    Usually bootloaders are designed to rewrite all of the application flash memory, except for the bootloader area itself. Cautious people are even protecting the bootloader area against unintended overwrite by hardware fuses and provide a safe recovery in case of bootloader failure.

    Rewriting only part of the application is generally possible, but the memory layout has to consider it. The flash self rewrite feature is operating on erase block entities of the respective microprocessor. You have to care, that no other code is sharing the rewritten block of memory. Most PIC compilers have compiler commands for it, e.g. #org statements.


    1 members found this post helpful.

  3. #3
    Advanced Member level 4
    Points: 11,875, Level: 26
    bobcat1's Avatar
    Join Date
    Jul 2002
    Posts
    1,288
    Helped
    99 / 99
    Points
    11,875
    Level
    26

    Re: how replace a function in data & program memory during running my code.(Using Mik

    HI

    You need to use ptr to function (pointer to function ) just load the pointer in real time

    All the best

    Bobi


    1 members found this post helpful.

    •   AltAdvertisment

        
       

  4. #4
    Member level 2
    Points: 987, Level: 7

    Join Date
    Jun 2010
    Location
    Home
    Posts
    50
    Helped
    26 / 26
    Points
    987
    Level
    7

    Re: how replace a function in data & program memory during running my code.(Using Mik

    thx for reply.
    yes FvM i keep in mind this thing.that how and where to place my function in memory.

    Bobi ur idea seem to be interesting.
    Actually i have no more space for my cod in RAM and ROM.i want i save my some of function in External EEPROM and when i need them than i put them in ROM by replacing some any function. did any one try this successfully.????



  5. #5
    Advanced Member level 4
    Points: 11,875, Level: 26
    bobcat1's Avatar
    Join Date
    Jul 2002
    Posts
    1,288
    Helped
    99 / 99
    Points
    11,875
    Level
    26

    Re: how replace a function in data & program memory during running my code.(Using Mik

    Hi

    It is more easy to replace your micro with larger memory one.

    Anyhow - in order to do what you ask you will need to define an array in RAM who can be accessed by a function pointer(rather complicated)
    the function data need to be copy from EEPROM to RAM array prior to execution and accessed by the function Ptr
    the function body should be located in RAM using compiler predefined MACRO "__RAM"

    All the best

    Bobi


    1 members found this post helpful.

    •   AltAdvertisment

        
       

  6. #6
    Super Moderator
    Points: 254,930, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    44,424
    Helped
    13527 / 13527
    Points
    254,930
    Level
    100

    Re: how replace a function in data & program memory during running my code.(Using Mik

    I was assuming in fact, that having both function in flash memory won't be an option. Otherwise, you don't need to think about a bootloader and similar. You should however consider the limited flash endurance. The PIC18 datasheets aren't very exact in this regard, they promise "many thousands of erase/write cycles - up to 100,000".

    function body should be located in RAM using compiler predefined MACRO "__RAM"
    Most PIC processors don't have an option to execute code from RAM, execpt for a few special devices.


    1 members found this post helpful.

  7. #7
    Member level 2
    Points: 987, Level: 7

    Join Date
    Jun 2010
    Location
    Home
    Posts
    50
    Helped
    26 / 26
    Points
    987
    Level
    7

    how replace a function in data & program memory during running my code.(Using Mik

    i cant place the code in RAM or ROM.i just have a defined address in main function and want to call it when i place some code that address. Otherwise this address is used by another function.Idea behind is i want to update a complete function(i take care of the addresses).
    Main purpose is to memory organization.Have any idea to organize the memory of embedded systems .



--[[ ]]--