SEMC Demo Project i.mxRT1050

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

SEMC Demo Project i.mxRT1050

1,480 次查看
christiangradl
Contributor III

Hi, i 've just downloaded the semc demo project for i.mxrt1050. i think there is a very fatal mistake

void SEMC_GetDefaultConfig(semc_config_t *config)
{
    assert(config);

    semc_axi_queueweight_t queueWeight; /*!< AXI queue weight. */
    semc_queuea_weight_t queueaWeight;
    semc_queueb_weight_t queuebWeight;

    /* Get default settings. */
    config->dqsMode = kSEMC_Loopbackinternal;
    config->cmdTimeoutCycles = 0;
    config->busTimeoutCycles = 0x1F;

    /* Set a typical weight settings. */
    memset((void *)&queueWeight, 0, sizeof(semc_axi_queueweight_t));

    queueaWeight.qos = SEMC_BMCR0_TYPICAL_WQOS;
    queueaWeight.aging = SEMC_BMCR0_TYPICAL_WAGE;
    queueaWeight.slaveHitSwith = SEMC_BMCR0_TYPICAL_WSH;
    queueaWeight.slaveHitNoswitch = SEMC_BMCR0_TYPICAL_WRWS;
    queuebWeight.qos = SEMC_BMCR1_TYPICAL_WQOS;
    queuebWeight.aging = SEMC_BMCR1_TYPICAL_WAGE;
    queuebWeight.slaveHitSwith = SEMC_BMCR1_TYPICAL_WRWS;
    queuebWeight.weightPagehit = SEMC_BMCR1_TYPICAL_WPH;
    queuebWeight.bankRotation = SEMC_BMCR1_TYPICAL_WBR;

    config->queueWeight.queueaWeight = &queueaWeight;
    config->queueWeight.queuebWeight = &queuebWeight;
}

Both vars "queueaWeight" and "queuebWeight" are on the stack.

The function void SEMC_Init reads the pointers, etc., etc. etc.

How can this work? The content of the Stackmem is not saved....

标记 (1)
0 项奖励
回复
4 回复数

1,182 次查看
christiangradl
Contributor III

Hi, both variables are lying on the stack and with these pointer assignments they are used later in the code

    config->queueWeight.queueaWeight = &queueaWeight;
    config->queueWeight.queuebWeight = &queuebWeight;

it is not really safe to use the content of the stackmemory later anywhere in the code.

0 项奖励
回复

1,182 次查看
Carlos_Musich
NXP Employee
NXP Employee

Hi Christian,

In order to report any issue and the examples I need to demonstrate that it fails. If you can see a specific scenario which I can reproduce and show that it fails please let me know.

Carlos

0 项奖励
回复

1,182 次查看
christiangradl
Contributor III

Hi,

ok thats simple.

have a look to SEMC driver.

void SEMC_GetDefaultConfig(semc_config_t *config)
{
    assert(config);

    SEMC_AXI_QUEUEWEIGHT_TYPE queueWeight; // AXI queue weight.
    SEMC_QUEUEA_WEIGHT_TYPE queueaWeight;  // !!! Q0 !!!
    SEMC_QUEUEB_WEIGHT_TYPE queuebWeight;
    // Get default settings
    config->dqsMode = kSEMC_Loopbackinternal;
    config->cmdTimeoutCycles = 0;
    config->busTimeoutCycles = 0x1F;
    memset((void *)&queueWeight, 0, sizeof(SEMC_AXI_QUEUEWEIGHT_TYPE));        // !!! Q1 !!!
    queueaWeight.qos = SEMC_BMCR0_TYPICAL_WQOS;
    queueaWeight.aging = SEMC_BMCR0_TYPICAL_WAGE;
    queueaWeight.slaveHitSwith = SEMC_BMCR0_TYPICAL_WSH;
    queueaWeight.slaveHitNoswitch = SEMC_BMCR0_TYPICAL_WRWS;
    queuebWeight.qos = SEMC_BMCR1_TYPICAL_WQOS;
    queuebWeight.aging = SEMC_BMCR1_TYPICAL_WAGE;
    queuebWeight.slaveHitSwith = SEMC_BMCR1_TYPICAL_WRWS;
    queuebWeight.weightPagehit = SEMC_BMCR1_TYPICAL_WPH;
    queuebWeight.bankRotation = SEMC_BMCR1_TYPICAL_WBR;
    config->queueWeight.queueaWeight = &queueaWeight;                  // !!! Q2 !!!!
    config->queueWeight.queuebWeight = &queuebWeight;

}

void SEMC_Init(SEMC_Type *base, SEMC_CONFIG_TYPE *configure)
{

    .......
    // Configure Queue 0/1 for AXI bus

    // !!! Q3 !!!!
    if (configure->queueWeight.queueaWeight) base->BMCR0 = (unsigned long)(configure->queueWeight.queueaWeight);      if (configure->queueWeight.queuebWeight) base->BMCR1 = (unsigned long)(configure->queueWeight.queuebWeight);
}

ad !!! Q1 !!!

queueWeight is a local variable, where is this var used? I think it is dead code

ad !!! Q2 !!!

config->queueWeight.queueaWeight and config->queueWeight.queuebWeight  !!!!  are Pointers !!!!

ad !!! Q3 !!!

base->BMCR0 is set with the pointer address and not with the content ???? Why

ad !!! Q0 !!!

SEMC_QUEUEA_WEIGHT_TYPE queueaWeight is a local variable

at !!! Q2 !!! is then assign with the address if this local variable

at !!! Q3 !!! if the content should be used, then think about this.

    SEMC_GetDefaultConfig(&config);
    MyFunction();      // here the stack memory is used and content of queueaWeight and queuebWeight is being destoryed
    SEMC_Init(SEMC, &config);

christian

0 项奖励
回复

1,182 次查看
Carlos_Musich
NXP Employee
NXP Employee

Hi Christian,

which is the behavior you are facing?

Carlos

0 项奖励
回复