Ich möchte in den Flash schreiben und anschließend prüfen, ob erfolgreich geschrieben wurde indem ich es wieder auslese:
1 | RCC->APB2ENR |= RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO; |
2 | GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE); |
3 | GPIOA->CRH = _BV(8) | _BV(9) | _BV(28) | _BV(29); |
4 | |
5 | FLASH_Status status = FLASH_COMPLETE; |
6 | FLASH_Unlock(); |
7 | FLASH_ClearFlag(FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR | FLASH_FLAG_EOP); |
8 | FLASH_ProgramWord((uint32_t)FLASH_ADDR, (uint32_t)0x11111111); |
9 | FLASH_Lock(); |
10 | |
11 | while(1) { |
12 | uint16_t len = 0; |
13 | int i = 0; |
14 | |
15 | // _gets((char*)&len, 2); |
16 | // _printf("%d\r\n", len); // debug |
17 | |
18 | if(len == 0x4141) { |
19 | FLASH_Unlock(); |
20 | status = FLASH_ProgramWord((uint32_t)FLASH_ADDR, (uint32_t)0x0); |
21 | // _printf("%d\r\n", status); |
22 | // while(status != FLASH_COMPLETE) |
23 | // status = FLASH_GetStatus(); |
24 | FLASH_Lock(); |
25 | // _printf("erase\r\n"); |
26 | } else { |
27 | GPIOA->ODR ^= _BV(15); |
28 | FLASH_Unlock(); |
29 | status = FLASH_ProgramWord((uint32_t)FLASH_ADDR, (uint32_t)0x11111111); |
30 | // _printf("%d\r\n", status); |
31 | // while(status != FLASH_COMPLETE) |
32 | // status = FLASH_GetStatus(); |
33 | FLASH_Lock(); |
34 | // _printf("write\r\n"); |
35 | } |
36 | |
37 | for(int n = 0; n < 5000000; n++) {} |
38 | |
39 | if(*(uint32_t*)FLASH_ADDR == (uint32_t)0x11111111) { |
40 | GPIOA->ODR &= ~_BV(10); |
41 | } else { |
42 | GPIOA->ODR |= _BV(10); |
43 | } |
44 | } |
Allerdings ist die LED PA10 immer an, es wurde also nicht korrekt geschrieben! Was habe ich falsch gemacht? Die anddresse in die ich versuche zu schreiben ist 0x08002400 .