/*
 * flash.h
 *
 *  Created on: Jan 3, 2023
 *      Author: Tjitte van der Ploeg
 */

#ifndef SRC_FLASH_H_
#define SRC_FLASH_H_

#include "stm32g4xx_hal.h"
#include "stdbool.h"
#include "stdint.h"

//#define FLASH_PAGES			  100
//#define BOOTLOADER_BASE		100
//#define MAIN_APP_BASE     0
//#define NEW_APP_BASE      50
//#define NEW_APP_SECTORS   50
//#define NEW_APP_MAX_SIZE	(NEW_APP_SECTORS * (1 << 11))

#define MAIN_BASE 	0x08000000
#define APP_BASE 	0x0803d800
#define EROM_BASE   0x0807b800
#define BOOT_BASE   0x0807c000



uint16_t modFlashEraseNewAppData(uint32_t new_app_size);
uint16_t modFlashEraseMainAppData(uint32_t new_app_size);
uint16_t modFlashWriteNewAppData(uint32_t offset, uint8_t *data, uint32_t len);
uint16_t modFlashCopyNewAppToMainApp(uint64_t *data, uint32_t len);
void     modFlashJumpToBootloader(void);
void     modFlashJumpToMainApplication(void);

#endif /* SRC_FLASH_H_ */
