×
单片机 > 单片机程序设计 > 详情

在STM32中将变量或代码设定在指定内存地址的方法

发布时间:2020-05-29 发布时间:
|

各个编译器有自己不同的语法


对于arm_none_eabi_gcc:


// Sampling variables

#define ADC_SAMPLE_MAX_LEN 2000

__attribute__((section(".ram4"))) static volatile int16_t m_curr0_samples[ADC_SAMPLE_MAX_LEN];

__attribute__((section(".ram4"))) static volatile int16_t m_curr1_samples[ADC_SAMPLE_MAX_LEN];

__attribute__((section(".ram4"))) static volatile int16_t m_ph1_samples[ADC_SAMPLE_MAX_LEN];

__attribute__((section(".ram4"))) static volatile int16_t m_ph2_samples[ADC_SAMPLE_MAX_LEN];

__attribute__((section(".ram4"))) static volatile int16_t m_ph3_samples[ADC_SAMPLE_MAX_LEN];

__attribute__((section(".ram4"))) static volatile int16_t m_vzero_samples[ADC_SAMPLE_MAX_LEN];

__attribute__((section(".ram4"))) static volatile uint8_t m_status_samples[ADC_SAMPLE_MAX_LEN];

__attribute__((section(".ram4"))) static volatile int16_t m_curr_fir_samples[ADC_SAMPLE_MAX_LEN];

__attribute__((section(".ram4"))) static volatile int16_t m_f_sw_samples[ADC_SAMPLE_MAX_LEN];

__attribute__((section(".ram4"))) static volatile int8_t m_phase_samples[ADC_SAMPLE_MAX_LEN];

在连接脚本中需声明该内存块


MEMORY

{

    flash : org = 0x08000000, len = 16k

    flash2 : org = 0x0800C000, len = 393216 - 16 /* NEW_APP_MAX_SIZE - CRC_INFO */

crcinfo : org = 0x0805FFF0, len = 8 /* CRC info */

    ram0  : org = 0x20000000, len = 128k    /* SRAM1 + SRAM2 */

    ram1  : org = 0x20000000, len = 112k    /* SRAM1 */

    ram2  : org = 0x2001C000, len = 16k     /* SRAM2 */

    ram3  : org = 0x00000000, len = 0

    ram4  : org = 0x10000000, len = 64k     /* CCM SRAM */

    ram5  : org = 0x40024000, len = 4k      /* BCKP SRAM */

    ram6  : org = 0x00000000, len = 0

    ram7  : org = 0x00000000, len = 0

}

并在连接脚本后面要有添加数据的操作


    .ram4 (NOLOAD) : ALIGN(4)

    {

        . = ALIGN(4);

        *(.ram4)

        *(.ram4.*)

        . = ALIGN(4);

        __ram4_free__ = .;

    } > ram4

针对IAR:


 

#if defined (CCMRAM)

#if defined (__ICCARM__)

#pragma location = ".ccmram"     //这里是针对IAR的语法

#elif defined (__CC_ARM) || defined(__GNUC__)

__attribute__( ( section ( "ccmram" ) ) )    //这里是针对GCC等编译器的语法

#endif

#endif

/**

  * @brief  It return the Vqd componets fed in input plus the feed forward

  *         action and store the last Vqd values in the internal variable.

  * @param  pHandle Feed forward  strutcture.

  * @param  Vqd Initial value of Vqd to be manipulated by FF .

  * @retval Volt_Components Vqd conditioned values.

  */

Volt_Components FF_VqdConditioning( FF_Handle_t * pHandle, Volt_Components Vqd )

{

  int32_t wtemp;

 

  pHandle->VqdPIout = Vqd;

 

  wtemp = ( int32_t )( Vqd.qV_Component1 ) + pHandle->Vqdff.qV_Component1;

 

  SATURATION_TO_S16( wtemp )

 

  Vqd.qV_Component1 = ( int16_t )wtemp;

 

  wtemp = ( int32_t )( Vqd.qV_Component2 ) + pHandle->Vqdff.qV_Component2;

 

  SATURATION_TO_S16( wtemp )

 

  Vqd.qV_Component2 = ( int16_t )wtemp;

 

  return ( Vqd );

}

上面的操作是将函数代码放到指定的存储区内。需要快速执行的代码或数据,可以放在SMT32的CCRAM区里。内核访问该存储区的速度比访问FLASH快很多。


关键字:STM32  变量  内存地址 

『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
单片机中高阻态的实质及意义