test_4mpsram.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include "esp_heap_caps.h"
  2. #include "unity.h"
  3. #include "esp_log.h"
  4. #include "driver/spi_common.h"
  5. #include "sdkconfig.h"
  6. static const char TAG[] = "test_psram";
  7. #ifdef CONFIG_SPIRAM_SUPPORT
  8. static void test_psram_content()
  9. {
  10. const int test_size = 2048;
  11. uint32_t *test_area = heap_caps_malloc(test_size, MALLOC_CAP_SPIRAM);
  12. size_t p;
  13. size_t s=test_size;
  14. int errct=0;
  15. int initial_err=-1;
  16. for (p=0; p<(s/sizeof(int)); p+=4) {
  17. test_area[p]=p^0xAAAAAAAA;
  18. }
  19. for (p=0; p<(s/sizeof(int)); p+=4) {
  20. if (test_area[p]!=(p^0xAAAAAAAA)) {
  21. errct++;
  22. if (errct==1) initial_err=p*4;
  23. }
  24. }
  25. if (errct) {
  26. ESP_LOGE(TAG, "SPI SRAM memory test fail. %d/%d writes failed, first @ %p\n", errct, s/32, initial_err+test_area);
  27. TEST_FAIL();
  28. } else {
  29. ESP_LOGI(TAG, "SPI SRAM memory test OK");
  30. }
  31. free(test_area);
  32. }
  33. #endif
  34. // NOTE: this unit test rely on the config that PSRAM of 8MB is used only when CONFIG_SPIRAM_BNKSWITCH_ENABLE is set
  35. TEST_CASE("can use spi when not being used by psram", "[psram_4m]")
  36. {
  37. spi_host_device_t host;
  38. #if !CONFIG_SPIRAM_SUPPORT || !CONFIG_SPIRAM_SPEED_80M || CONFIG_SPIRAM_BANKSWITCH_ENABLE
  39. //currently all 8M psram don't need more SPI peripherals
  40. host = -1;
  41. #elif CONFIG_SPIRAM_OCCUPY_HSPI_HOST
  42. host = HSPI_HOST;
  43. #elif CONFIG_SPIRAM_OCCUPY_VSPI_HOST
  44. host = VSPI_HOST;
  45. #endif
  46. bool claim_hspi = spicommon_periph_claim(HSPI_HOST, "ut-hspi");
  47. if (claim_hspi) ESP_LOGI(TAG, "HSPI claimed.");
  48. bool claim_vspi = spicommon_periph_claim(VSPI_HOST, "ut-vspi");
  49. if (claim_vspi) ESP_LOGI(TAG, "VSPI claimed.");
  50. if (host == HSPI_HOST) {
  51. TEST_ASSERT(claim_hspi==false);
  52. TEST_ASSERT(claim_vspi==true);
  53. } else if (host == VSPI_HOST) {
  54. TEST_ASSERT(claim_vspi==false);
  55. TEST_ASSERT(claim_hspi==true);
  56. } else {
  57. TEST_ASSERT(claim_hspi==true);
  58. TEST_ASSERT(claim_vspi==true);
  59. }
  60. #ifdef CONFIG_SPIRAM_SUPPORT
  61. test_psram_content();
  62. #endif
  63. }