搜索
bottom↓
回复: 7

keil+iar对STM32位段区软仿真操作似乎不支持?

[复制链接]

出0入0汤圆

发表于 2008-8-11 10:24:21 | 显示全部楼层 |阅读模式
为了什么要用位段区,不再解释.昨天晚上为了优化代码尺寸,做了一个实验
typedef struct{
        vu32 HSION;
        vu32 HSIRDY;
        vu32 NC2;
        vu32 HSITRIM[5];
        vu32 HSICAL[8];
        vu32 HSEON[5];
        vu32 HSERDY;
        vu32 HSEBYP;
        vu32 CSSON;
        vu32 NC1[4];
        vu32 PLLON;
        vu32 PLLRDY;
        vu32 NC[6];       
}RCC_CR_DEF;

//0x42000000+0x21000*0x20+0 = 0x42420000
RCC_CR_DEF * RCC_CR = (RCC_CR_DEF*)0x42420000l;

RCC_CR->HSION = 1; //比用C位域的方式要减少10多个字节

在KEIL和IAR下软仿真,得不到期望得结果.地址计算方式有误? 期盼知情人援助!谢谢!

出0入0汤圆

发表于 2008-8-11 12:04:52 | 显示全部楼层
HSION控制内部RC的开关,但是STM32在使用内部RC作为时钟时,不允许关闭它。
另外,对外设的模拟可能软件方式与硬件方式会有出入。我后来试着把地址改为SRAM区的bitband,如0x2200C000,就可以成功读写(软件模拟与硬件仿真都可以)
我还使用STM32硬件仿真,只不过把代码改成了

//0x42000000+0x21000*0x20+0 = 0x42420000
RCC_CR_DEF * RCC_CR = (RCC_CR_DEF*)( 0x42000000 + 0x21000 * 32);
void TestBitBand(void)
{
        RCC_CR->HSITRIM[0]=0;
        RCC_CR->HSITRIM[1]=1;
        RCC_CR->HSITRIM[2]=0;
        RCC_CR->HSITRIM[3]=1;
        RCC_CR->HSITRIM[4]=0;

        RCC_CR->HSITRIM[0]=1;
        RCC_CR->HSITRIM[1]=0;
        RCC_CR->HSITRIM[2]=1;
        RCC_CR->HSITRIM[3]=0;
        RCC_CR->HSITRIM[4]=1;
}

发现是可以更改HSITRIM[4:0]位段的。不过,还发现在它后面的只读位段值HSICAL[7:0]也会受一些影响,可能是芯片自动更新的。
但在软件模拟时,发现无法更改,可能要使用新版本的MDK

出0入0汤圆

 楼主| 发表于 2008-8-11 15:59:30 | 显示全部楼层
首先谢谢bluelucky.我觉得21ic大牛们都回避了这个问题!也赖得问他们,水平都差不多,问不出结果,其实本帖就是想向bluelucky请教.
HSION上电默认为1,清楚.iar下软仿真进入默认为0.因此觉得置1来玩玩,结果不行.转KEIL下,也相同之.
MDK3.22同MDK3.20.IAR我用的是4.42A,IAR下软仿真可对目标地址置位,映射到关系位失败.
不行的话,不怕,俺就买个最新的512K.羊毛长在羊身上,1包烟的事情,关键心里不爽.不怨天,不怨地,知道bluelucky给出的结果,非常感激
俺继续努力中..!

出0入0汤圆

发表于 2008-8-11 20:49:23 | 显示全部楼层
感谢Qhjh的信任和肯定,这对我是莫大的鼓励!
   
    21ic还是有很多热心的高手的,像匠人,电脑圈圈,还有菜农等。今天电脑圈圈还在我们这里分享了很多USB的in帖,感激中!

    看来软件仿真具体的芯片还是有局限性的,我向英蓓特反映一下。我用的硬件仿真平台是:英蓓特的STM32F103VBT6开发板。现在据我所知512KB flash的新STM32开发板都比较贵,可以仔细地分析一下。

    我对STM32的了解并不多,IAR的经验就更少了。奇文共欣赏,疑义相与析。愿Qhjh和其他朋友们把自己实践的经验、心得与疑问多多放出来,让这个版面红火红火( 也时不时给我消灭消灭盲点:P )

出0入0汤圆

 楼主| 发表于 2008-8-12 10:22:05 | 显示全部楼层
忙着改写头文件.1个好消息,iar4.22a硬件仿真观察支持位段操作.对片内外设操作

