This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] MSP430I2040:如何将大量数据写入闪存?

Guru**** 2378650 points
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1184824/msp430i2040-how-to-write-large-chunk-of-data-into-flash

器件型号:MSP430I2040

您好!

我正在尝试将大量数据(某些用户生成的设置的结构)保存到闪存中以保留这些数据。 大小(如果为112B)。  由于某种方式、有时在回读整个闪存时实际只保存前3个~ 10个字节、由于在写入之前擦除整个闪存段、其余字节将为0xFF。

uint8_t tlv[64];
    uint8_t *Flash_ptr;
    // Read TLV calibration data before erasing information memory
	memcpy((void *)&tlv[0], (void*)TLV_START, sizeof(tlv));
    // Save settings struct into flash or other persistent medium
    Flash_ptr = (uint8_t *)SETTINGS_ADDR;
    // Erase information memory
    WDTCTL = WDTPW | WDTHOLD;
    FCTL2 = FWKEY | FSSEL_1 | FN1 | FN3 | FN5;  // MCLK/42 for Flash Timing Generator
    while (FCTL3 & BUSY);                       // Make sure flash controller is not busy
    FCTL3 = FWKEY;                              // Clear Lock bit
    if(FCTL3 & LOCKSEG) {                       // If Info Seg is still locked
        FCTL3 = FWKEY | LOCKSEG;                // Clear LOCKSEG bit
    }
    FCTL1 = FWKEY | ERASE;                      // Set Erase bit
    *Flash_ptr = 0;                             // Dummy write to erase info segment
    while (FCTL3 & BUSY);                       // Make sure flash controller is not busy
    FCTL3 = FWKEY;
    if(FCTL3 & LOCKSEG) {                       // If Info Seg is still locked
        FCTL3 = FWKEY | LOCKSEG;                // Clear LOCKSEG bit
    }
    FCTL1 = FWKEY | WRT;
    memcpy((void *)SETTINGS_ADDR, &settings, sizeof(Settings));
    // Save TLV calibration data back into flash
    memcpy((void *)TLV_START, &tlv[0], sizeof(tlv));
    FCTL1 = FWKEY;                              // Clear WRT bit
    FCTL3 = FWKEY | LOCKSEG;                    // Set LOCK bit

起初、我以为这只发生在信息闪存上、但后来我发现、当 SETTINGS_ADDR 指向0xF800等主闪存时、也会发生这种情况。 数据表提到累计编程时间不应超过8ms。 但我的计算表明、112B 花费的时间少于3ms。 MCLK/42作为时钟。

有人能告诉我在这里缺少什么吗?

谢谢。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    问题会一直跟踪到我们使用的固件下载软件。  此用于将数据保存到闪存中的代码块将在首次系统引导时立即运行。 但是、软件会在下载固件后立即重置 MCU、而最后的数据字节仍在写入闪存中。