This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Flash Programming Interrupt

Other Parts Discussed in Thread: SYSBIOS

Hello,

i am using I am using 123GH6PGE DK , TivaWare_C_Series-1.1 ,CCS 5.4 and tirtos_1_21_00_09

i am trying to program  flash using Tivaware APIs and create sysbios -Managed ISR through that main file but the problem is that while i am trying to run that application the bios always start with the hwi ISR and when it comes to the task it doesn't triggers an interrupt when erasing or writing

 

//---------------------------------------------------------------------------
// Project: Flash Sample1
// Author: AHmed Hassan
// Date: March 2014
//---------------------------------------------------------------------------
/*
* This Sample is to provide safe thread operation
*
*/

//------------------------------------------
// TivaWare Header Files
//------------------------------------------
#include <stdint.h>
#include <stdbool.h>
#include<stdio.h>

#include "driverlib/flash.h"
#include "driverlib/sysctl.h"
#include "driverlib/interrupt.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"

//----------------------------------------
// BIOS header files
//----------------------------------------
#include <xdc/std.h> //mandatory - have to include first, for BIOS types
#include <ti/sysbios/BIOS.h> //mandatory - if you call APIs like BIOS_start()
#include <xdc/runtime/Log.h> //needed for any Log_info() call
#include <xdc/cfg/global.h> //header file for statically defined objects/handles

#include <xdc/std.h>
#include <xdc/runtime/Error.h>
#include <xdc/runtime/System.h>
#include <xdc/runtime/Timestamp.h>
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/hal/Timer.h>
#include <ti/sysbios/hal/Hwi.h>
#include <ti/sysbios/knl/Swi.h>
#include "inc/hw_ints.h"


#define int_ID 45 /*defining Flash Memory Control vector number */
/*Function Prototype */
void Flash_Writing(void);
void Flash_ISR(void);
void Flash_led(void);
void hardware_init(void);

Error_Block eb;

/*create HWI */
Hwi_Handle hwi0;
Hwi_Params hwiParams;

/* Create SWI */
Swi_Handle LEDSwi;
Swi_Params swiParams;

/*Task */
Task_Params taskParams;
Task_Handle myTsk;


void Flash_ISR(void)
{
Hwi_disableInterrupt(int_ID);
Swi_post(LEDSwi); // post LEDSwi

}


void Flash_led(void)
{

GPIOPinWrite(GPIO_PORTG_BASE, GPIO_PIN_2, 0x04);
SysCtlDelay(2000000);
GPIOPinWrite(GPIO_PORTG_BASE, GPIO_PIN_2, 0x00);
}
void hardware_init(void)
{

/* Enable the GPIO PortG Peripheral*/

//
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);

/* Make PIN 2 as Output Pin*/

GPIOPinTypeGPIOOutput(GPIO_PORTG_BASE,GPIO_PIN_2);
GPIOPinWrite(GPIO_PORTG_BASE, GPIO_PIN_2, 0x00);


}
void Flash_Writing(void)
{

uint32_t pui32Data[2];
pui32Data[0] = 0x12345678;
pui32Data[1] = 0x56789abc;
uint32_t ui32User0_Set=0XEEEEEEEE; /*the value to be written to user register 0 */
uint32_t ui32User1_Set=0XDDDDDDDD; /*the value to be written to user register 1 */
int8_t FRESULT; /*To check the success of the programming*/
FRESULT=-1;
uint32_t ui32User0_Get;
uint32_t ui32User1_Get;

/* ERASE A BLOCK AT FLASH*/

FRESULT=FlashErase(0x20000);
if(FRESULT==-1)
{
printf("error erasing");
}


/* Program some data into the newly erased block of the flash*/
FRESULT=FlashProgram(pui32Data,0x20000, sizeof(pui32Data));

if(FRESULT==-1)
{
printf("error programming");
}

/*sets the contents of the user registers (0 and 1)*/

FlashUserSet(ui32User0_Set,ui32User1_Set);


/*reads the contents of user registers (0 and 1), and stores them */

FlashUserGet(&ui32User0_Get,&ui32User1_Get);

}


