New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make NRF52 flash work with SoftDevice #6124

Merged
merged 1 commit into from Feb 20, 2018

Conversation

Projects
None yet
4 participants
@marcuschangarm
Contributor

marcuschangarm commented Feb 16, 2018

The way flash writes and erases are done on the NRF52 changes depends on whether the SoftDevice is enabled or not.

This change does a runtime check before erasing and writing, and then chooses the correct function to perform the action.

Make NRF52 flash work with SoftDevice
How you write and ersae the flash on the NRF52 changes depending on
whether the SoftDevice is enabled or not.

This change does a runtime check before erasing and writing, and
then chooses the correct function to perform the action.

@cmonr cmonr added the needs: review label Feb 16, 2018

@0xc0170

How was this tested?

@0xc0170

This comment has been minimized.

Member

0xc0170 commented Feb 19, 2018

/morph build

@mbed-ci

This comment has been minimized.

mbed-ci commented Feb 19, 2018

Build : SUCCESS

Build number : 1175
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/6124/

Triggering tests

/morph test
/morph uvisor-test
/morph export-build
/morph mbed2-build

@mbed-ci

This comment has been minimized.

@marcuschangarm

This comment has been minimized.

Contributor

marcuschangarm commented Feb 19, 2018

Using the mbed OS flash tests, a custom test, and this to enable the SoftDevice:

#include "ble/BLE.h"

void bleInitComplete(BLE::InitializationCompleteCallbackContext *params)
{
}

int main(void)
{ 
    BLE &ble = BLE::Instance();
    ble.init(bleInitComplete);

    FlashIAP flash;

    /** Initialize a flash IAP device
     *
     *  Should be called once per lifetime of the object.
     *  @return 0 on success or a negative error code on failure
     */
    int ret_init = flash.init();
    printf("init: %d\r\n", ret_init);

    /** Get the sector size at the defined address
     *
     *  Sector size might differ at address ranges. 
     *  An example <0-0x1000, sector size=1024; 0x10000-0x20000, size=2048>
     *
     *  @param addr Address of or inside the sector to query
     *  @return Size of a sector in bytes or MBED_FLASH_INVALID_SIZE if not mapped
     */
    uint32_t sector_size = flash.get_sector_size(0);
    printf("get_sector_size: %u\r\n", sector_size);

    /** Get the flash start address 
     *
     *  @return Flash start address 
     */
    uint32_t flash_start = flash.get_flash_start();
    printf("get_flash_start: %u\r\n", flash_start);

    /** Get the flash size
     *
     *  @return Flash size 
     */
    uint32_t flash_size = flash.get_flash_size();
    printf("get_flash_size: %u\r\n", flash_size);

    /** Get the program page size
     *
     *  The page size defines the writable page size
     *  @return Size of a program page in bytes
     */
    uint32_t page_size = flash.get_page_size();
    printf("get_page_size: %u\r\n", page_size);



    uint8_t buffer[256];
    uint32_t address = flash_start + flash_size - 10 * sector_size;


    /** Read data from a flash device. 
     *
     *  This method invokes memcpy - reads number of bytes from the address
     *
     *  @param buffer Buffer to write to
     *  @param addr   Flash address to begin reading from
     *  @param size   Size to read in bytes
     *  @return       0 on success, negative error code on failure
     */
    int ret_read = flash.read(buffer, address, sizeof(buffer));

    printf("ret_read: %d\r\n", ret_read);
    for (size_t index = 0; index < sizeof(buffer); index++)    
    {
        printf("%02X", buffer[index]);
    }
    printf("\r\n");

    /** Erase sectors
     *
     *  The state of an erased sector is undefined until it has been programmed
     *
     *  @param addr Address of a sector to begin erasing, must be a multiple of the sector size
     *  @param size Size to erase in bytes, must be a multiple of the sector size
     *  @return     0 on success, negative error code on failure
     */
    int ret_erase = flash.erase(address, sector_size);

    printf("ret_erase: %d\r\n", ret_erase);


    ret_read = flash.read(buffer, address, sizeof(buffer));

    printf("ret_read: %d\r\n", ret_read);
    for (size_t index = 0; index < sizeof(buffer); index++)    
    {
        printf("%02X", buffer[index]);
    }
    printf("\r\n");



    /** Program data to pages
     *
     *  The sectors must have been erased prior to being programmed
     *
     *  @param buffer Buffer of data to be written
     *  @param addr   Address of a page to begin writing to, must be a multiple of program and sector sizes
     *  @param size   Size to write in bytes, must be a multiple of program and sector sizes
     *  @return       0 on success, negative error code on failure
     */
    for (size_t index = 0; index < sizeof(buffer); index++) 
    {
        buffer[index] = index;
    }

    int ret_program = flash.program(buffer, address, sizeof(buffer));

    printf("ret_program: %d\r\n", ret_program);



    ret_read = flash.read(buffer, address, sizeof(buffer));

    printf("ret_read: %d\r\n", ret_read);
    for (size_t index = 0; index < sizeof(buffer); index++)    
    {
        printf("%02X", buffer[index]);
    }
    printf("\r\n");


    /** Deinitialize a flash IAP device
     *
     *  @return 0 on success or a negative error code on failure
     */
    int ret_deinit = flash.deinit();

    printf("deinit: %d\r\n", ret_deinit);
 
   for (;;)
    {
        printf("blink!\r\n");

        led1 = !led1;
        wait_ms(1000);
    }
}
@mbed-ci

This comment has been minimized.

@cmonr cmonr merged commit 8008227 into ARMmbed:master Feb 20, 2018

18 checks passed

AWS-CI uVisor Build & Test Success
Details
ci-morph-build build completed
Details
ci-morph-exporter build completed
Details
ci-morph-mbed2-build build completed
Details
ci-morph-test test completed
Details
continuous-integration/jenkins/pr-head This commit looks good
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
mbed-ci-generic Build finished.
Details
travis-ci/docs/ Local docs testing has passed
Details
travis-ci/events/ Local events testing has passed
Details
travis-ci/littlefs/ Local littlefs testing has passed
Details
travis-ci/mbed2-ATMEL/ Local mbed2-ATMEL testing has passed
Details
travis-ci/mbed2-MAXIM/ Local mbed2-MAXIM testing has passed
Details
travis-ci/mbed2-NORDIC/ Local mbed2-NORDIC testing has passed
Details
travis-ci/mbed2-NUVOTON/ Local mbed2-NUVOTON testing has passed
Details
travis-ci/mbed2-NXP/ Local mbed2-NXP testing has passed
Details
travis-ci/mbed2-SILICON_LABS/ Local mbed2-SILICON_LABS testing has passed
Details
travis-ci/mbed2-STM/ Local mbed2-STM testing has passed
Details

@cmonr cmonr removed the ready for merge label Feb 20, 2018

@marcuschangarm marcuschangarm deleted the marcuschangarm:nrf52_flash_fix branch Feb 21, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment