Skip to content

Commit 0081139

Browse files
committed
Fixed VTOR startup value, added return value check to Cy_* functions
1 parent 5a692a7 commit 0081139

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

hal/psoc6.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
#include "psoc6_02_config.h"
3636

37-
#define ROW_SIZE (0x1000)
37+
#define ROW_SIZE (WOLFBOOT_SECTOR_SIZE)
3838
#define FLASH_BASE_ADDRESS (0x10000000)
3939
#define CPU_FREQ (100000000)
4040

@@ -89,8 +89,14 @@ static void hal_set_pll(void)
8989
}
9090
}
9191

92+
93+
9294
void hal_init(void)
9395
{
96+
#define VTOR (*(volatile uint32_t *)(0xE000ED08))
97+
VTOR = FLASH_BASE_ADDRESS;
98+
#undef VTOR
99+
94100
Cy_PDL_Init(CY_DEVICE_CFG);
95101
Cy_Flash_Init();
96102
hal_set_pll();
@@ -109,6 +115,7 @@ void hal_prepare_boot(void)
109115
int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
110116
{
111117
const uint8_t *src = data;
118+
int ret;
112119
if (len < ROW_SIZE)
113120
return -1;
114121
if ((((uint32_t)data) & FLASH_BASE_ADDRESS) == FLASH_BASE_ADDRESS) {
@@ -119,7 +126,9 @@ int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
119126
src = psoc6_write_buffer;
120127
}
121128
while (len) {
122-
Cy_Flash_ProgramRow(address, (const uint32_t *) src);
129+
ret = Cy_Flash_ProgramRow(address, (const uint32_t *) src);
130+
if (ret)
131+
return ret;
123132
len -= ROW_SIZE;
124133
if ((len > 0) && (len < ROW_SIZE))
125134
return -1;
@@ -137,14 +146,16 @@ void RAMFUNCTION hal_flash_lock(void)
137146

138147
int RAMFUNCTION hal_flash_erase(uint32_t address, int len)
139148
{
140-
int start = -1, end = -1;
141149
uint32_t end_address;
150+
int ret;
142151
uint32_t p = (uint32_t)address;
143152
if (len == 0)
144153
return -1;
145154
end_address = address + len;
146155
while ((end_address - p) >= ROW_SIZE) {
147-
Cy_Flash_EraseRow(p);
156+
ret = Cy_Flash_EraseRow(p);
157+
if (ret)
158+
return ret;
148159
p += ROW_SIZE;
149160
}
150161
return 0;

0 commit comments

Comments
 (0)