Advertisement
ulikoehler

ChibiOS sdcErase() patch

Mar 27th, 2015
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.77 KB | None | 0 0
  1. diff --git a/testhal/STM32/STM32F4xx/SDC/main.c b/testhal/STM32/STM32F4xx/SDC/main.c
  2. index ee5725a..8d6bb97 100644
  3. --- a/testhal/STM32/STM32F4xx/SDC/main.c
  4. +++ b/testhal/STM32/STM32F4xx/SDC/main.c
  5. @@ -62,6 +62,8 @@ static msg_t Thread1(void *arg) {
  6. /* Buffer for block read/write operations, note that an extra byte is
  7. allocated in order to support unaligned operations.*/
  8. static uint8_t buf[MMCSD_BLOCK_SIZE * SDC_BURST_SIZE + 1];
  9. +/* Additional buffer for sdcErase() test */
  10. +static uint8_t buf2[MMCSD_BLOCK_SIZE * SDC_BURST_SIZE ];
  11.  
  12. void cmd_sdc(BaseSequentialStream *chp, int argc, char *argv[]) {
  13. static const char *mode[] = {"SDV11", "SDV20", "MMC", NULL};
  14. @@ -69,7 +71,7 @@ void cmd_sdc(BaseSequentialStream *chp, int argc, char *argv[]) {
  15. uint32_t n, startblk;
  16.  
  17. if (argc != 1) {
  18. - chprintf(chp, "Usage: sdiotest read|write|all\r\n");
  19. + chprintf(chp, "Usage: sdiotest read|write|erase|all\r\n");
  20. return;
  21. }
  22.  
  23. @@ -159,6 +161,81 @@ void cmd_sdc(BaseSequentialStream *chp, int argc, char *argv[]) {
  24. #endif /* STM32_SDC_SDIO_UNALIGNED_SUPPORT */
  25. }
  26.  
  27. +
  28. + if ((strcmp(argv[0], "erase") == 0) ||
  29. + (strcmp(argv[0], "all") == 0)) {
  30. + /**
  31. + * Test sdcErase()
  32. + * Strategy:
  33. + * 1. Fill two blocks with non-constant data
  34. + * 2. Write two blocks starting at startblk
  35. + * 3. Erase the second of the two blocks
  36. + * 3.1. First block should be equal to the data written
  37. + * 3.2. Second block should NOT be equal too the data written (i.e. erased).
  38. + * 4. Erase both first and second block
  39. + * 4.1 Both blocks should not be equal to the data initially written
  40. + * Precondition: SDC_BURST_SIZE >= 2
  41. + */
  42. + memset(buf, 0, MMCSD_BLOCK_SIZE * 2);
  43. + memset(buf2, 0, MMCSD_BLOCK_SIZE * 2);
  44. + /* 1. */
  45. + unsigned int i = 0;
  46. + for (; i < MMCSD_BLOCK_SIZE * 2; ++i) {
  47. + buf[i] = (i + 7) % 'T'; //Ensure block 1/2 are not equal
  48. + }
  49. + /* 2. */
  50. + if(sdcWrite(&SDCD1, startblk, buf, 2)) {
  51. + chprintf(chp, "sdcErase() test write failed\r\n");
  52. + goto exittest;
  53. + }
  54. + /* 3. (erase) */
  55. + if(sdcErase(&SDCD1, startblk + 1, startblk + 2)) {
  56. + chprintf(chp, "sdcErase() failed\r\n");
  57. + goto exittest;
  58. + }
  59. + sdcflags_t errflags = sdcGetAndClearErrors(&SDCD1);
  60. + if(errflags) {
  61. + chprintf(chp, "sdcErase() yielded error flags: %d\r\n", errflags);
  62. + goto exittest;
  63. + }
  64. + if(sdcRead(&SDCD1, startblk, buf2, 2)) {
  65. + chprintf(chp, "single-block sdcErase() failed\r\n");
  66. + goto exittest;
  67. + }
  68. + /* 3.1. */
  69. + if(memcmp(buf, buf2, MMCSD_BLOCK_SIZE) != 0) {
  70. + chprintf(chp, "sdcErase() non-erased block compare failed\r\n");
  71. + goto exittest;
  72. + }
  73. + /* 3.2. */
  74. + if(memcmp(buf + MMCSD_BLOCK_SIZE,
  75. + buf2 + MMCSD_BLOCK_SIZE, MMCSD_BLOCK_SIZE) == 0) {
  76. + chprintf(chp, "sdcErase() erased block compare failed\r\n");
  77. + goto exittest;
  78. + }
  79. + /* 4. */
  80. + if(sdcErase(&SDCD1, startblk, startblk + 2)) {
  81. + chprintf(chp, "multi-block sdcErase() failed\r\n");
  82. + goto exittest;
  83. + }
  84. + if(sdcRead(&SDCD1, startblk, buf2, 2)) {
  85. + chprintf(chp, "single-block sdcErase() failed\r\n");
  86. + goto exittest;
  87. + }
  88. + /* 4.1 */
  89. + if(memcmp(buf, buf2, MMCSD_BLOCK_SIZE) == 0) {
  90. + chprintf(chp, "multi-block sdcErase() erased block compare failed\r\n");
  91. + goto exittest;
  92. + }
  93. + if(memcmp(buf + MMCSD_BLOCK_SIZE,
  94. + buf2 + MMCSD_BLOCK_SIZE, MMCSD_BLOCK_SIZE) == 0) {
  95. + chprintf(chp, "multi-block sdcErase() erased block compare failed\r\n");
  96. + goto exittest;
  97. + }
  98. + /* END of sdcErase() test */
  99. + }
  100. +
  101. +
  102. if ((strcmp(argv[0], "write") == 0) ||
  103. (strcmp(argv[0], "all") == 0)) {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement