Hello there guys! I'm struggling with this problem and hope you can help me to figure out my mistake.
I've searched on the forum but couldn't find anyone with the same problem as mine.
I successfully implemented functions to read and write on the information memory, the datasheet had all information I needed. But I have this strange problem to read from the main flash area. Right now I cannot read more then 156 bytes from the main flash, if I try to, my system dont work at all.
Here is my function to read from flash:
#define FLASH_PTR_SEG_D (0x1000) //Pointer to segment D of information memory #define FLASH_PTR_SEG_C (0x1040) //Pointer to segment C of information memory #define FLASH_PTR_SEG_B (0x1080) //Pointer to segment B of information memory #define FLASH_PTR_SEG_A (0x10C0) //Pointer to segment A of information memory #define FLASH_PTR_SEG_4 (0xF600) //Pointer to segment 4 of main memory #define FLASH_PTR_SEG_3 (0xF800) //Pointer to segment 3 of main memory #define FLASH_PTR_SEG_2 (0xFA00) //Pointer to segment 2 of main memory #define FLASH_INFO_SEG_SIZE (0x40) // 64 bytes per segment of information memory #define FLASH_MAIN_SEG_SIZE (0x200) //512 bytes per segment of main memory typedef enum { FLASH_SEG_D, //Information memory FLASH_SEG_C, //Information memory FLASH_SEG_B, //Information memory FLASH_SEG_A, //Information memory FLASH_SEG_4, //Main memory FLASH_SEG_3, //Main memory FLASH_SEG_2, //Main memory FLASH_NUM_SEG }flash_seg_t; #define FLASH_FIRST_INFO_SEG FLASH_SEG_D #define FLASH_FIRST_MAIN_SEG FLASH_SEG_4 static uint16_t flash_address[FLASH_NUM_SEG] = {FLASH_PTR_SEG_D, //Lookup table for segment address FLASH_PTR_SEG_C, FLASH_PTR_SEG_B, FLASH_PTR_SEG_A, FLASH_PTR_SEG_4, FLASH_PTR_SEG_3, FLASH_PTR_SEG_2}; /*! * @brief Reads data from flash memory * @param none * @return none */ error_code_t flash_read_seg(flash_seg_t segment, uint16_t begin, uint16_t size, uint8_t *destiny) { uint16_t max_size; error_code_t error; error = ERROR_NONE; if(segment < FLASH_FIRST_MAIN_SEG) //If segment is at information memory { max_size = FLASH_INFO_SEG_SIZE; } else { max_size = 156; //This should be FLASH_MAIN_SEG_SIZE but if I make this number 1 byte bigger than 156, the system crashes! } //We can only read if segment is in the correct range if( (segment < FLASH_NUM_SEG) && (destiny != NULL) && ( (begin + size) < max_size)) { uint16_t *p_seg; uint16_t index; uint16_t final_index; final_index = begin+size; p_seg = (uint16_t *)flash_address[segment]; //Points to start of segment for( index = begin; index < final_index; index++) { destiny[index] = (uint8_t)p_seg[index]; } } else { error = ERROR_INVALID_PARAMETER; } return error; }
--------------------------
I believe I have put all information necessary! But let me know if you guys want to see more!
I hope this have not been asked before, I did use the search! :)
Thanks in advance! BR.