1 /***************************************************************************
2 * Copyright (C) 2006 by Magnus Lundin *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 /***************************************************************************
22 * STELLARIS is tested on LM3S811
26 ***************************************************************************/
31 #include "replacements.h"
33 #include "stellaris.h"
34 #include "cortex_m3.h"
39 #include "binarybuffer.h"
46 int stellaris_register_commands(struct command_context_s *cmd_ctx);
47 int stellaris_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank);
48 int stellaris_erase(struct flash_bank_s *bank, int first, int last);
49 int stellaris_protect(struct flash_bank_s *bank, int set, int first, int last);
50 int stellaris_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count);
51 int stellaris_probe(struct flash_bank_s *bank);
52 int stellaris_erase_check(struct flash_bank_s *bank);
53 int stellaris_protect_check(struct flash_bank_s *bank);
54 int stellaris_info(struct flash_bank_s *bank, char *buf, int buf_size);
56 u32 stellaris_get_flash_status(flash_bank_t *bank);
57 void stellaris_set_flash_mode(flash_bank_t *bank,int mode);
58 u32 stellaris_wait_status_busy(flash_bank_t *bank, u32 waitbits, int timeout);
60 int stellaris_read_part_info(struct flash_bank_s *bank);
62 flash_driver_t stellaris_flash =
65 .register_commands = stellaris_register_commands,
66 .flash_bank_command = stellaris_flash_bank_command,
67 .erase = stellaris_erase,
68 .protect = stellaris_protect,
69 .write = stellaris_write,
70 .probe = stellaris_probe,
71 .erase_check = stellaris_erase_check,
72 .protect_check = stellaris_protect_check,
73 .info = stellaris_info
131 /***************************************************************************
132 * openocd command interface *
133 ***************************************************************************/
135 /* flash_bank stellaris <base> <size> 0 0 <target#>
137 int stellaris_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank)
139 stellaris_flash_bank_t *stellaris_info;
143 WARNING("incomplete flash_bank stellaris configuration");
144 return ERROR_FLASH_BANK_INVALID;
147 stellaris_info = calloc(sizeof(stellaris_flash_bank_t),1);
149 bank->driver_priv = stellaris_info;
151 stellaris_info->target_name = "Unknown target";
153 /* part wasn't probed for info yet */
154 stellaris_info->did1 = 0;
156 /* TODO Use an optional main oscillator clock rate in kHz from arg[6] */
160 int stellaris_register_commands(struct command_context_s *cmd_ctx)
163 command_t *stellaris_cmd = register_command(cmd_ctx, NULL, "stellaris", NULL, COMMAND_ANY, NULL);
164 register_command(cmd_ctx, stellaris_cmd, "gpnvm", stellaris_handle_gpnvm_command, COMMAND_EXEC,
165 "stellaris gpnvm <num> <bit> set|clear, set or clear stellaris gpnvm bit");
170 int stellaris_info(struct flash_bank_s *bank, char *buf, int buf_size)
173 stellaris_flash_bank_t *stellaris_info = bank->driver_priv;
175 stellaris_read_part_info(bank);
177 if (stellaris_info->did1 == 0)
179 printed = snprintf(buf, buf_size, "Cannot identify target as a Stellaris\n");
182 return ERROR_FLASH_OPERATION_FAILED;
185 printed = snprintf(buf, buf_size, "\nLMI Stellaris information: Chip is class %i %s v%c.%i\n",
186 (stellaris_info->did0>>16)&0xff, stellaris_info->target_name,
187 'A' + (stellaris_info->did0>>8)&0xFF, (stellaris_info->did0)&0xFF);
191 printed = snprintf(buf, buf_size, "did1: 0x%8.8x, arch: 0x%4.4x, eproc: %s, ramsize:%ik, flashsize: %ik\n",
192 stellaris_info->did1, stellaris_info->did1, "ARMV7M", (1+(stellaris_info->dc0>>16)&0xFFFF)/4, (1+stellaris_info->dc0&0xFFFF)*2);
196 printed = snprintf(buf, buf_size, "master clock(estimated): %ikHz, rcc is 0x%x \n", stellaris_info->mck_freq / 1000, stellaris_info->rcc);
200 if (stellaris_info->num_lockbits>0) {
201 printed = snprintf(buf, buf_size, "pagesize: %i, lockbits: %i 0x%4.4x, pages in lock region: %i \n", stellaris_info->pagesize, stellaris_info->num_lockbits, stellaris_info->lockbits,stellaris_info->num_pages/stellaris_info->num_lockbits);
208 /***************************************************************************
209 * chip identification and status *
210 ***************************************************************************/
212 u32 stellaris_get_flash_status(flash_bank_t *bank)
214 stellaris_flash_bank_t *stellaris_info = bank->driver_priv;
215 target_t *target = bank->target;
218 target_read_u32(target, FLASH_CONTROL_BASE|FLASH_FMC, &fmc);
223 /** Read clock configuration and set stellaris_info->usec_clocks*/
225 void stellaris_read_clock_info(flash_bank_t *bank)
227 stellaris_flash_bank_t *stellaris_info = bank->driver_priv;
228 target_t *target = bank->target;
229 u32 rcc, pllcfg, sysdiv, usesysdiv, bypass, oscsrc;
230 unsigned long tmp, mainfreq;
232 target_read_u32(target, SCB_BASE|RCC, &rcc);
233 DEBUG("Stellaris RCC %x",rcc);
234 target_read_u32(target, SCB_BASE|PLLCFG, &pllcfg);
235 DEBUG("Stellaris PLLCFG %x",pllcfg);
236 stellaris_info->rcc = rcc;
238 sysdiv = (rcc>>23)&0xF;
239 usesysdiv = (rcc>>22)&0x1;
240 bypass = (rcc>>11)&0x1;
241 oscsrc = (rcc>>4)&0x3;
242 /* xtal = (rcc>>6)&0xF; */
246 mainfreq = 6000000; /* Default xtal */
249 mainfreq = 22500000; /* Internal osc. 15 MHz +- 50% */
252 mainfreq = 5625000; /* Internal osc. / 4 */
255 WARNING("Invalid oscsrc (3) in rcc register");
261 mainfreq = 200000000; /* PLL out frec */
264 stellaris_info->mck_freq = mainfreq/(1+sysdiv);
266 stellaris_info->mck_freq = mainfreq;
268 /* Forget old flash timing */
269 stellaris_set_flash_mode(bank,0);
272 /* Setup the timimg registers */
273 void stellaris_set_flash_mode(flash_bank_t *bank,int mode)
275 stellaris_flash_bank_t *stellaris_info = bank->driver_priv;
276 target_t *target = bank->target;
278 u32 usecrl = (stellaris_info->mck_freq/1000000ul-1);
279 DEBUG("usecrl = %i",usecrl);
280 target_write_u32(target, SCB_BASE|USECRL , usecrl);
284 u32 stellaris_wait_status_busy(flash_bank_t *bank, u32 waitbits, int timeout)
288 /* Stellaris waits for cmdbit to clear */
289 while (((status = stellaris_get_flash_status(bank)) & waitbits) && (timeout-- > 0))
291 DEBUG("status: 0x%x", status);
295 /* Flash errors are reflected in the FLASH_CRIS register */
301 /* Send one command to the flash controller */
302 int stellaris_flash_command(struct flash_bank_s *bank,u8 cmd,u16 pagen)
305 stellaris_flash_bank_t *stellaris_info = bank->driver_priv;
306 target_t *target = bank->target;
308 fmc = FMC_WRKEY | cmd;
309 target_write_u32(target, FLASH_CONTROL_BASE|FLASH_FMC, fmc);
310 DEBUG("Flash command: 0x%x", fmc);
312 if (stellaris_wait_status_busy(bank, cmd, 100))
314 return ERROR_FLASH_OPERATION_FAILED;
320 /* Read device id register, main clock frequency register and fill in driver info structure */
321 int stellaris_read_part_info(struct flash_bank_s *bank)
323 stellaris_flash_bank_t *stellaris_info = bank->driver_priv;
324 target_t *target = bank->target;
325 u32 did0,did1, ver, fam, status;
328 /* Read and parse chip identification register */
329 target_read_u32(target, SCB_BASE|DID0, &did0);
330 target_read_u32(target, SCB_BASE|DID1, &did1);
331 target_read_u32(target, SCB_BASE|DC0, &stellaris_info->dc0);
332 target_read_u32(target, SCB_BASE|DC1, &stellaris_info->dc1);
333 DEBUG("did0 0x%x, did1 0x%x, dc0 0x%x, dc1 0x%x",did0, did1, stellaris_info->dc0,stellaris_info->dc1);
336 if((ver != 0) && (ver != 1))
338 WARNING("Unknown did0 version, cannot identify target");
339 return ERROR_FLASH_OPERATION_FAILED;
344 fam = (did1 >> 24) & 0xF;
345 if(((ver != 0) && (ver != 1)) || (fam != 0))
347 WARNING("Unknown did1 version/family, cannot positively identify target as a Stellaris");
352 WARNING("Cannot identify target as a Stellaris");
353 return ERROR_FLASH_OPERATION_FAILED;
356 for (i=0;StellarisParts[i].partno;i++)
358 if (StellarisParts[i].partno==((did1>>16)&0xFF))
362 stellaris_info->target_name = StellarisParts[i].partname;
364 stellaris_info->did0 = did0;
365 stellaris_info->did1 = did1;
367 stellaris_info->num_lockbits = 1+stellaris_info->dc0&0xFFFF;
368 stellaris_info->num_pages = 2*(1+stellaris_info->dc0&0xFFFF);
369 stellaris_info->pagesize = 1024;
370 bank->size = 1024*stellaris_info->num_pages;
371 stellaris_info->pages_in_lockregion = 2;
372 target_read_u32(target, SCB_BASE|FMPPE, &stellaris_info->lockbits);
374 // Read main and master clock freqency register
375 stellaris_read_clock_info(bank);
377 status = stellaris_get_flash_status(bank);
379 WARNING("stellaris flash only tested for LM3S811 series");
384 /***************************************************************************
386 ***************************************************************************/
388 int stellaris_erase_check(struct flash_bank_s *bank)
390 stellaris_flash_bank_t *stellaris_info = bank->driver_priv;
391 target_t *target = bank->target;
399 int stellaris_protect_check(struct flash_bank_s *bank)
403 stellaris_flash_bank_t *stellaris_info = bank->driver_priv;
404 target_t *target = bank->target;
406 if (stellaris_info->did1 == 0)
408 stellaris_read_part_info(bank);
411 if (stellaris_info->did1 == 0)
413 WARNING("Cannot identify target as an AT91SAM");
414 return ERROR_FLASH_OPERATION_FAILED;
417 status = stellaris_get_flash_status(bank);
418 stellaris_info->lockbits = status >> 16;
423 int stellaris_erase(struct flash_bank_s *bank, int first, int last)
426 u32 flash_fmc, flash_cris;
427 stellaris_flash_bank_t *stellaris_info = bank->driver_priv;
428 target_t *target = bank->target;
430 if (bank->target->state != TARGET_HALTED)
432 return ERROR_TARGET_NOT_HALTED;
435 if (stellaris_info->did1 == 0)
437 stellaris_read_part_info(bank);
440 if (stellaris_info->did1 == 0)
442 WARNING("Cannot identify target as Stellaris");
443 return ERROR_FLASH_OPERATION_FAILED;
446 if ((first < 0) || (last < first) || (last >= stellaris_info->num_pages))
448 return ERROR_FLASH_SECTOR_INVALID;
451 /* Configure the flash controller timing */
452 stellaris_read_clock_info(bank);
453 stellaris_set_flash_mode(bank,0);
455 /* Clear and disable flash programming interrupts */
456 target_write_u32(target, FLASH_CIM, 0);
457 target_write_u32(target, FLASH_MISC, PMISC|AMISC);
459 if ((first == 0) && (last == (stellaris_info->num_pages-1)))
461 target_write_u32(target, FLASH_FMA, 0);
462 target_write_u32(target, FLASH_FMC, FMC_WRKEY | FMC_MERASE);
463 /* Wait until erase complete */
466 target_read_u32(target, FLASH_FMC, &flash_fmc);
468 while(flash_fmc & FMC_MERASE);
470 /* if device has > 128k, then second erase cycle is needed */
471 if(stellaris_info->num_pages * stellaris_info->pagesize > 0x20000)
473 target_write_u32(target, FLASH_FMA, 0x20000);
474 target_write_u32(target, FLASH_FMC, FMC_WRKEY | FMC_MERASE);
475 /* Wait until erase complete */
478 target_read_u32(target, FLASH_FMC, &flash_fmc);
480 while(flash_fmc & FMC_MERASE);
486 for (banknr=first;banknr<=last;banknr++)
488 /* Address is first word in page */
489 target_write_u32(target, FLASH_FMA, banknr*stellaris_info->pagesize);
490 /* Write erase command */
491 target_write_u32(target, FLASH_FMC, FMC_WRKEY | FMC_ERASE);
492 /* Wait until erase complete */
495 target_read_u32(target, FLASH_FMC, &flash_fmc);
497 while(flash_fmc & FMC_ERASE);
499 /* Check acess violations */
500 target_read_u32(target, FLASH_CRIS, &flash_cris);
501 if(flash_cris & (AMASK))
503 WARNING("Error erasing flash page %i, flash_cris 0x%x", banknr, flash_cris);
504 target_write_u32(target, FLASH_CRIS, 0);
505 return ERROR_FLASH_OPERATION_FAILED;
512 int stellaris_protect(struct flash_bank_s *bank, int set, int first, int last)
514 u32 cmd, fmppe, flash_fmc, flash_cris;
517 stellaris_flash_bank_t *stellaris_info = bank->driver_priv;
518 target_t *target = bank->target;
520 if (bank->target->state != TARGET_HALTED)
522 return ERROR_TARGET_NOT_HALTED;
525 if ((first < 0) || (last < first) || (last >= stellaris_info->num_lockbits))
527 return ERROR_FLASH_SECTOR_INVALID;
530 if (stellaris_info->did1 == 0)
532 stellaris_read_part_info(bank);
535 if (stellaris_info->did1 == 0)
537 WARNING("Cannot identify target as an Stellaris MCU");
538 return ERROR_FLASH_OPERATION_FAILED;
541 /* Configure the flash controller timing */
542 stellaris_read_clock_info(bank);
543 stellaris_set_flash_mode(bank,0);
545 fmppe = stellaris_info->lockbits;
546 for (lockregion=first;lockregion<=last;lockregion++)
549 fmppe &= ~(1<<lockregion);
551 fmppe |= (1<<lockregion);
554 /* Clear and disable flash programming interrupts */
555 target_write_u32(target, FLASH_CIM, 0);
556 target_write_u32(target, FLASH_MISC, PMISC|AMISC);
558 DEBUG("fmppe 0x%x",fmppe);
559 target_write_u32(target, SCB_BASE|FMPPE, fmppe);
561 target_write_u32(target, FLASH_FMA, 1);
562 /* Write commit command */
563 /* TODO safety check, sice this cannot be undone */
564 WARNING("Flash protection cannot be removed once commited, commit is NOT executed !");
565 /* target_write_u32(target, FLASH_FMC, FMC_WRKEY | FMC_COMT); */
566 /* Wait until erase complete */
569 target_read_u32(target, FLASH_FMC, &flash_fmc);
571 while(flash_fmc & FMC_COMT);
573 /* Check acess violations */
574 target_read_u32(target, FLASH_CRIS, &flash_cris);
575 if(flash_cris & (AMASK))
577 WARNING("Error setting flash page protection, flash_cris 0x%x", flash_cris);
578 target_write_u32(target, FLASH_CRIS, 0);
579 return ERROR_FLASH_OPERATION_FAILED;
582 target_read_u32(target, SCB_BASE|FMPPE, &stellaris_info->lockbits);
587 u8 stellaris_write_code[] =
591 r1 = destination address
592 r2 = bytecount (in) - endaddr (work)
593 r3 = pFLASH_CTRL_BASE
599 0x07,0x4B, /* ldr r3,pFLASH_CTRL_BASE */
600 0x08,0x4C, /* ldr r4,FLASHWRITECMD */
601 0x01,0x25, /* movs r5, 1 */
602 0x00,0x26, /* movs r6, #0 */
604 0x19,0x60, /* str r1, [r3, #0] */
605 0x87,0x59, /* ldr r7, [r0, r6] */
606 0x5F,0x60, /* str r7, [r3, #4] */
607 0x9C,0x60, /* str r4, [r3, #8] */
609 0x9F,0x68, /* ldr r7, [r3, #8] */
610 0x2F,0x42, /* tst r7, r5 */
611 0xFC,0xD1, /* bne waitloop */
612 0x04,0x31, /* adds r1, r1, #4 */
613 0x04,0x36, /* adds r6, r6, #4 */
614 0x96,0x42, /* cmp r6, r2 */
615 0xF4,0xD1, /* bne mainloop */
616 0x00,0xBE, /* bkpt #0 */
617 /* pFLASH_CTRL_BASE: */
618 0x00,0xD0,0x0F,0x40, /* .word 0x400FD000 */
620 0x01,0x00,0x42,0xA4 /* .word 0xA4420001 */
623 int stellaris_write_block(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 wcount)
625 stellaris_flash_bank_t *stellaris_info = bank->driver_priv;
626 target_t *target = bank->target;
627 u32 buffer_size = 8192;
628 working_area_t *source;
629 working_area_t *write_algorithm;
630 u32 address = bank->base + offset;
631 reg_param_t reg_params[8];
632 armv7m_algorithm_t armv7m_info;
635 DEBUG("(bank=%08X buffer=%08X offset=%08X wcount=%08X)",
636 bank, buffer, offset, wcount);
638 /* flash write code */
639 if (target_alloc_working_area(target, sizeof(stellaris_write_code), &write_algorithm) != ERROR_OK)
641 WARNING("no working area available, can't do block memory writes");
642 return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
645 target_write_buffer(target, write_algorithm->address, sizeof(stellaris_write_code), stellaris_write_code);
648 while (target_alloc_working_area(target, buffer_size, &source) != ERROR_OK)
650 DEBUG("called target_alloc_working_area(target=%08X buffer_size=%08X source=%08X)",
651 target, buffer_size, source);
653 if (buffer_size <= 256)
655 /* if we already allocated the writing code, but failed to get a buffer, free the algorithm */
657 target_free_working_area(target, write_algorithm);
659 WARNING("no large enough working area available, can't do block memory writes");
660 return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
664 armv7m_info.common_magic = ARMV7M_COMMON_MAGIC;
665 armv7m_info.core_mode = ARMV7M_MODE_ANY;
666 armv7m_info.core_state = ARMV7M_STATE_THUMB;
668 init_reg_param(®_params[0], "r0", 32, PARAM_OUT);
669 init_reg_param(®_params[1], "r1", 32, PARAM_OUT);
670 init_reg_param(®_params[2], "r2", 32, PARAM_OUT);
671 init_reg_param(®_params[3], "r3", 32, PARAM_OUT);
672 init_reg_param(®_params[4], "r4", 32, PARAM_OUT);
673 init_reg_param(®_params[5], "r5", 32, PARAM_OUT);
674 init_reg_param(®_params[6], "r6", 32, PARAM_OUT);
675 init_reg_param(®_params[7], "r7", 32, PARAM_OUT);
679 u32 thisrun_count = (wcount > (buffer_size / 4)) ? (buffer_size / 4) : wcount;
681 target_write_buffer(target, source->address, thisrun_count * 4, buffer);
683 buf_set_u32(reg_params[0].value, 0, 32, source->address);
684 buf_set_u32(reg_params[1].value, 0, 32, address);
685 buf_set_u32(reg_params[2].value, 0, 32, 4*thisrun_count);
686 WARNING("Algorithm flash write %i words to 0x%x, %i remaining",thisrun_count,address, wcount);
687 DEBUG("Algorithm flash write %i words to 0x%x, %i remaining",thisrun_count,address, wcount);
688 if ((retval = target->type->run_algorithm(target, 0, NULL, 3, reg_params, write_algorithm->address, write_algorithm->address + sizeof(stellaris_write_code)-10, 10000, &armv7m_info)) != ERROR_OK)
690 ERROR("error executing stellaris flash write algorithm");
691 target_free_working_area(target, source);
692 destroy_reg_param(®_params[0]);
693 destroy_reg_param(®_params[1]);
694 destroy_reg_param(®_params[2]);
695 return ERROR_FLASH_OPERATION_FAILED;
698 buffer += thisrun_count * 4;
699 address += thisrun_count * 4;
700 wcount -= thisrun_count;
704 target_free_working_area(target, write_algorithm);
705 target_free_working_area(target, source);
707 destroy_reg_param(®_params[0]);
708 destroy_reg_param(®_params[1]);
709 destroy_reg_param(®_params[2]);
710 destroy_reg_param(®_params[3]);
711 destroy_reg_param(®_params[4]);
712 destroy_reg_param(®_params[5]);
713 destroy_reg_param(®_params[6]);
714 destroy_reg_param(®_params[7]);
719 int stellaris_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count)
721 stellaris_flash_bank_t *stellaris_info = bank->driver_priv;
722 target_t *target = bank->target;
723 u32 dst_min_alignment, wcount, bytes_remaining = count;
724 u32 address = offset;
725 u32 fcr,flash_cris,flash_fmc;
728 DEBUG("(bank=%08X buffer=%08X offset=%08X count=%08X)",
729 bank, buffer, offset, count);
731 if (bank->target->state != TARGET_HALTED)
733 return ERROR_TARGET_NOT_HALTED;
736 if (stellaris_info->did1 == 0)
738 stellaris_read_part_info(bank);
741 if (stellaris_info->did1 == 0)
743 WARNING("Cannot identify target as a Stellaris processor");
744 return ERROR_FLASH_OPERATION_FAILED;
747 if((offset & 3) || (count & 3))
749 WARNING("offset size must be word aligned");
750 return ERROR_FLASH_DST_BREAKS_ALIGNMENT;
753 if (offset + count > bank->size)
754 return ERROR_FLASH_DST_OUT_OF_BANK;
756 /* Configure the flash controller timing */
757 stellaris_read_clock_info(bank);
758 stellaris_set_flash_mode(bank,0);
761 /* Clear and disable flash programming interrupts */
762 target_write_u32(target, FLASH_CIM, 0);
763 target_write_u32(target, FLASH_MISC, PMISC|AMISC);
765 /* multiple words to be programmed? */
768 /* try using a block write */
769 if ((retval = stellaris_write_block(bank, buffer, offset, count/4)) != ERROR_OK)
771 if (retval == ERROR_TARGET_RESOURCE_NOT_AVAILABLE)
773 /* if block write failed (no sufficient working area),
774 * we use normal (slow) single dword accesses */
775 WARNING("couldn't use block writes, falling back to single memory accesses");
777 else if (retval == ERROR_FLASH_OPERATION_FAILED)
779 /* if an error occured, we examine the reason, and quit */
780 target_read_u32(target, FLASH_CRIS, &flash_cris);
782 ERROR("flash writing failed with CRIS: 0x%x", flash_cris);
783 return ERROR_FLASH_OPERATION_FAILED;
789 address += count * 4;
798 if (!(address&0xff)) DEBUG("0x%x",address);
799 /* Program one word */
800 target_write_u32(target, FLASH_FMA, address);
801 target_write_buffer(target, FLASH_FMD, 4, buffer);
802 target_write_u32(target, FLASH_FMC, FMC_WRKEY | FMC_WRITE);
803 //DEBUG("0x%x 0x%x 0x%x",address,buf_get_u32(buffer, 0, 32),FMC_WRKEY | FMC_WRITE);
804 /* Wait until write complete */
807 target_read_u32(target, FLASH_FMC, &flash_fmc);
809 while(flash_fmc & FMC_WRITE);
814 /* Check acess violations */
815 target_read_u32(target, FLASH_CRIS, &flash_cris);
816 if(flash_cris & (AMASK))
818 DEBUG("flash_cris 0x%x", flash_cris);
819 return ERROR_FLASH_OPERATION_FAILED;
825 int stellaris_probe(struct flash_bank_s *bank)
827 /* we can't probe on an stellaris
828 * if this is an stellaris, it has the configured flash
830 stellaris_flash_bank_t *stellaris_info = bank->driver_priv;
832 if (stellaris_info->did1 == 0)
834 stellaris_read_part_info(bank);
837 if (stellaris_info->did1 == 0)
839 WARNING("Cannot identify target as a LMI Stellaris");
840 return ERROR_FLASH_OPERATION_FAILED;