#define PERIPH_BB_BASE        ((u32)0x42000000)
#define PERIPH_BASE           ((u32)0x40000000)
用PERIPH_BB_BASE替换PERIPH_BASE,会有惊喜的效果.

512K是夸张了.呵呵!

出0入8汤圆

发表于 2008-8-12 10:52:50 | 显示全部楼层
对于Bit Band的操作,可以看看下面的这个Example,里面涉及到几种方法使用这个功能。在IAR下是可以支持的,MDK下不知道,我没试过。例子来源与ST在07年6月做的CM3培训 动手练习4。

点击此处下载 ourdev_375173.rar(文件大小:70K) (原文件名:LAB4.rar)


/******************** (C) COPYRIGHT 2007 STMicroelectronics ********************
* File Name          : main.c
* Author             : MCD Application Team
* Date First Issued  : 02/05/2007
* Description        : Main program body
********************************************************************************
* History:
* 04/02/2007: V0.2
* 02/05/2007: V0.1
********************************************************************************
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/

/* Includes ------------------------------------------------------------------*/
#include "stm32f10x_lib.h"

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
//#define LAB4_PART1
//#define LAB4_PART2
#define LAB4_PART3

/* GPIOC offset */
#define GPIOC_OFFSET                 (GPIOC_BASE - PERIPH_BASE)

/* GPIOC BSRR offset */
#define GPIOC_BSRR_OFFSET                 (GPIOC_OFFSET + 0x10)

#ifdef LAB4_PART2
/* define the bit set number for PC0.6, PC.07, PC.08 & PC.09 in the BSRR*/
  #define GPIOC_Bit6_SET  ((u8)0x06)
  #define GPIOC_Bit7_SET  ((u8)0x07)
  #define GPIOC_Bit8_SET  ((u8)0x08)
  #define GPIOC_Bit9_SET  ((u8)0x09)

  /* define the bit set address in the alias region for PC0.6, PC.07, PC.08 & PC.09*/
  #define GPIOC_Bit6_SET_BB  (PERIPH_BB_BASE + (GPIOC_BSRR_OFFSET * 32) + (GPIOC_Bit6_SET * 4))
  #define GPIOC_Bit7_SET_BB  (PERIPH_BB_BASE + (GPIOC_BSRR_OFFSET * 32) + (GPIOC_Bit7_SET * 4))
  #define GPIOC_Bit8_SET_BB  (PERIPH_BB_BASE + (GPIOC_BSRR_OFFSET * 32) + (GPIOC_Bit8_SET * 4))
  #define GPIOC_Bit9_SET_BB  (PERIPH_BB_BASE + (GPIOC_BSRR_OFFSET * 32) + (GPIOC_Bit9_SET * 4))
#endif

#ifdef LAB4_PART3
  #define GPIOC_BRR_OFFSET                  (GPIOC_OFFSET + 0x14)
#endif

/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
GPIO_InitTypeDef GPIO_InitStructure;

/* Private function prototypes -----------------------------------------------*/
void RCC_Configuration(void);
void NVIC_Configuration(void);
void Delay(vu32 nCount);

