Skip to content

Commit 3db37a6

Browse files
danielinuxdgarske
authored andcommitted
Updated NVM_CACHE_SIZE to match different configurations.
Progress on psoc6 HAL, fixed memory mapping and test app
1 parent 1e8a0fb commit 3db37a6

12 files changed

Lines changed: 178 additions & 19 deletions

File tree

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ endif
141141

142142
ifeq ($(NVM_FLASH_WRITEONCE),1)
143143
CFLAGS+= -DNVM_FLASH_WRITEONCE
144+
ifneq ($(NVM_CACHE_SIZE),)
145+
CFLAGS+= -DNVM_CACHE_SIZE=$(NVM_CACHE_SIZE)
146+
endif
144147
endif
145148

146149

arch.mk

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,18 @@ ifeq ($(TARGET),psoc6)
159159
$(CYPRESS_PDL)/drivers/source/cy_ipc_drv.o \
160160
$(CYPRESS_PDL)/drivers/source/cy_device.o \
161161
$(CYPRESS_PDL)/drivers/source/cy_sysclk.o \
162+
$(CYPRESS_PDL)/drivers/source/cy_sysint.o \
163+
$(CYPRESS_PDL)/drivers/source/cy_syslib.o \
162164
$(CYPRESS_PDL)/drivers/source/cy_ble_clk.o \
163-
$(CYPRESS_PDL)/devices/templates/COMPONENT_MTB/COMPONENT_CM0P/system_psoc6_cm0plus.o \
164-
$(CYPRESS_PDL)/drivers/source/TOOLCHAIN_GCC_ARM/cy_syslib_gcc.o
165+
$(CYPRESS_PDL)/drivers/source/cy_wdt.o \
166+
$(CYPRESS_PDL)/drivers/source/TOOLCHAIN_GCC_ARM/cy_syslib_gcc.o \
167+
$(CYPRESS_TARGET_LIB)/COMPONENT_CM0P/system_psoc6_cm0plus.o
165168
PKA_EXTRA_CFLAGS+=-I$(CYPRESS_PDL)/drivers/include/ \
166169
-I$(CYPRESS_PDL)/devices/psoc6/psoc63/include/ \
167170
-I$(CYPRESS_PDL)/devices/include \
168171
-I$(CYPRESS_PDL)/cmsis/include \
169-
-I$(CYPRESS_PDL)/core-lib/include \
170-
-I$(CYPRESS_PDL)/devices/templates/COMPONENT_MTB \
172+
-I$(CYPRESS_TARGET_LIB) \
173+
-I$(CYPRESS_CORE_LIB)/include \
171174
-DCY8C6248FNI_S2D43
172175
ARCH_FLASH_OFFSET=0x10000000
173176
endif

hal/psoc6.c

Lines changed: 80 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,78 @@
2727

2828
#include "cy_flash.h"
2929
#include "cy_syspm.h"
30+
#include "cy_sysclk.h"
31+
#include "cy_syslib.h"
3032
#include "cy_ipc_drv.h"
3133

34+
#define ROW_SIZE (0x200)
35+
#define CPU_FREQ (100000000)
36+
3237
#ifndef NVM_FLASH_WRITEONCE
3338
# error "wolfBoot psoc6 HAL: no WRITEONCE support detected. Please define NVM_FLASH_WRITEONCE"
3439
#endif
3540

41+
#if (NVM_CACHE_SIZE != ROW_SIZE)
42+
# error "Wrong NVM_CACHE_SIZE specified for this platform. Please set NVM_CACHE_SIZE to match ROW_SIZE"
43+
#endif
3644

3745
#ifdef __WOLFBOOT
46+
/* Replace Cy_SysLib_DelayUs with a custom call that does not use SysTick
47+
* (required by Cy_SysClk_PllEnable)
48+
*/
49+
50+
#if 0
51+
void Cy_SysLib_DelayUs(uint16_t delay_us)
52+
{
53+
volatile unsigned int i;
54+
uint32_t cycles = ((CPU_FREQ / 1000000)) * delay_us;
55+
for (i = 0; i < cycles; i++) {
56+
asm volatile("nop");
57+
}
58+
}
59+
#endif
60+
61+
static const cy_stc_pll_manual_config_t srss_0_clock_0_pll_0_pllConfig =
62+
{
63+
.feedbackDiv = 100,
64+
.referenceDiv = 2,
65+
.outputDiv = 4,
66+
.lfMode = false,
67+
.outputMode = CY_SYSCLK_FLLPLL_OUTPUT_AUTO,
68+
};
69+
3870
void hal_init(void)
3971
{
40-
/* TODO: how to set clock full speed? */
72+
SystemInit();
73+
#if 0
74+
/*Set clock path 1 source to IMO, this feeds PLL1*/
75+
Cy_SysClk_ClkPathSetSource(1U, CY_SYSCLK_CLKPATH_IN_IMO);
76+
77+
/*Set the input for CLK_HF0 to the output of the PLL, which is on clock path 1*/
78+
Cy_SysClk_ClkHfSetSource(0U, CY_SYSCLK_CLKHF_IN_CLKPATH1);
79+
Cy_SysClk_ClkHfSetDivider(0U, CY_SYSCLK_CLKHF_NO_DIVIDE);
80+
81+
/*Set divider for CM4 clock to 0, might be able to lower this to save power if needed*/
82+
Cy_SysClk_ClkFastSetDivider(0U);
83+
/*Set divider for peripheral and CM0 clock to 0 - This must be 0 to get fastest clock to CM0*/
84+
Cy_SysClk_ClkPeriSetDivider(0U);
85+
/*Set divider for CM0 clock to 0*/
86+
Cy_SysClk_ClkSlowSetDivider(0U);
87+
88+
/*Configure PLL for 100 MHz*/
89+
if (CY_SYSCLK_SUCCESS != Cy_SysClk_PllManualConfigure(1U, &srss_0_clock_0_pll_0_pllConfig))
90+
{
91+
while(1)
92+
;
93+
}
94+
/*Enable PLL*/
95+
if (CY_SYSCLK_SUCCESS != Cy_SysClk_PllEnable(1U, 10000u))
96+
{
97+
while(1)
98+
;
99+
}
100+
#endif
101+
Cy_Flash_Init();
41102
}
42103

43104
void hal_prepare_boot(void)
@@ -47,11 +108,20 @@ void hal_prepare_boot(void)
47108

48109
#endif
49110

111+
112+
/* Only Row-aligned writes allowed. This is guaranteed by wolfBoot if NVM_CACHE is
113+
* in use (via NVM_FLASH_WRITEONCE=1), as unaligned writes become cached.
114+
*/
50115
int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
51116
{
52-
if (len != WOLFBOOT_SECTOR_SIZE)
117+
if (len < NVM_CACHE_SIZE)
53118
return -1;
54-
Cy_Flash_WriteRow(address,(const uint32_t *) data);
119+
while (len) {
120+
Cy_Flash_WriteRow(address, (const uint32_t *) data);
121+
len -= NVM_CACHE_SIZE;
122+
if ((len > 0) && (len < NVM_CACHE_SIZE))
123+
return -1;
124+
}
55125
return 0;
56126
}
57127

@@ -67,12 +137,16 @@ int RAMFUNCTION hal_flash_erase(uint32_t address, int len)
67137
{
68138
int start = -1, end = -1;
69139
uint32_t end_address;
70-
uint32_t p;
140+
uint32_t p = (uint32_t)address;
71141
if (len == 0)
72142
return -1;
73-
end_address = address + len - 1;
74-
for (p = address; p < end_address; p += WOLFBOOT_SECTOR_SIZE) {
143+
end_address = address + len;
144+
/* Assume NVM_CACHE_SIZE is always defined for this platform
145+
* (see #error statements above)
146+
* */
147+
while ((end_address - p) >= NVM_CACHE_SIZE) {
75148
Cy_Flash_EraseRow(p);
149+
p += NVM_CACHE_SIZE;
76150
}
77151
return 0;
78152
}

hal/psoc6.ld

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ SECTIONS
1010
.text :
1111
{
1212
_start_text = .;
13+
__Vectors = .;
1314
KEEP(*(.isr_vector))
1415
. = ALIGN(0x400);
1516
*(.text*)
@@ -46,8 +47,10 @@ SECTIONS
4647
_end_bss = .;
4748
__bss_end__ = .;
4849
_end = .;
50+
__ramVectors = .;
4951
} > RAM
5052
. = ALIGN(4);
5153
}
5254

5355
END_STACK = ORIGIN(RAM) + LENGTH(RAM);
56+

include/wolfboot/wolfboot.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@
3434
#endif
3535
#define IMAGE_HEADER_OFFSET (2 * sizeof(uint32_t))
3636

37+
#ifdef NVM_FLASH_WRITEONCE
38+
# define FLASHBUFFER_SIZE NVM_CACHE_SIZE
39+
#else
40+
# define FLASHBUFFER_SIZE IMAGE_HEADER_SIZE
41+
#endif
42+
3743
#define WOLFBOOT_MAGIC 0x464C4F57 /* WOLF */
3844
#define WOLFBOOT_MAGIC_TRAIL 0x544F4F42 /* BOOT */
3945

@@ -111,4 +117,5 @@ int wolfBoot_dualboot_candidate(void);
111117
# error "No valid hash algorithm defined!"
112118
#endif
113119

120+
114121
#endif /* !WOLFBOOT_H */

src/boot_arm.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,12 @@ void RAMFUNCTION do_boot(const uint32_t *app_offset)
9797
#ifndef NO_VTOR
9898
/* Disable interrupts */
9999
asm volatile("cpsid i");
100-
/* Update IV */
101-
VTOR = ((uint32_t)app_offset);
100+
#ifdef PLATFORM_psoc6
101+
VTOR = (((uint32_t)(app_offset)) - ARCH_FLASH_OFFSET);
102+
#else
103+
/* Update IV */
104+
VTOR = ((uint32_t)app_offset);
105+
#endif
102106
#endif
103107

104108
/* Get stack pointer, entry point */

src/libwolfboot.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,14 @@ uint32_t ext_cache;
3939
#define PART_UPDATE_ENDFLAGS ((WOLFBOOT_PARTITION_UPDATE_ADDRESS + WOLFBOOT_PARTITION_SIZE) - TRAILER_SKIP)
4040

4141
#ifdef NVM_FLASH_WRITEONCE
42+
43+
#ifndef NVM_CACHE_SIZE
44+
#error "Please define NVM_CACHE_SIZE for this flash model"
45+
#endif
46+
4247
#include <stddef.h>
4348
extern void *memcpy(void *dst, const void *src, size_t n);
44-
static uint8_t NVM_CACHE[WOLFBOOT_SECTOR_SIZE];
49+
static uint8_t NVM_CACHE[NVM_CACHE_SIZE];
4550
int RAMFUNCTION hal_trailer_write(uint32_t addr, uint8_t val) {
4651
uint32_t addr_align = addr & (~(WOLFBOOT_SECTOR_SIZE - 1));
4752
uint32_t addr_off = addr & (WOLFBOOT_SECTOR_SIZE - 1);

src/loader.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ static volatile const uint32_t __attribute__((used)) wolfboot_version = WOLFBOOT
3232
extern void (** const IV_RAM)(void);
3333
#endif
3434

35-
#define FLASHBUFFER_SIZE 256
36-
3735
#ifndef DUALBANK_SWAP
3836
static int wolfBoot_copy_sector(struct wolfBoot_image *src, struct wolfBoot_image *dst, uint32_t sector)
3937
{

src/update_flash.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include "spi_flash.h"
2929
#include "wolfboot/wolfboot.h"
3030

31-
#define FLASHBUFFER_SIZE 256
3231

3332
#ifdef RAM_CODE
3433
extern unsigned int _start_text;

test-app/ARM-psoc6.ld

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
MEMORY
2+
{
3+
FLASH (rx) : ORIGIN = ##WOLFBOOT_TEST_APP_ADDRESS##, LENGTH = ##WOLFBOOT_TEST_APP_SIZE##
4+
RAM (rwx) : ORIGIN = 0x08000000, LENGTH = 64K
5+
}
6+
7+
SECTIONS
8+
{
9+
10+
.text :
11+
{
12+
_start_text = .;
13+
KEEP(*(.isr_vector))
14+
. = ALIGN(0x400);
15+
*(.text*)
16+
*(.rodata*)
17+
*(.init*)
18+
*(.fini*)
19+
. = ALIGN(4);
20+
_end_text = .;
21+
} > FLASH
22+
23+
.edidx :
24+
{
25+
. = ALIGN(4);
26+
*(.ARM.exidx*)
27+
} > FLASH
28+
29+
_stored_data = .;
30+
31+
.data : AT (_stored_data)
32+
{
33+
_start_data = .;
34+
KEEP(*(.data*))
35+
. = ALIGN(4);
36+
_end_data = .;
37+
} > RAM
38+
39+
.bss (NOLOAD) :
40+
{
41+
_start_bss = .;
42+
__bss_start__ = .;
43+
*(.bss*)
44+
*(COMMON)
45+
. = ALIGN(4);
46+
_end_bss = .;
47+
__bss_end__ = .;
48+
_end = .;
49+
} > RAM
50+
. = ALIGN(4);
51+
}
52+
53+
END_STACK = ORIGIN(RAM) + LENGTH(RAM);
54+
PROVIDE(_start_heap = _end);
55+
PROVIDE(_end_stack = ORIGIN(RAM) + LENGTH(RAM));

0 commit comments

Comments
 (0)