/*
* main.c
*/
void main()
{

/*HW INtialization*/
hardware_init();


/* Initialize error block and hwiParams to default values */
Error_init(&eb);


Hwi_Params_init(&hwiParams);
hwi0 = Hwi_create(int_ID,Flash_ISR, &hwiParams, &eb);
/* Set Flash_ISR parameters */
// hwiParams.arg = 12;
hwiParams.enableInt = FALSE; /* override default setting: Keep interrupt disabled until later */
// don't allow this interrupt to nest itself
hwiParams.maskSetting = Hwi_MaskingOption_SELF;
if (hwi0 == NULL) {
System_abort("Hwi create failed");
}

/* Initialize swiParams to default values */
Swi_Params_init(&swiParams);
LEDSwi = Swi_create(Flash_led, &swiParams, &eb);
swiParams.priority = 10;
if (LEDSwi == NULL) {
System_abort("Swi create failed");
}

/*Initialize taskParams to default values */
Task_Params_init(&taskParams);
taskParams.stackSize = 512;
taskParams.priority = 3;
myTsk = Task_create((Task_FuncPtr)Flash_Writing, &taskParams, &eb);
if (myTsk == NULL) {
System_abort("hiPriTask create failed");
}

/* enable interrupts */
Hwi_enableInterrupt(int_ID);
FlashIntEnable(FLASH_INT_PROGRAM);
Hwi_enable();

/* start BIOS */
BIOS_start();


}

 

Regards,

