TheThingsIndustries / generic-node-se

Generic Node Sensor Edition
https://www.genericnode.com
Other
108 stars 31 forks source link

Feature/spiffs #170

Closed elsalahy closed 3 years ago

elsalahy commented 3 years ago

Summary:

This PR adds support for SPIFFS and this will allow us to easily write to external flash without worrying about mapping.

This is useful in debugging/logging sensors and update client

Relates to #160 #82 #75

Changes:

Notes for Reviewers:

You can test this using this code snippet

  char buf[12];
  GNSE_Flash_Init();
  GNSE_Flash_mount();
  spiffs_file fdw = SPIFFS_open(&GNSE_Flash_SPIFFS, "my_file", SPIFFS_CREAT | SPIFFS_TRUNC | SPIFFS_RDWR, 0);
  if (SPIFFS_write(&GNSE_Flash_SPIFFS, fdw, (u8_t *)"Hello world", 12) < 0) APP_PPRINTF("errno %i\n", SPIFFS_errno(&GNSE_Flash_SPIFFS));
  SPIFFS_close(&GNSE_Flash_SPIFFS, fdw);

  spiffs_file fdr = SPIFFS_open(&GNSE_Flash_SPIFFS, "my_file", SPIFFS_RDWR, 0);
  if (SPIFFS_read(&GNSE_Flash_SPIFFS, fdr, (u8_t *)buf, 12) < 0) APP_PPRINTF("errno %i\n", SPIFFS_errno(&GNSE_Flash_SPIFFS));
  SPIFFS_close(&GNSE_Flash_SPIFFS, fdr);

  APP_PPRINTF("--> %s <--\n", buf);

Release Notes: (optional)

...

elsalahy commented 3 years ago

This is how people write to external flash without any files system (using our new APIs)

    uint8_t bufferR[4] = {0, 0, 0, 0};
    uint8_t bufferW[4] = {1, 1, 3, 3};
    GNSE_Flash_Write(0x1EFFFE, 4, bufferW);
    GNSE_Flash_BlockErase(0x1EFFFE, 2);
    GNSE_Flash_Read(0x1EFFFE, 4, bufferR);
    GNSE_Flash_Write(0x1EFFFE, 4, bufferW);
    GNSE_Flash_BlockErase(0x1EFFFE, 1);
    GNSE_Flash_Read(0x1EFFFE, 4, bufferR);
elsalahy commented 3 years ago

@marnixcro it seems there is an issue when the external flash is initialized twice causing the system to hang, so I opened #173 and will fix it later.

elsalahy commented 3 years ago

@johanstokking mainly check if you approve of using the SPIFFS APIs/ library. I find it useful but need another opinion on the subject.

johanstokking commented 3 years ago

@johanstokking mainly check if you approve of using the SPIFFS APIs/ library. I find it useful but need another opinion on the subject.

What's the alternative? Why choose this?

I'm not against it, but it doesn't seem maintained (https://github.com/pellepl/spiffs/graphs/contributors) and nobody seems to be actively triaging quite a bunch of issues.

elsalahy commented 3 years ago

@johanstokking

What's the alternative? Why choose this?

There isn't a lot of alternatives. The guys at Mbed OS used the same lib and did a good explanation of why it's useful here. The features mentioned are perfect for the GNSE and I did some testing to confirm functionality.

I'm not against it, but it doesn't seem maintained (https://github.com/pellepl/spiffs/graphs/contributors) and nobody seems to be actively triaging quite a bunch of issues.

Yes I understand, nothing we can do about maintaining it, but the current feature set is enough for us and there is no breaking issues preventing us from not using it.