cancel
Showing results for 
Search instead for 
Did you mean: 

STM32WL store NVM context Lorawan

RPaja.1
Associate II

Hi,

I need some help trying to undestand this operation in Lorawan_end_node example project

nvm_size = ( ( sizeof( LoRaMacNvmData_t ) + 7 ) & ~0x07 ); in the code below:

Maybe it is so simple, but i thought that it would be something like that

nvm_size = sizeof( LoRaMacNvmData_t );

Thanks in advance

LmHandlerErrorStatus_t LmHandlerNvmDataStore( void )
{
#if (defined( CONTEXT_MANAGEMENT_ENABLED ) && ( CONTEXT_MANAGEMENT_ENABLED == 1 ))
    LoRaMacNvmData_t *nvm;
    uint32_t nvm_size;
    LmHandlerErrorStatus_t lmhStatus = LORAMAC_HANDLER_SUCCESS;
    int32_t status = NVM_DATA_OK;
 
    lmhStatus = LmHandlerHalt();
 
    if( lmhStatus == LORAMAC_HANDLER_SUCCESS )
    {
        status = NvmDataMgmtStoreBegin();
 
        if( status == NVM_DATA_NO_UPDATED_DATA )
        {
            lmhStatus = LORAMAC_HANDLER_NVM_DATA_UP_TO_DATE;
        }
        else if( ( status != NVM_DATA_OK ) || ( LmHandlerCallbacks->OnStoreContextRequest == NULL ) )
        {
            lmhStatus = LORAMAC_HANDLER_ERROR;
        }
        else
        {
            MibRequestConfirm_t mibReq;
            mibReq.Type = MIB_NVM_CTXS;
            LoRaMacMibGetRequestConfirm( &mibReq );
            nvm = ( LoRaMacNvmData_t * )mibReq.Param.Contexts;
            nvm_size = ( ( sizeof( LoRaMacNvmData_t ) + 7 ) & ~0x07 );
            LmHandlerCallbacks->OnStoreContextRequest( nvm, nvm_size );
        }
 
        if( NvmDataMgmtStoreEnd() != NVM_DATA_OK )
        {
            lmhStatus = LORAMAC_HANDLER_ERROR;
        }
    }
 
    if( ( lmhStatus == LORAMAC_HANDLER_SUCCESS ) && ( LmHandlerCallbacks->OnNvmDataChange != NULL ) )
    {
        LmHandlerCallbacks->OnNvmDataChange( LORAMAC_HANDLER_NVM_STORE );
    }
 
    return lmhStatus;
#else
    return LORAMAC_HANDLER_ERROR;
#endif /* CONTEXT_MANAGEMENT_ENABLED */
}
1 ACCEPTED SOLUTION

Accepted Solutions
IIRHO.1
ST Employee

Hello @RPaja.1​  ​ and welcome to ST Community

I think that this line of code is used in order to round the size of the `LoRaMacNvmData_t` to the nearest multiple of 8 bytes.

hope this is helpful

Issam

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

3 REPLIES 3
IIRHO.1
ST Employee

Hello @RPaja.1​  ​ and welcome to ST Community

I think that this line of code is used in order to round the size of the `LoRaMacNvmData_t` to the nearest multiple of 8 bytes.

hope this is helpful

Issam

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Thanks for your response @IIRHO.1​ , sizeof returns the number of bytes of LoRaMacNvmData_t, in that case 1484 bytes, is it correct?

It is multiple of 8 bits, my operation, maybe is wrong is that:

nvm_size = ( ( sizeof( LoRaMacNvmData_t ) + 7 ) & ~0x07 );

nvm_size = ( ( 1484 + 7 ) & ~0x07 )

nvm_size = (1491 ) & 0xFFF8 )

nvm_size =1488

Do you mean multiple of 8 bytes?

IIRHO.1
ST Employee

Hi again @RPaja.1​  yes, I mean 8 Bytes . It's just a typo. I corrected . If this is what you are looking for, please mention my answer as the best answer so that the information will be defused

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.