X-Git-Url: https://review.openocd.org/gitweb?a=blobdiff_plain;f=src%2Fflash%2Fnor%2Flpcspifi.c;h=7355c30a9ceacc627e9a6d80e1d7d253311cc26a;hb=56802d794e9b23c290ccb373c44b86999f35ca20;hp=7566c275f863e3a32209a126fa4cfbf1782f0a31;hpb=32c4c18045599ddfed36f52b276166ce932b1bf7;p=openocd.git diff --git a/src/flash/nor/lpcspifi.c b/src/flash/nor/lpcspifi.c index 7566c275f8..7355c30a9c 100644 --- a/src/flash/nor/lpcspifi.c +++ b/src/flash/nor/lpcspifi.c @@ -44,6 +44,10 @@ #define SSP_PROBE_TIMEOUT (100) #define SSP_MAX_TIMEOUT (3000) +/* Size of the stack to alloc in the working area for the execution of + * the ROM spifi_init() function */ +#define SPIFI_INIT_STACK_SIZE 512 + struct lpcspifi_flash_bank { int probed; uint32_t ssp_base; @@ -151,7 +155,7 @@ static int lpcspifi_set_hw_mode(struct flash_bank *bank) uint32_t ssp_base = lpcspifi_info->ssp_base; struct armv7m_algorithm armv7m_info; struct working_area *spifi_init_algorithm; - struct reg_param reg_params[1]; + struct reg_param reg_params[2]; int retval = ERROR_OK; LOG_DEBUG("Uninitializing LPC43xx SSP"); @@ -187,13 +191,13 @@ static int lpcspifi_set_hw_mode(struct flash_bank *bank) LOG_DEBUG("Allocating working area for SPIFI init algorithm"); /* Get memory for spifi initialization algorithm */ - retval = target_alloc_working_area(target, sizeof(spifi_init_code), - &spifi_init_algorithm); + retval = target_alloc_working_area(target, sizeof(spifi_init_code) + + SPIFI_INIT_STACK_SIZE, &spifi_init_algorithm); if (retval != ERROR_OK) { LOG_ERROR("Insufficient working area to initialize SPIFI "\ "module. You must allocate at least %zdB of working "\ "area in order to use this driver.", - sizeof(spifi_init_code) + sizeof(spifi_init_code) + SPIFI_INIT_STACK_SIZE ); return retval; @@ -214,6 +218,8 @@ static int lpcspifi_set_hw_mode(struct flash_bank *bank) } init_reg_param(®_params[0], "r0", 32, PARAM_OUT); /* spifi clk speed */ + /* the spifi_init() rom API makes use of the stack */ + init_reg_param(®_params[1], "sp", 32, PARAM_OUT); /* For now, the algorithm will set up the SPIFI module * @ the IRC clock speed. In the future, it could be made @@ -221,10 +227,13 @@ static int lpcspifi_set_hw_mode(struct flash_bank *bank) * already configured them in order to speed up memory- * mapped reads. */ buf_set_u32(reg_params[0].value, 0, 32, 12); + /* valid stack pointer */ + buf_set_u32(reg_params[1].value, 0, 32, (spifi_init_algorithm->address + + sizeof(spifi_init_code) + SPIFI_INIT_STACK_SIZE) & ~7UL); /* Run the algorithm */ LOG_DEBUG("Running SPIFI init algorithm"); - retval = target_run_algorithm(target, 0 , NULL, 1, reg_params, + retval = target_run_algorithm(target, 0 , NULL, 2, reg_params, spifi_init_algorithm->address, spifi_init_algorithm->address + sizeof(spifi_init_code) - 2, 1000, &armv7m_info); @@ -235,6 +244,7 @@ static int lpcspifi_set_hw_mode(struct flash_bank *bank) target_free_working_area(target, spifi_init_algorithm); destroy_reg_param(®_params[0]); + destroy_reg_param(®_params[1]); return retval; } @@ -581,7 +591,7 @@ static int lpcspifi_protect(struct flash_bank *bank, int set, return ERROR_OK; } -static int lpcspifi_write(struct flash_bank *bank, uint8_t *buffer, +static int lpcspifi_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count) { struct target *target = bank->target;