iap.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * @brief Common FLASH support functions
  3. *
  4. * @note
  5. * Copyright(C) NXP Semiconductors, 2013
  6. * All rights reserved.
  7. *
  8. * @par
  9. * Software that is described herein is for illustrative purposes only
  10. * which provides customers with programming information regarding the
  11. * LPC products. This software is supplied "AS IS" without any warranties of
  12. * any kind, and NXP Semiconductors and its licensor disclaim any and
  13. * all warranties, express or implied, including all implied warranties of
  14. * merchantability, fitness for a particular purpose and non-infringement of
  15. * intellectual property rights. NXP Semiconductors assumes no responsibility
  16. * or liability for the use of the software, conveys no license or rights under any
  17. * patent, copyright, mask work right, or any other intellectual property rights in
  18. * or to any products. NXP Semiconductors reserves the right to make changes
  19. * in the software without notification. NXP Semiconductors also makes no
  20. * representation or warranty that such application will be suitable for the
  21. * specified use without further testing or modification.
  22. *
  23. * @par
  24. * Permission to use, copy, modify, and distribute this software and its
  25. * documentation is hereby granted, under NXP Semiconductors' and its
  26. * licensor's relevant copyrights in the software, without fee, provided that it
  27. * is used in conjunction with NXP Semiconductors microcontrollers. This
  28. * copyright, permission, and disclaimer notice must appear in all copies of
  29. * this code.
  30. */
  31. #include "chip.h"
  32. /*****************************************************************************
  33. * Private types/enumerations/variables
  34. ****************************************************************************/
  35. /*****************************************************************************
  36. * Public types/enumerations/variables
  37. ****************************************************************************/
  38. /*****************************************************************************
  39. * Private functions
  40. ****************************************************************************/
  41. /*****************************************************************************
  42. * Public functions
  43. ****************************************************************************/
  44. /* Prepare sector for write operation */
  45. uint8_t Chip_IAP_PreSectorForReadWrite(uint32_t strSector, uint32_t endSector)
  46. {
  47. uint32_t command[5], result[4];
  48. command[0] = IAP_PREWRRITE_CMD;
  49. command[1] = strSector;
  50. command[2] = endSector;
  51. iap_entry(command, result);
  52. return result[0];
  53. }
  54. /* Copy RAM to flash */
  55. uint8_t Chip_IAP_CopyRamToFlash(uint32_t dstAdd, uint32_t *srcAdd, uint32_t byteswrt)
  56. {
  57. uint32_t command[5], result[4];
  58. command[0] = IAP_WRISECTOR_CMD;
  59. command[1] = dstAdd;
  60. command[2] = (uint32_t) srcAdd;
  61. command[3] = byteswrt;
  62. command[4] = SystemCoreClock / 1000;
  63. iap_entry(command, result);
  64. return result[0];
  65. }
  66. /* Erase sector */
  67. uint8_t Chip_IAP_EraseSector(uint32_t strSector, uint32_t endSector)
  68. {
  69. uint32_t command[5], result[4];
  70. command[0] = IAP_ERSSECTOR_CMD;
  71. command[1] = strSector;
  72. command[2] = endSector;
  73. command[3] = SystemCoreClock / 1000;
  74. iap_entry(command, result);
  75. return result[0];
  76. }
  77. /* Blank check sector */
  78. uint8_t Chip_IAP_BlankCheckSector(uint32_t strSector, uint32_t endSector)
  79. {
  80. uint32_t command[5], result[4];
  81. command[0] = IAP_BLANK_CHECK_SECTOR_CMD;
  82. command[1] = strSector;
  83. command[2] = endSector;
  84. iap_entry(command, result);
  85. return result[0];
  86. }
  87. /* Read part identification number */
  88. uint32_t Chip_IAP_ReadPID()
  89. {
  90. uint32_t command[5], result[4];
  91. command[0] = IAP_REPID_CMD;
  92. iap_entry(command, result);
  93. return result[1];
  94. }
  95. /* Read boot code version number */
  96. uint8_t Chip_IAP_ReadBootCode()
  97. {
  98. uint32_t command[5], result[4];
  99. command[0] = IAP_READ_BOOT_CODE_CMD;
  100. iap_entry(command, result);
  101. return result[0];
  102. }
  103. /* IAP compare */
  104. uint8_t Chip_IAP_Compare(uint32_t dstAdd, uint32_t srcAdd, uint32_t bytescmp)
  105. {
  106. uint32_t command[5], result[4];
  107. command[0] = IAP_COMPARE_CMD;
  108. command[1] = dstAdd;
  109. command[2] = srcAdd;
  110. command[3] = bytescmp;
  111. iap_entry(command, result);
  112. return result[0];
  113. }
  114. /* Reinvoke ISP */
  115. uint8_t Chip_IAP_ReinvokeISP()
  116. {
  117. uint32_t command[5], result[4];
  118. command[0] = IAP_REINVOKE_ISP_CMD;
  119. iap_entry(command, result);
  120. return result[0];
  121. }
  122. /* Read the unique ID */
  123. uint32_t Chip_IAP_ReadUID()
  124. {
  125. uint32_t command[5], result[4];
  126. command[0] = IAP_READ_UID_CMD;
  127. iap_entry(command, result);
  128. return result[1];
  129. }
  130. /* Erase page */
  131. uint8_t Chip_IAP_ErasePage(uint32_t strPage, uint32_t endPage)
  132. {
  133. uint32_t command[5], result[4];
  134. command[0] = IAP_ERASE_PAGE_CMD;
  135. command[1] = strPage;
  136. command[2] = endPage;
  137. command[3] = SystemCoreClock / 1000;
  138. iap_entry(command, result);
  139. return result[0];
  140. }