Menu

DMA flash write

Help Me
Susa
2009-06-30
2013-04-29
  • Susa

    Susa - 2009-06-30

    I try to use the dma functions included in NanoStack to write to the integrated flash mempory on an RC2301AT mote. The code compiles, erase works but nothing is written to the flash. Has anyone else used dma for flash write? I know the project is no longer supported but any help would be appreciated. Thank you

    Susa

    /* Standard includes. */
    #include <stdlib.h>
    #include <string.h>
    #include <sys/inttypes.h>

    /* Scheduler includes. */
    #include "FreeRTOS.h"
    #include "task.h"
    #include "queue.h"

    /* NanoStack includes */
    #include "stack.h"
    #include "socket.h"
    #include "debug.h"
    //#include "control_message.h"

    /* Platform includes */
    #include "uart.h"
    #include "rf.h"
    #include "bus.h"
    #include "dma.h"
    #include "timer.h"
    #include "gpio.h"

    #define DATA_AMOUNT 4

    static void vAppTask( int8_t *pvParameters );
    static void verify();

    uint8_t code at 0x1f800 flashwritelocation[4]={0,0,0,0};

    /* Main task, initialize hardware and start the FreeRTOS scheduler */
    int main( void )
    {
        /* Initialize the Nano hardware */
        bus_init();
        stack_init();
        dma_init();
       
        /* Setup the application task and start the scheduler */
        xTaskCreate( vAppTask, "App", configMINIMAL_STACK_SIZE+50, NULL, (tskIDLE_PRIORITY + 1 ), ( xTaskHandle * )NULL );
        vTaskStartScheduler();
       
        /* Scheduler has taken control, next vAppTask starts executing. */

        return 0;
    }

    /**
    * Tryout application task
    */
    static void vAppTask( int8_t *pvParameters )
    {
        uint16_t faddr = (uint16_t) &flashwritelocation;
        //set up some test data
        uint8_t testdata[DATA_AMOUNT]= {  0x44,0x44,0x44, 0x44};
        xDMAHandle channel1;

        channel1 = dma_config(1,&testdata, DMA_INC , &FWDATA , DMA_NOINC , 4 , DMA_VLEN_LEN, DMA_BLOCK , DMA_T_FLASH, &verify);
        //set up flash adress. high byte: 0 = row, 1-6 page low byte: 0-5 location, 6-7 row
        FADDRH =0x7e;
        FADDRL =0x00;
        //FWT must be adjusted if 16 MHz CPU Frequency is used
        FWT = 0x2A;
        // erase page before writng
        FCTL |= 0x01;   
        //arm DMA channel
        dma_arm(channel1);
        //start Flashwrite by setting write bit in Flash Controller
        FCTL |=0x02;

        /* Start an endless task loop, we must sleep most of the time allowing execution of other tasks. */
        for (;;)
        {
            /* Sleep for 1000 ms + Conrol when cycle is finished*/
            LED2_TOGGLE();
            vTaskDelay( 1000 / portTICK_RATE_MS );
           
        }
        //}
    }

    static void verify()
    {
        uint8_t i;
        uint8_t flashData[4] = {0,0,0,0};
        while( FCTL & 0x80 || FCTL & 0x40 ){;}
        flash_read(flashData, 0x1F800,8);
        for (i=0;i<4;i++){
            if (flashData[i] == 0x44){ LED1_ON();}
        }
       
    }

     
    • Niklas Wik

      Niklas Wik - 2009-07-03

      When using the DMA you have to use the complete address of the register FWDATA is defined in SFR as 0xAF, but you should give the complete address as defined in XDATA address space.

      You may also have to do a manual trigger if the transfer does not start when you have armed the channel.

      //Niklas

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.