1 /*
2  * Copyright (c) 2012 Travis Geiselbrecht
3  *
4  * Use of this source code is governed by a MIT-style
5  * license that can be found in the LICENSE file or at
6  * https://opensource.org/licenses/MIT
7  */
8 #include <lk/debug.h>
9 #include <lk/trace.h>
10 #include <lk/err.h>
11 #include <sys/types.h>
12 #include <kernel/thread.h>
13 #include <platform.h>
14 #include <platform/stm32.h>
15 #include <dev/flash_nor.h>
16 #include <stm32f10x_rcc.h>
17 #include <stm32f10x_flash.h>
18 #include <misc.h>
19 
20 /* flash size and page size determined dynamically */
21 #define FLASH_SIZE ((*(REG16(0x1FFFF7E0))) * (size_t)1024)
22 #define FLASH_PAGE_SIZE ((size_t)((FLASH_SIZE > 131072) ? 2048 : 1024))
23 
24 struct flash_nor_bank flash[1];
25 
stm32_flash_nor_early_init(void)26 void stm32_flash_nor_early_init(void) {
27     FLASH_Lock(); // make sure it's locked
28 
29     flash[0].base = 0x08000000;
30     flash[0].len = FLASH_SIZE;
31     flash[0].page_size = FLASH_PAGE_SIZE;
32     flash[0].flags = 0;
33 }
34 
stm32_flash_nor_init(void)35 void stm32_flash_nor_init(void) {
36     TRACEF("flash size %zu\n", FLASH_SIZE);
37     TRACEF("page size %zu\n", FLASH_PAGE_SIZE);
38 }
39 
flash_nor_get_bank(unsigned int bank)40 const struct flash_nor_bank *flash_nor_get_bank(unsigned int bank) {
41     if (bank != 0)
42         return NULL;
43 
44     return &flash[0];
45 }
46 
47