/* Private functions ---------------------------------------------------------*/
/*******************************************************************************
* Function Name  : main
* Description    : Main program.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
int main(void)
{
#ifdef DEBUG
  debug();
#endif

  /* System Clocks Configuration */
  RCC_Configuration();

  /* NVIC Configuration */
  NVIC_Configuration();

  /* Enable GPIOC clock */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);

  /* Configure PC.06, PC.07, PC.08 and PC.09 as output push-pull */
  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOC, &GPIO_InitStructure);

  while(1)
  {
  #ifdef LAB4_PART1
    /* Turn on led connected to PC.06 pin */
    GPIO_Write(GPIOC, GPIO_Pin_6);  
   
    /* Insert delay */
    Delay(0x7FFFF);

    /* Turn on led connected to PC.07 pin */
    GPIO_Write(GPIOC, GPIO_Pin_7);  
   
    /* Insert delay */
    Delay(0x7FFFF);

    /* Turn on led connected to PC.08 pin */
    GPIO_Write(GPIOC, GPIO_Pin_8);  
   
    /* Insert delay */
    Delay(0x7FFFF);
   
    /* Turn on led connected to PC.08 pin */
    GPIO_Write(GPIOC, GPIO_Pin_9);  
   
    /* Insert delay */
    Delay(0x7FFFF);
  
  #endif /* LAB4_PART1 */

  #ifdef LAB4_PART2
   
    /* Turn off leds connected to PC.06, PC.07, PC.08 & PC.09 pin */
    GPIO_Write(GPIOC, (u16) ~(GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9));
   
    /* Insert delay */
    Delay(0x7FFFF);
   
    /* Turn on led connected to PC.06 pin using bit band */
    *(vu32 *) GPIOC_Bit6_SET_BB = 1;
   
    /* Insert delay */
    Delay(0x7FFFF);
   
    /* Turn on led connected to PC.07 pin using bit band */
    *(vu32 *) GPIOC_Bit7_SET_BB = 1;
   
    /* Insert delay */
    Delay(0x7FFFF);
   
    /* Turn on led connected to PC.08 pin using bit band */
    *(vu32 *) GPIOC_Bit8_SET_BB = 1;
   
    /* Insert delay */
    Delay(0x7FFFF);
   
    /* Turn on led connected to PC.09 pin using bit band */
    *(vu32 *) GPIOC_Bit9_SET_BB = 1;
   
    /* Insert delay */
    Delay(0x7FFFF);
   
  #endif /* LAB4_PART2 */
   
  #ifdef LAB4_PART3
    /* Turn on leds connected to PC.06, PC.07, PC.08 & PC.09 pin */
    *(vu32 *) (GPIOC_BRR_OFFSET + PERIPH_BASE) =  (u32) (GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9);
   
      /* Insert delay */
    Delay(0x7FFFF);  
   
    /* Turn off leds connected to PC.06, PC.07, PC.08 & PC.09 pin */
    *(vu32 *) (GPIOC_BRR_OFFSET + PERIPH_BASE) =  (u32) (GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9);
   
    /* Insert delay */
    Delay(0x7FFFF);
   
  #endif /* LAB4_PART3 */
   
  }
}

/*******************************************************************************
* Function Name  : RCC_Configuration
* Description    : Configures the different system clocks.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void RCC_Configuration(void)
{
  /* RCC system reset(for debug purpose) */
  RCC_DeInit();

  /* Enable HSE */
  RCC_HSEConfig(RCC_HSE_ON);

  /* Wait till HSE is ready */
  while(RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET)
  {
  }

  /* HCLK = SYSCLK */
  RCC_HCLKConfig(RCC_SYSCLK_Div1);
  
  /* PCLK2 = HCLK */
  RCC_PCLK2Config(RCC_HCLK_Div1);

  /* PCLK1 = HCLK */
  RCC_PCLK1Config(RCC_HCLK_Div1);

  /* Select HSE as system clock source */
  RCC_SYSCLKConfig(RCC_SYSCLKSource_HSE);

  /* Wait till HSE is used as system clock source */
  while(RCC_GetSYSCLKSource() != 0x04)
  {
  }
}

/*******************************************************************************
* Function Name  : NVIC_Configuration
* Description    : Configures Vector Table base location.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void NVIC_Configuration(void)
{
#ifdef  VECT_TAB_RAM  
  /* Set the Vector Table base location at 0x20000000 */
  NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else  /* VECT_TAB_FLASH  */
  /* Set the Vector Table base location at 0x08000000 */
  NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);   
#endif
}

#ifdef  DEBUG
/*******************************************************************************
* Function Name  : assert_failed
* Description    : Reports the name of the source file and the source line number
*                  where the assert error has occurred.
* Input          : - file: pointer to the source file name
*                  - line: assert error line source number
* Output         : None
* Return         : None
*******************************************************************************/
void assert_failed(u8* file, u32 line)
{
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  /* Infinite loop */
  while (1)
  {
  }
}
#endif

/*******************************************************************************
* Function Name  : Delay
* Description    : Inserts a delay time.
* Input          : nCount: specifies the delay time length.
* Output         : None
* Return         : None
*******************************************************************************/
void Delay(vu32 nCount)
{
  for(; nCount!= 0;nCount--);
}

/******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/

出0入0汤圆

 楼主| 发表于 2008-8-12 11:42:20 | 显示全部楼层
这就对了啊.谢谢Grant.
以前做伪PLC,AVR真的很不合适,一直寻找能有价格便宜一些片上功能不需要很强大的单时钟51核.
现在STM32可以圆这个等待了2年的梦.有Bit Band,等于从硬件上就支持位操作.

出0入0汤圆

发表于 2008-9-3 11:36:51 | 显示全部楼层
MDK3.22软仿真没问题
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-5 10:13

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表