Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 6 months ago.
Error with FreescaleIAP code with K22F
Hi again!
I have a K22F platform. I found a problem with the example code of the FreescaleIAP library, i've just done an easier code from this:
--------------
- include "mbed.h"
- include "FreescaleIAP.h"
int main() { int sizeflash = flash_size(); printf(" Flash Size: %d\r\n",sizeflash);
int sizesector = SECTOR_SIZE; printf("Sector Size: %d\r\n",sizesector);
int address = flash_size() - SECTOR_SIZE; int *data = (int*)address; printf("Address: %d\r\n",address); printf(" \r\n");
printf("Starting\r\n"); erase_sector(address);
int numbers[2] = {5,6}; program_flash(address, (char*)&numbers, 8);
printf("Resulting flash: \r\n"); for (int i = 0; i<2; i++) printf("%d\r\n", data[i]);
printf("Done\r\n\n");
while (true) { } }
--------------
While i'm printing, "data[i]" returns me only "-1" values, whatever are the variables in the array.
I tried to change the bytes i program (4, 8 and 16) but it returns me always "-1".
Which could be the problem?
Thank you!!
Question relating to:
1 Answer
9 years, 6 months ago.
I could have sworn I also used this before on the K22F. But you are correct, it indeed does not work properly, it returns access violation error, which is of the flash controller the "I am not going to run that command but I am not telling you why" response.
But I found the problem, it is in the clock setup of the K22F, and I already checked, the K64F does not suffer from this. I might try to add a workaround in the library itself, but not sure about that yet, since I also don't want it to become too bloated. Something I will look into.
In the meantime for you: You can delete your mbed lib and import mbed-src. Navigate to this file: https://developer.mbed.org/users/mbed_official/code/mbed-src/file/1abac31e188e/targets/cmsis/TARGET_Freescale/TARGET_K22F/system_MK22F51212.h, and switch from clock setup 4 to clock setup 5. This is a bit slower one. The difference is that to reach the speed of clock setup 4 it enters HSRUN mode. In HSRUN mode all write access to flash memory is disabled.
Erik, thanks for the time you put in on this bootloader. Looks like the latest mbed lib defaulted the clock back to 4. Works well with the K22.
posted by 15 Dec 2016
Please use
posted by Erik - 23 May 2015<<code>> and <</code>>
around your code, this makes it easier readable and usable.