stevenendlos
Newbie level 5
I'm using TMS470R1B1M F05 Flash and I'm trying erase, write & validate data onto the flash. i'm using IAR Embedded workbench IDE. Here's how my subroutine for write looks like looks like-
#include<stdio.h>
#include<stdlib.h>
#include <TexasInstruments/iotms470r1b1m.h>
#include <TexasInstruments/tms470r1b1m_bit_definitions.h>
#include <intrinsics.h>
# define buffer 0x000F0000 // to find out bank & sector value from the given flash address
# define random_address 0x0003f011 //some random address in flash for writing opreand
# include <string.h>
//////my inputs are 32 bit flash address, 32 bit source pointer, length)
//// void program_flash(uint32 *source_pointer, uint32 flashaddress, uint32 data_len) //my subroutine
void main ()
{
int flashaddress = 0x000f00ff; //temporary input
int sourceaddress = 0x02021292; ///temporary input
unsigned short int sector;
GCR |= FLCONFIG; //setting gcr
sector = (int) (buffer & flashaddress) >> 16; //finding out sector value
FMMAC2_bit.BANK = (int)((sector) /8) ; //assigning bank value to fmmac register
sector = (sector % 8); //since sector range is from 0-7
FMMAC1_bit.PROTL1DIS = 1; //setting bit
FMBSEA = sector; //.....sector value goes into fmbsea
FMPKEY = 0X1111; // write protection keys default(all 1's)
FMREGOPT &= READOTP; //clear the bit readotp
volatile int *dummy = (int *)random_address; //random address in flash memory
*dummy = 0x0010; //writing operand is sent to random adrress in flash memory
memcpy((void*)flashaddress,(void*)sourceaddress, 2); //copying halfword data at a time from source address to flash address
}
My question is-
1. How do I check the final result of the above operation? (writing pass or fail)
2. Anything wrong with the code?
#include<stdio.h>
#include<stdlib.h>
#include <TexasInstruments/iotms470r1b1m.h>
#include <TexasInstruments/tms470r1b1m_bit_definitions.h>
#include <intrinsics.h>
# define buffer 0x000F0000 // to find out bank & sector value from the given flash address
# define random_address 0x0003f011 //some random address in flash for writing opreand
# include <string.h>
//////my inputs are 32 bit flash address, 32 bit source pointer, length)
//// void program_flash(uint32 *source_pointer, uint32 flashaddress, uint32 data_len) //my subroutine
void main ()
{
int flashaddress = 0x000f00ff; //temporary input
int sourceaddress = 0x02021292; ///temporary input
unsigned short int sector;
GCR |= FLCONFIG; //setting gcr
sector = (int) (buffer & flashaddress) >> 16; //finding out sector value
FMMAC2_bit.BANK = (int)((sector) /8) ; //assigning bank value to fmmac register
sector = (sector % 8); //since sector range is from 0-7
FMMAC1_bit.PROTL1DIS = 1; //setting bit
FMBSEA = sector; //.....sector value goes into fmbsea
FMPKEY = 0X1111; // write protection keys default(all 1's)
FMREGOPT &= READOTP; //clear the bit readotp
volatile int *dummy = (int *)random_address; //random address in flash memory
*dummy = 0x0010; //writing operand is sent to random adrress in flash memory
memcpy((void*)flashaddress,(void*)sourceaddress, 2); //copying halfword data at a time from source address to flash address
}
My question is-
1. How do I check the final result of the above operation? (writing pass or fail)
2. Anything wrong with the code?