[STM32U5] STM32U5 Flash 的Quad‑Word大小

[复制链接]
14|0
lvluoo 发表于 2026-9-20 15:59 | 显示全部楼层 |阅读模式
我被 ST 所定义的 “Quad‑Word” 概念搞得很迷惑。按照绝大多数通用的定义,1 个 Word 是 16 位,那么一个 Quad‑Word 就应该是 64 位。
但是对于 STM32U535,ST 这边把 Quad‑Word 定义成了 128 bit。

下面附上我代码的片段。简单来说,我希望向 Flash 写入一共 11520 个 32 位无符号整数;之后设备重新上电再把这些数据读回来。现在程序运行出现混乱,其实就是我始终搞不清楚这里的 Quad‑Word 到底是 64 位还是 128 位。

`xnLookup[][][]`就是待写入并且后续回读的参数数组,数组元素类型为 U32。
写函数如下
i=0;//Channel 0..3
j=0;//Temperature 0..180 (-50 to +130DegC)
k=0;//Term X0, X1, X2, X3 etc
n=1;//Counter for every 4th flash word
MemCount=0;//Total memory locations
//was 11520 for -50 to +130DegC. change to
for(m=0;m<11520;m++)//Total number of parameters to write - //12160
{
         //Copy the polynomial term into the flash array
         flashdata32[n-1].l=xnlookup[k][i][j].l;//Put the polynomial term onto the flash array
         //Every 4 itterations, write the array to flash
         if(n==4)
         {
                 n=0;//reset the counter
                 HAL_FLASH_Program(FLASH_TYPEPROGRAM_QUADWORD, FLASH_TLOOKUP+MemCount, ((u32)flashdata32));
                 MemCount=MemCount+16;//Next QUAD word - 16 BYTES
         }
         //Do the relevant index incrementing - next temperature, next channel, or next term
         if(j>=180)
         {
                 j=0;
                 i++;//i is the channel number 0..3
                 if(i>=16)
                 {
                         i=0;
                         j=0;
                         k++;//k goes 0,1,2,3 for each polynomial term
                 }
         }
         n++;//n is the Flashword index 0..3 4 words =16 bytes
         j++;//j is the temperature index
}
//Now lock the flash
HAL_FLASH_Lock();
}


读函数如下
//Read all of the configuration data
void Read_TLookup(void)
{
u16 i,j,k,l;
u32 MemCount;
l=0;
k=0;
//Read the Polynomial Calibration values
l=0;
for(k=0;k<4;k++)//Polynomial order index (X0, X1, X2, X3)
{
for(i=0;i<16;i++)//channel
{
for(j=0;j<180;j++)//temperature index - was 180, change to 190
{
MemCount=l*4;
xnlookup[k][i][j].l=*(u32*)(FLASH_TLOOKUP+MemCount);//floating point representation
l++;
}
}
}
}

您需要登录后才可以回帖 登录 | 注册

本版积分规则

209

主题

235

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部
0