18
18
#include "mbed_critical.h"
19
19
20
20
#if DEVICE_FLASH
21
+ #include <string.h>
21
22
#include "iodefine.h"
22
23
#include "spibsc_iobitmask.h"
23
24
#include "spibsc.h"
24
25
#include "mbed_drv_cfg.h"
25
26
26
27
/* ---- serial flash command ---- */
28
+ #if (FLASH_SIZE > 0x1000000 )
29
+ #define SPIBSC_OUTPUT_ADDR SPIBSC_OUTPUT_ADDR_32
30
+ #define SFLASHCMD_SECTOR_ERASE (0x21u) /* SE4B 4-byte address(1bit) */
31
+ #define SFLASHCMD_PAGE_PROGRAM (0x12u) /* PP4B 4-byte address(1bit), data(1bit) */
32
+ #else
33
+ #define SPIBSC_OUTPUT_ADDR SPIBSC_OUTPUT_ADDR_24
27
34
#define SFLASHCMD_SECTOR_ERASE (0x20u) /* SE 3-byte address(1bit) */
28
35
#define SFLASHCMD_PAGE_PROGRAM (0x02u) /* PP 3-byte address(1bit), data(1bit) */
36
+ #endif
29
37
#define SFLASHCMD_READ_STATUS_REG (0x05u) /* RDSR data(1bit) */
30
38
#define SFLASHCMD_WRITE_ENABLE (0x06u) /* WREN */
31
39
/* ---- serial flash register definitions ---- */
@@ -74,10 +82,6 @@ typedef struct {
74
82
uint32_t smwdr [2 ]; /* write data */
75
83
} st_spibsc_spimd_reg_t ;
76
84
77
- /* SPI Multi-I/O bus address space address definitions */
78
- #define SPIBSC_ADDR_START (0x18000000uL)
79
- #define SPIBSC_ADDR_END (0x1BFFFFFFuL)
80
-
81
85
typedef struct {
82
86
uint32_t b0 : 1 ; /* bit 0 : - (0) */
83
87
uint32_t b1 : 1 ; /* bit 1 : - (1) */
@@ -96,7 +100,7 @@ typedef struct {
96
100
uint32_t base_addr : 12 ; /* bit 31-20 : PA[31:20] PA(physical address) bits:bit31-20 */
97
101
} mmu_ttbl_desc_section_t ;
98
102
99
- static mmu_ttbl_desc_section_t desc_tbl [(SPIBSC_ADDR_END >> 20 ) - ( SPIBSC_ADDR_START >> 20 ) + 1 ];
103
+ static mmu_ttbl_desc_section_t desc_tbl [(FLASH_SIZE >> 20 )];
100
104
static volatile struct st_spibsc * SPIBSC = & SPIBSC0 ;
101
105
static st_spibsc_spimd_reg_t spimd_reg ;
102
106
static uint8_t write_tmp_buf [FLASH_PAGE_SIZE ];
@@ -193,7 +197,7 @@ int32_t _sector_erase(uint32_t addr)
193
197
spimd_reg .cmd = SFLASHCMD_SECTOR_ERASE ;
194
198
195
199
/* ---- address ---- */
196
- spimd_reg .ade = SPIBSC_OUTPUT_ADDR_24 ;
200
+ spimd_reg .ade = SPIBSC_OUTPUT_ADDR ;
197
201
spimd_reg .addre = SPIBSC_SDR_TRANS ; /* SDR */
198
202
spimd_reg .adb = SPIBSC_1BIT ;
199
203
spimd_reg .addr = addr ;
@@ -252,7 +256,7 @@ int32_t _page_program(uint32_t addr, const uint8_t * buf, int32_t size)
252
256
spimd_reg .cmd = SFLASHCMD_PAGE_PROGRAM ;
253
257
254
258
/* ---- address ---- */
255
- spimd_reg .ade = SPIBSC_OUTPUT_ADDR_24 ;
259
+ spimd_reg .ade = SPIBSC_OUTPUT_ADDR ;
256
260
spimd_reg .addre = SPIBSC_SDR_TRANS ; /* SDR */
257
261
spimd_reg .adb = SPIBSC_1BIT ;
258
262
spimd_reg .addr = addr ;
@@ -687,16 +691,16 @@ static void change_mmu_ttbl_spibsc(uint32_t type)
687
691
mmu_ttbl_desc_section_t * table = (mmu_ttbl_desc_section_t * )TTB ;
688
692
689
693
/* ==== Modify SPI Multi-I/O bus space settings in the MMU translation table ==== */
690
- for (index = (SPIBSC_ADDR_START >> 20 ); index <= ( SPIBSC_ADDR_END >> 20 ); index ++ ) {
694
+ for (index = (FLASH_BASE >> 20 ); index < (( FLASH_BASE + FLASH_SIZE ) >> 20 ); index ++ ) {
691
695
/* Modify memory attribute descriptor */
692
696
if (type == 0 ) { /* Spi */
693
697
desc = table [index ];
694
- desc_tbl [index - (SPIBSC_ADDR_START >> 20 )] = desc ;
698
+ desc_tbl [index - (FLASH_BASE >> 20 )] = desc ;
695
699
desc .AP1_0 = 0x0u ; /* AP[2:0] = b'000 (No access) */
696
700
desc .AP2 = 0x0u ;
697
701
desc .XN = 0x1u ; /* XN = 1 (Execute never) */
698
702
} else { /* Xip */
699
- desc = desc_tbl [index - (SPIBSC_ADDR_START >> 20 )];
703
+ desc = desc_tbl [index - (FLASH_BASE >> 20 )];
700
704
}
701
705
/* Write descriptor back to translation table */
702
706
table [index ] = desc ;
0 commit comments