STM32内存映射
FLASH起始地址 0X800 0000,结束地址是FLASH起始地址加FLASH大小。
RAM 起始地址 0x2000 0000,你定义的变量就是保存在这。
外设地址0x400 0000
如访问内存0x2000 0000直接用
(*((volatile u32 )0x2000 0000))即可。
访问FLASH用
(((volatile u32 *)0x800 0000))即可。
以下是我写的指令,能看懂多少就看懂多少。
#define BALANCE1_ADDR ((uint32_t)0x8000000) //³Æ1±£´æµØÖ·
#define BALANCE2_ADDR ((uint32_t)0x8000020) //³Æ1±£´æµØÖ·
#define BALANCE3_ADDR ((uint32_t)0x8000040) //³Æ1±£´æµØÖ·
#define BALANCE4_ADDR ((uint32_t)0x8000060) //³Æ1±£´æµØÖ·
#define BALANCE5_ADDR ((uint32_t)0x8000080) //³Æ1±£´æµØÖ·
#define BALANCE6_ADDR ((uint32_t)0x80000a0) //³Æ1±£´æµØÖ·
#define BALANCE7_ADDR ((uint32_t)0x80000c0) //³Æ1±£´æµØÖ·
#define BALANCE8_ADDR ((uint32_t)0x80000e0) //³Æ1±£´æµØÖ·
typedef struct
{
__IO float setting_weight; //Óû§ÉèÖÃÄ¿±êÖØÁ¿
__IO float scale; //Á¿³Ì
__IO u32 OFFSET ; //Æ«ÒÆ
__IO u32 times;
__IO float hugebias;
__IO float middlebias;
__IO float smallbias;
__IO float correctfactor;
}struct_balance;
#define BALANCE1 ((struct_balance*)BALANCE1_ADDR)
#define BALANCE2 ((struct_balance*)BALANCE2_ADDR)
#define BALANCE3 ((struct_balance*)BALANCE3_ADDR)
#define BALANCE4 ((struct_balance*)BALANCE4_ADDR)
#define BALANCE5 ((struct_balance*)BALANCE5_ADDR)
#define BALANCE6 ((struct_balance*)BALANCE6_ADDR)
#define BALANCE7 ((struct_balance*)BALANCE7_ADDR)
#define BALANCE8 ((struct_balance*)BALANCE8_ADDR)
h1point=&h1;
h2point=&h2;
h3point=&h3;
h4point=&h4;
h5point=&h5;
h6point=&h6;
h7point=&h7;
h8point=&h8;
h1point->b=BALANCE1;
h1point->settingweight=BALANCE1->setting_weight;
h1point->SCALE=BALANCE1->scale;
h1point->OFFSET=BALANCE1->OFFSET;
h1point->times=BALANCE1->times;
h1point->hugebias=BALANCE1->hugebias;
h1point->middlebias=BALANCE1->middlebias;
h1point->smallbias=BALANCE1->smallbias;
h1point->correctfactor=BALANCE2->correctfactor;
h2point->settingweight=BALANCE2->setting_weight;
h2point->SCALE=BALANCE2->scale;
h2point->OFFSET=BALANCE2->OFFSET;
h2point->times=BALANCE2->times;
h2point->hugebias=BALANCE2->hugebias;
h2point->middlebias=BALANCE2->middlebias;
h2point->smallbias=BALANCE2->smallbias;
h2point->correctfactor=BALANCE2->correctfactor;
h3point->settingweight=BALANCE3->setting_weight;
h3point->SCALE=BALANCE3->scale;
h3point->OFFSET=BALANCE3->OFFSET;
h3point->times=BALANCE3->times;
h3point->hugebias=BALANCE3->hugebias;
h3point->middlebias=BALANCE3->middlebias;
h3point->smallbias=BALANCE3->smallbias;
h3point->correctfactor=BALANCE3->correctfactor;
h4point->settingweight=BALANCE4->setting_weight;
h4point->SCALE=BALANCE4->scale;
h4point->OFFSET=BALANCE4->OFFSET;
h4point->times=BALANCE4->times;
h4point->hugebias=BALANCE4->hugebias;
h4point->middlebias=BALANCE4->middlebias;
h4point->smallbias=BALANCE4->smallbias;
h4point->correctfactor=BALANCE4->correctfactor;
h5point->settingweight=BALANCE5->setting_weight;
h5point->SCALE=BALANCE5->scale;
h5point->OFFSET=BALANCE5->OFFSET;
h5point->times=BALANCE5->times;
h5point->hugebias=BALANCE5->hugebias;
h5point->middlebias=BALANCE5->middlebias;
h5point->smallbias=BALANCE5->smallbias;
h5point->correctfactor=BALANCE5->correctfactor;
h6point->settingweight=BALANCE6->setting_weight;
h6point->SCALE=BALANCE6->scale;
h6point->OFFSET=BALANCE6->OFFSET;
h6point->times=BALANCE6->times;
h6point->hugebias=BALANCE6->hugebias;
h6point->middlebias=BALANCE6->middlebias;
h6point->smallbias=BALANCE6->smallbias;
h6point->correctfactor=BALANCE6->correctfactor;
h7point->settingweight=BALANCE7->setting_weight;
h7point->SCALE=BALANCE7->scale;
h7point->OFFSET=BALANCE7->OFFSET;
h7point->times=BALANCE7->times;
h7point->hugebias=BALANCE7->hugebias;
h7point->middlebias=BALANCE7->middlebias;
h7point->smallbias=BALANCE7->smallbias;
h7point->correctfactor=BALANCE7->correctfactor;
h8point->settingweight=BALANCE8->setting_weight;
h8point->SCALE=BALANCE8->scale;
h8point->OFFSET=BALANCE8->OFFSET;
h8point->times=BALANCE8->times;
h8point->hugebias=BALANCE8->hugebias;
h8point->middlebias=BALANCE8->middlebias;
h8point->smallbias=BALANCE8->smallbias;
h8point->correctfactor=BALANCE8->correctfactor;
main函数调用
t1=(BALANCE1->OFFSET);//h1point->hugebias;
直接可以读出保存的变量,不需要定义中间变量。