<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Move a function (not main()) from FLASH to RAM in S12 / MagniV Microcontrollers</title>
    <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Move-a-function-not-main-from-FLASH-to-RAM/m-p/136900#M2474</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;A rather daring solution is to reserve a block of RAM large enough to hold the largest function you want to copy (in my example below, 100 bytes).&lt;BR /&gt;&lt;BR /&gt;Then in the flash, write&lt;BR /&gt;&lt;BR /&gt;void myFunc (void)&lt;BR /&gt;{&lt;BR /&gt;...&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;void myFunc_end (void){}&lt;BR /&gt;&lt;BR /&gt;Here I assume that the two functions will be placed adjacent in the memory. To be certain of it, you could use&lt;BR /&gt;#pragma CODE_SEG MYFUNC_SEG or something just for the two functions.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Then in main():&lt;BR /&gt;&lt;BR /&gt;union myUnion&lt;BR /&gt;{&lt;BR /&gt;char dummySpace[100];&lt;BR /&gt;void (*myGenericFunction)(void);&lt;BR /&gt;};&lt;BR /&gt;&lt;BR /&gt;memcpy(myUnion.dummySpace, (void*)myFunc, (int)(myFunc_end-myFunc));&lt;BR /&gt;&lt;BR /&gt;myUnion.myGenericFunction();&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 29 May 2006 13:54:20 GMT</pubDate>
    <dc:creator>Lundin</dc:creator>
    <dc:date>2006-05-29T13:54:20Z</dc:date>
    <item>
      <title>Move a function (not main()) from FLASH to RAM</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Move-a-function-not-main-from-FLASH-to-RAM/m-p/136898#M2472</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hello world!&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I am rather new to programming microcontrollers, so this may be a trivial thing for you to help me with.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I'm going to erase the Flash on a NE64 (SPI master) and then be able to burn a new program from a DP256B (SPI slave). In order to do this I have to move the SPI function that I have written and place the whole function in RAM. I would really appreciate if I could get any hint. I'm thinking about using the #pragma directive but maybe there are easier ways to solve this problem.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thanks in advance!&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 May 2006 17:59:21 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Move-a-function-not-main-from-FLASH-to-RAM/m-p/136898#M2472</guid>
      <dc:creator>Mr_void</dc:creator>
      <dc:date>2006-05-24T17:59:21Z</dc:date>
    </item>
    <item>
      <title>Re: Move a function (not main()) from FLASH to RAM</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Move-a-function-not-main-from-FLASH-to-RAM/m-p/136899#M2473</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Hi,&lt;BR /&gt;You can make a project that is configured to run entirely from RAM. This project contains your flasher code and has a jump vector that points to its _Startup() routine. Build it and make from the .abs file an 'unsigned char array'. Put the array into your main project and call a little asm code that looks like this:&lt;BR /&gt;&lt;BR /&gt;// Copy flasher code to RAM and invoke it&lt;BR /&gt;asm&lt;BR /&gt;{&lt;BR /&gt;SEI // Interrupts OFF&lt;BR /&gt;LDX #0 // Initialize loop counter&lt;BR /&gt;L1: LDAB flashercode,X // Loop: Get one byte from flasher code&lt;BR /&gt;STAB $2000,X // ...and store into RAM&lt;BR /&gt;INX // Go to next byte&lt;BR /&gt;CPX #$1F00 // 0x1f00 bytes transferred?&lt;BR /&gt;BLT L1 // No, continue&lt;BR /&gt;LDX #0 // Initialize for indirect jump&lt;BR /&gt;JMP [$2000,x] // Invoke flasher code, jump to vector at 0x2000&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;It should be assembly which doesn't need the stack because the stack will surely be overwritten...&lt;BR /&gt;&lt;BR /&gt;With this method you can run big programs (depending only on how much RAM your MCU has). Such as my flasher code, which reads S-records from FAT-formatted compact flash memory cards and re-programs an HCS12XA256...&lt;BR /&gt;&lt;BR /&gt;Hope that helps a little,&lt;BR /&gt;pittbull&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 May 2006 01:24:20 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Move-a-function-not-main-from-FLASH-to-RAM/m-p/136899#M2473</guid>
      <dc:creator>pittbull</dc:creator>
      <dc:date>2006-05-25T01:24:20Z</dc:date>
    </item>
    <item>
      <title>Re: Move a function (not main()) from FLASH to RAM</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Move-a-function-not-main-from-FLASH-to-RAM/m-p/136900#M2474</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;A rather daring solution is to reserve a block of RAM large enough to hold the largest function you want to copy (in my example below, 100 bytes).&lt;BR /&gt;&lt;BR /&gt;Then in the flash, write&lt;BR /&gt;&lt;BR /&gt;void myFunc (void)&lt;BR /&gt;{&lt;BR /&gt;...&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;void myFunc_end (void){}&lt;BR /&gt;&lt;BR /&gt;Here I assume that the two functions will be placed adjacent in the memory. To be certain of it, you could use&lt;BR /&gt;#pragma CODE_SEG MYFUNC_SEG or something just for the two functions.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Then in main():&lt;BR /&gt;&lt;BR /&gt;union myUnion&lt;BR /&gt;{&lt;BR /&gt;char dummySpace[100];&lt;BR /&gt;void (*myGenericFunction)(void);&lt;BR /&gt;};&lt;BR /&gt;&lt;BR /&gt;memcpy(myUnion.dummySpace, (void*)myFunc, (int)(myFunc_end-myFunc));&lt;BR /&gt;&lt;BR /&gt;myUnion.myGenericFunction();&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 May 2006 13:54:20 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Move-a-function-not-main-from-FLASH-to-RAM/m-p/136900#M2474</guid>
      <dc:creator>Lundin</dc:creator>
      <dc:date>2006-05-29T13:54:20Z</dc:date>
    </item>
    <item>
      <title>Re: Move a function (not main()) from FLASH to RAM</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Move-a-function-not-main-from-FLASH-to-RAM/m-p/136901#M2475</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Thank you very much for your replies, it partially solved the problems.&lt;/DIV&gt;&lt;DIV&gt;But as always when programing microcontrollers a new problem is lurking behind the next corner.&lt;IMG alt=":smileymad:" class="emoticon emoticon-smileymad" id="smileymad" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-mad.gif" title="Smiley Mad" /&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Jun 2006 16:53:36 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Move-a-function-not-main-from-FLASH-to-RAM/m-p/136901#M2475</guid>
      <dc:creator>Mr_void</dc:creator>
      <dc:date>2006-06-19T16:53:36Z</dc:date>
    </item>
    <item>
      <title>Re: Move a function (not main()) from FLASH to RAM</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Move-a-function-not-main-from-FLASH-to-RAM/m-p/136902#M2476</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;Are you using CodeWarrior for HC12 V 2.0 or higher as development tool?&lt;/P&gt;&lt;P&gt;If this is the case there is a technical note (TN228) explaining how to achieve that. The Technical note should be available if you have done a full product install.&lt;/P&gt;&lt;P&gt;Anyway I have attached it to that thread for your convenience.&lt;/P&gt;&lt;P&gt;I hope this helps.&lt;/P&gt;&lt;P&gt;CrasyCat&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 Jun 2006 17:41:56 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Move-a-function-not-main-from-FLASH-to-RAM/m-p/136902#M2476</guid>
      <dc:creator>CrasyCat</dc:creator>
      <dc:date>2006-06-22T17:41:56Z</dc:date>
    </item>
  </channel>
</rss>

