Dear all,
I am developing an application based on the MCXA153 processor. The project uses an external 16MHz crystal, and I have modified the clock configuration, according to your suggestion, to obtain 96MHz as the Main clock.

Also following your instructions, I used the information from the 'romapi_flashiap' project to be able to write to the flash.
Everything works fine, but after the first flash write operation, the Main clock completely changed.
In this post you can find the class and method that I used.
Have you ever had a similar problem?
How was it solved?
Thank you very much for your cooperation and your help.
Regards
class flash {
public:
flash();
virtual ~flash();
void init();
int32_t flashWrite(uint8_t *source, int32_t size);
int32_t flashRead(uint8_t *pDest, int32_t size) ;
private:
status_t status;
uint32_t destAdrss; /* Address of the target location */
uint32_t i, failedAddress, failedData;
uint32_t pflashBlockBase ;
uint32_t pflashTotalSize ;
uint32_t pflashSectorSize ;
uint32_t PflashPageSize ;
flash_config_t s_flashDriver;
union _uBuffer buffer;
void speculation_buffer_clear();
void lpcac_clear();
};
void flash::init() {
pflashBlockBase = 0U;
pflashTotalSize = 0U;
pflashSectorSize = 0U;
PflashPageSize = 0U;
FLASH_API->flash_init(&s_flashDriver);
/* Get flash properties kFLASH_ApiEraseKey */
FLASH_API->flash_get_property(&s_flashDriver, kFLASH_PropertyPflashBlockBaseAddr, &pflashBlockBase);
FLASH_API->flash_get_property(&s_flashDriver, kFLASH_PropertyPflashSectorSize, &pflashSectorSize);
FLASH_API->flash_get_property(&s_flashDriver, kFLASH_PropertyPflashTotalSize, &pflashTotalSize);
FLASH_API->flash_get_property(&s_flashDriver, kFLASH_PropertyPflashPageSize, &PflashPageSize);
destAdrss = pflashBlockBase + (pflashTotalSize - (SECTOR_INDEX_FROM_END * pflashSectorSize));
}
int32_t flash::flashWrite(uint8_t *source, int32_t size) {
status = FLASH_API->flash_erase_sector(&s_flashDriver, destAdrss, pflashSectorSize, kFLASH_ApiEraseKey);
if (status == kStatus_Success) {
speculation_buffer_clear();
lpcac_clear();
status = FLASH_API->flash_verify_erase_sector(&s_flashDriver, destAdrss, pflashSectorSize);
if (status == kStatus_Success) {
status = FLASH_API->flash_program_page(&s_flashDriver, destAdrss, (uint8_t*) source, size);
}
speculation_buffer_clear();
lpcac_clear();
}
return status;
}