@@ -39,9 +39,9 @@ typedef void (*IAP_Entry) (unsigned long *cmd, unsigned long *stat);
39
39
#define IAP_Call ((IAP_Entry) 0x1FFF1FF1)
40
40
41
41
typedef struct flash_s flash_t ;
42
- unsigned long CCLK ;// CCLK in kHz
42
+ unsigned long CCLK ; // CCLK in kHz
43
43
44
- struct sIAP {// IAP Structure
44
+ struct sIAP { // IAP Structure
45
45
unsigned long cmd ;// Command
46
46
unsigned long par [4 ];// Parameters
47
47
unsigned long stat ;// Status
@@ -57,16 +57,16 @@ struct sIAP {// IAP Structure
57
57
unsigned long GetSecNum (unsigned long address ) {
58
58
unsigned long n ;
59
59
60
- n = address >> 12 ;// 4kB Sector
60
+ n = address >> 12 ; // 4kB Sector
61
61
if (n >= 0x10 ) {
62
- n = 0x0E + (n >> 3 );// 32kB Sector
62
+ n = 0x0E + (n >> 3 ); // 32kB Sector
63
63
}
64
64
65
- return (n );// Sector Number
65
+ return (n ); // Sector Number
66
66
}
67
67
int32_t flash_init (flash_t * obj )
68
68
{
69
- CCLK = SystemCoreClock / 1000 ;// CCLK value is in kHz, clk in Hz
69
+ CCLK = SystemCoreClock / 1000 ; // CCLK value is in kHz, clk in Hz
70
70
71
71
MEMMAP = 0x01 ;// User Flash Mode
72
72
@@ -88,16 +88,20 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
88
88
IAP .par [0 ] = n ;// Start Sector
89
89
IAP .par [1 ] = n ;// End Sector
90
90
IAP_Call (& IAP .cmd , & IAP .stat );// Call IAP Command
91
- if (IAP .stat ) return (1 );// Command Failed
91
+ if (IAP .stat ) {
92
+ return (1 ); // Command Failed
93
+ }
92
94
93
- IAP .cmd = 52 ;// Erase Sector
95
+ IAP .cmd = 52 ; // Erase Sector
94
96
IAP .par [0 ] = n ;// Start Sector
95
97
IAP .par [1 ] = n ;// End Sector
96
98
IAP .par [2 ] = CCLK ;// CCLK in kHz
97
99
IAP_Call (& IAP .cmd , & IAP .stat );// Call IAP Command
98
- if (IAP .stat ) return (1 );// Command Failed
100
+ if (IAP .stat ) {
101
+ return (1 ); // Command Failed
102
+ }
99
103
100
- return (0 );// Finished without Errors
104
+ return (0 ); // Finished without Errors
101
105
102
106
}
103
107
@@ -111,44 +115,47 @@ int32_t flash_program_page(flash_t *obj, uint32_t address,
111
115
unsigned long n ;
112
116
uint8_t * alignedData = 0 ;
113
117
114
- n = GetSecNum (address );// Get Sector Number
118
+ n = GetSecNum (address ); // Get Sector Number
115
119
116
120
IAP .cmd = 50 ;// Prepare Sector for Write
117
121
IAP .par [0 ] = n ;// Start Sector
118
122
IAP .par [1 ] = n ;// End Sector
119
123
IAP_Call (& IAP .cmd , & IAP .stat );// Call IAP Command
120
- if (IAP .stat ) return (1 );// Command Failed
124
+ if (IAP .stat ) {
125
+ return (1 ); // Command Failed
126
+ }
121
127
122
- IAP .cmd = 51 ;// Copy RAM to Flash
128
+ IAP .cmd = 51 ; // Copy RAM to Flash
123
129
IAP .par [0 ] = address ;// Destination Flash Address
124
-
125
- if ((unsigned long )data %4 == 0 ){ // Word boundary
130
+
131
+ if ((unsigned long )data %4 == 0 ) { // Word boundary
126
132
IAP .par [1 ] = (unsigned long )data ;// Source RAM Address
127
133
} else {
128
134
alignedData = malloc (size );
129
135
memcpy (alignedData ,data ,size );
130
- IAP .par [1 ] = (unsigned long )alignedData ;// Source RAM Address
136
+ IAP .par [1 ] = (unsigned long )alignedData ; // Source RAM Address
131
137
}
132
138
133
- IAP .par [2 ] = 1024 ;// Fixed Page Size
139
+ IAP .par [2 ] = 1024 ; // Fixed Page Size
134
140
IAP .par [3 ] = CCLK ;// CCLK in kHz
135
141
IAP_Call (& IAP .cmd , & IAP .stat );// Call IAP Command
136
-
137
- if (alignedData != 0 ){ // We allocated our own memory
142
+
143
+ if (alignedData != 0 ) { // We allocated our own memory
138
144
free (alignedData );
139
145
}
140
-
141
- if (IAP .stat ) return (1 );// Command Failed
142
146
143
- return (0 );// Finished without Errors
147
+ if (IAP .stat ) {
148
+ return (1 ); // Command Failed
149
+ }
150
+ return (0 ); // Finished without Errors
144
151
}
145
152
146
153
uint32_t flash_get_sector_size (const flash_t * obj , uint32_t address )
147
154
{
148
- if (address < flash_get_start_address (obj ) || address >= flash_get_start_address (obj ) + flash_get_size (obj )){
155
+ if (address < flash_get_start_address (obj ) || address >= flash_get_start_address (obj ) + flash_get_size (obj )) {
149
156
return MBED_FLASH_INVALID_SIZE ;
150
157
}
151
- if (GetSecNum (address )>=0x10 ){
158
+ if (GetSecNum (address )>=0x10 ) {
152
159
return 0x8000 ;
153
160
} else {
154
161
return 0x1000 ;
0 commit comments