As stated by jpearmen - this code does pose a risk to your device - if used incorrectly. I assume no responsibility for any damage your device may endure.
I got some time today to look in to writing a file-system module for easyc and stumbled accross some code (I am pretty sure its from the Cortex-M3 SDK) that can be used for reading\writing to the flash memory - and a host of other sorts of things. I found it specifically when I was browsing a “Hardware Abstraction for VEX” project on GitHub:
I found a file under fwLib (Firmware Library), hax/arch_cortex/lib/fwlib/inc/stm32f10x_flash.h
Here are some APIs I see it has defined:
void FLASH_SetLatency(uint32_t FLASH_Latency);
void FLASH_HalfCycleAccessCmd(uint32_t FLASH_HalfCycleAccess);
void FLASH_PrefetchBufferCmd(uint32_t FLASH_PrefetchBuffer);
void FLASH_Unlock(void);
void FLASH_Lock(void);
FLASH_Status FLASH_ErasePage(uint32_t Page_Address);
FLASH_Status FLASH_EraseAllPages(void);
FLASH_Status FLASH_EraseOptionBytes(void);
FLASH_Status FLASH_ProgramWord(uint32_t Address, uint32_t Data);
FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data);
FLASH_Status FLASH_ProgramOptionByteData(uint32_t Address, uint8_t Data);
FLASH_Status FLASH_EnableWriteProtection(uint32_t FLASH_Pages);
FLASH_Status FLASH_ReadOutProtection(FunctionalState NewState);
FLASH_Status FLASH_UserOptionByteConfig(uint16_t OB_IWDG, uint16_t OB_STOP, uint16_t OB_STDBY);
uint32_t FLASH_GetUserOptionByte(void);
uint32_t FLASH_GetWriteProtectionOptionByte(void);
FlagStatus FLASH_GetReadOutProtectionStatus(void);
FlagStatus FLASH_GetPrefetchBufferStatus(void);
void FLASH_ITConfig(uint16_t FLASH_IT, FunctionalState NewState);
FlagStatus FLASH_GetFlagStatus(uint16_t FLASH_FLAG);
void FLASH_ClearFlag(uint16_t FLASH_FLAG);
FLASH_Status FLASH_GetStatus(void);
FLASH_Status FLASH_WaitForLastOperation(uint32_t Timeout);
Which handles flash memory IO - also, there are some files there for programming the interrupt timer and applying the ISRs which handle them - this could introduce a lot of multi-threading features in to easyc. I haven’t done any kernel development on an embeded system (and have done very little on the x86 architecture) so it would definitely be a challenge for me.
Anyway, I don’t have access to my schools cortex till Monday (HOPEFULLY, if the BC Teacher’s Foundation doesn’t vote to stop all extracurricular activites! [This is a mess in the Canadian BC Education system atm…] ) so I was wondering if anyone wanted to play around with the stm32f10x_flash module. I have prepared a solution but have encountered a small trouble when compiling. I must define one of these macros before compiling, they describe for which model the module is for (and I don’t know specifically which is used in the vex cortex and am having trouble finding this out): (its probably easier to just trial & error if you’re unsure)
#if !defined (STM32F10X_LD) && !defined (STM32F10X_LD_VL) && !defined (STM32F10X_MD) && !defined (STM32F10X_MD_VL) && !defined (STM32F10X_HD) && !defined (STM32F10X_CL)
/* #define STM32F10X_LD */ /*!< STM32F10X_LD: STM32 Low density devices */
/* #define STM32F10X_LD_VL */ /*!< STM32F10X_LD_VL: STM32 Low density Value Line devices */
/* #define STM32F10X_MD */ /*!< STM32F10X_MD: STM32 Medium density devices */
/* #define STM32F10X_MD_VL */ /*!< STM32F10X_MD_VL: STM32 Medium density Value Line devices */
/* #define STM32F10X_HD */ /*!< STM32F10X_HD: STM32 High density devices */
/* #define STM32F10X_CL */ /*!< STM32F10X_CL: STM32 Connectivity line devices */
#error "used device must be defined."
#endif
If you do decide to play with it, please report your results. I have attached the easyc project files that is setup in the most primitive way possible for testing the flash memory API - I may have missed a few dependancies - you can find them on the GitHub link above.
easyCFs.zip (82.9 KB)