Ahmed

  • Hello Ahmed

    Can you check if the Interrupt Mask register bits are set and is the NVIC interrupt enabled for the INT_FLASH

    Regards

    Amit

  • Hello ,

    It is my problem now is that when i just enable the interrupt source and the global interrupt it goes to execute the ISR without starting the BIOS

    Regards

    Ahmed

  • Hello Ahmed,

    Please make sure that there is no previous interrupt status set before you enable the interrupt mask bits and the interrupt.

    Regards

    Amit

  • Hello Amit,

    I am sure that i don't set and interrupt status as you could see in the following code but when i followed the flash status interrupt register(FCRIS) i found it always (by default) in start of the main sets the PRIS bit which indicates that an programming or erasing have completed and also set  PMASK bit which enable the programming FLASH interrupt source ,

    Then although that i clear the pris in the main it goes through the ISR upon on Bios starting

    //---------------------------------------------------------------------------
    // Project: Flash Sample1
    // Author: AHmed Hassan
    // Date: March 2014
    //---------------------------------------------------------------------------
    /*
    * This Sample is to provide safe thread operation
    *
    */

    //------------------------------------------
    // TivaWare Header Files
    //------------------------------------------
    #include <stdint.h>
    #include <stdbool.h>
    #include<stdio.h>

    #include "driverlib/flash.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/gpio.h"
    #include "driverlib/pin_map.h"
    #include "inc/hw_types.h"
    #include "inc/hw_memmap.h"

    //----------------------------------------
    // BIOS header files
    //----------------------------------------
    #include <xdc/std.h> //mandatory - have to include first, for BIOS types
    #include <ti/sysbios/BIOS.h> //mandatory - if you call APIs like BIOS_start()
    #include <xdc/runtime/Log.h> //needed for any Log_info() call
    #include <xdc/cfg/global.h> //header file for statically defined objects/handles

    #include <xdc/std.h>
    #include <xdc/runtime/Error.h>
    #include <xdc/runtime/System.h>
    #include <xdc/runtime/Timestamp.h>
    #include <ti/sysbios/BIOS.h>
    #include <ti/sysbios/knl/Task.h>
    #include <ti/sysbios/hal/Timer.h>
    #include <ti/sysbios/hal/Hwi.h>
    #include <ti/sysbios/knl/Swi.h>
    #include "inc/hw_ints.h"


    #define int_ID 45 /*defining Flash Memory Control vector number */
    /*Function Prototype */
    void Flash_Writing(void);
    void Flash_ISR(void);
    void Flash_led(void);
    void hardware_init(void);

    Error_Block eb;

    /*create HWI*/
    Hwi_Handle hwi0;
    Hwi_Params hwiParams;

    /* Create SWI */
    Swi_Handle LEDSwi;
    Swi_Params swiParams;

    /*Task */
    Task_Params taskParams;
    Task_Handle myTsk;

    void Flash_Writing(void)
    {

    uint32_t pui32Data[2];
    pui32Data[0] = 0x12345678;
    pui32Data[1] = 0x56789abc;
    uint32_t ui32User0_Set=0XEEEEEEEE; /*the value to be written to user register 0 */
    uint32_t ui32User1_Set=0XDDDDDDDD; /*the value to be written to user register 1 */
    int8_t FRESULT; /*To check the success of the programming*/
    FRESULT=-1;
    uint32_t ui32User0_Get;
    uint32_t ui32User1_Get;

    /* ERASE A BLOCK AT FLASH*/

    FRESULT=FlashErase(0x20000);
    if(FRESULT==-1)
    {
    printf("error erasing");
    }


    /* Program some data into the newly erased block of the flash*/
    FRESULT=FlashProgram(pui32Data,0x20000, sizeof(pui32Data));

    if(FRESULT==-1)
    {
    printf("error programming");
    }

    /*sets the contents of the user registers (0 and 1)*/

    FlashUserSet(ui32User0_Set,ui32User1_Set);


    /*reads the contents of user registers (0 and 1), and stores them */

    FlashUserGet(&ui32User0_Get,&ui32User1_Get);

    }

    void Flash_ISR(void)
    {
    FlashIntClear(FLASH_INT_PROGRAM); /*Clear the source of interrupt*/
    Swi_post(LEDSwi); /* post LEDSwi*/

    }


    void Flash_led(void)
    {

    GPIOPinWrite(GPIO_PORTG_BASE, GPIO_PIN_2, 0x04);
    SysCtlDelay(2000000);
    GPIOPinWrite(GPIO_PORTG_BASE, GPIO_PIN_2, 0x00);
    }

    void hardware_init(void)
    {

    /* Enable the GPIO PortG Peripheral*/

    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);

    /* Make PIN 2 as Output Pin*/

    GPIOPinTypeGPIOOutput(GPIO_PORTG_BASE,GPIO_PIN_2);
    GPIOPinWrite(GPIO_PORTG_BASE, GPIO_PIN_2, 0x00);


    }


    /*
    * main.c
    */
    void main()
    {

    /*HW INtialization*/
    hardware_init();


    /* Initialize error block and hwiParams to default values */
    Error_init(&eb);

    Hwi_Params_init(&hwiParams);
    hwi0 = Hwi_create(int_ID,Flash_ISR, &hwiParams, &eb);
    /* Set Flash_ISR parameters */
    // hwiParams.arg = 12;
    hwiParams.enableInt = FALSE; /* override default setting: Keep interrupt disabled until later */
    // don't allow this interrupt to nest itself
    hwiParams.maskSetting = Hwi_MaskingOption_SELF;
    if (hwi0 == NULL) {
    System_abort("Hwi create failed");
    }

    /* Initialize swiParams to default values */
    Swi_Params_init(&swiParams);
    LEDSwi=Swi_create(Flash_led, &swiParams, &eb);
    swiParams.priority = 1;
    if (LEDSwi == NULL) {
    System_abort("Swi create failed");
    }


    /*Initialize taskParams to default values */
    Task_Params_init(&taskParams);
    taskParams.stackSize = 512;
    taskParams.priority = 3;
    myTsk = Task_create((Task_FuncPtr)Flash_Writing, &taskParams, &eb);
    if (myTsk == NULL) {
    System_abort("hiPriTask create failed");
    }

    /* Clear programming source Flash interrupt */

    FlashIntDisable(FLASH_INT_PROGRAM);
    FlashIntClear(FLASH_INT_PROGRAM);

    /* enable interrupts */

    FlashIntEnable(FLASH_INT_PROGRAM);

    /* start BIOS */
    BIOS_start();


    }

  • Hello Ahmed,

    The PRIS bit is set because the debugger flashes the code every time the code is loaded. The PMASK however may have been set by the debugger as well.

    This causes the interrupt to be put in PEND state inside the NVIC. So before enabling the Interrupt, it needs to be UNPEND in the NVIC

    Regards

    Amit