打印
[STM8]

stm8s的cpu不能工作到24MHz吗?

[复制链接]
4832|8
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
ifree64|  楼主 | 2009-5-19 13:25 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
测试程序如下:

#include "stm8s.h"

void CLK_Init(void)
{
    /* Configure clock prescaler */
    CLK->CKDIVR = 0x01;          /* To be programmed with different value */
                                 /* Fmaster, Fmaster/1, ...               */
    /* To select external source by automtic switch */
    CLK->SWCR |= 0x02;            /* Enable switch */
    CLK->SWR   = 0xB4;            /* Select HSE */
        
    while (!(CLK->SWCR & 0x08));  /* Wait for switch done */
        
        /* verify the external clock is selected (optional) */
    if (CLK->CMSR != 0xB4)        
            while(1);
    
    CLK->CSSR |= 0x01; 
}
/* Private defines -----------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
#define LEDS_PORT (GPIOD)
#define LED1_PIN  (GPIO_PIN_0)
#define LED2_PIN  (GPIO_PIN_2)
#define LED3_PIN    (GPIO_PIN_3)

void Delay(u16 nCount)
{
  /* Decrement nCount value */
  while (nCount != 0)
  {
    nCount--;
  }
}

int main(void)
{
  u8 Leds = LED1_PIN|LED2_PIN|LED3_PIN; /* Contains which LEDs to operate */

    u8 t = 10;
    /* Initialize I/Os in Output Mode */
  GPIO_Init(LEDS_PORT, (LED1_PIN | LED2_PIN | LED3_PIN ), GPIO_MODE_OUT_PP_LOW_FAST);
    
// 这里是用启动后默认的16MHz(HSI)/8=2MHz时钟工作
    while (t--)
  {
    /* LEDs ON */
    GPIO_WriteHigh(LEDS_PORT, Leds);
    Delay((u16)60000);
    Delay((u16)60000);
    /* LEDs OFF */
    GPIO_WriteLow(LEDS_PORT, Leds);
    Delay((u16)60000);
    Delay((u16)60000);
  }

    CLK_Init();
    t=10;
// 切换到HSE 24MHz晶振,FCPU=FMASTER/2,正常工作,LED闪烁变快了
    while (t--)
  {
    /* LEDs ON */
    GPIO_WriteHigh(LEDS_PORT, Leds);
    Delay((u16)60000);
    Delay((u16)60000);
    /* LEDs OFF */
    GPIO_WriteLow(LEDS_PORT, Leds);
    Delay((u16)60000);
    Delay((u16)60000);
  }

    CLK->CKDIVR = 0X00;
// 切换到FCPU=FMASTER/1 24MHz,不工作,看上去是很快系统复位了。
  while (1)
  {
    /* LEDs ON */
    GPIO_WriteHigh(LEDS_PORT, Leds);
    Delay((u16)60000);
    Delay((u16)60000);
    /* LEDs OFF */
    GPIO_WriteLow(LEDS_PORT, Leds);
    Delay((u16)60000);
    Delay((u16)60000);
  }

}

实验板是STM8 MINI KIT
沙发
ifree64|  楼主 | 2009-5-19 13:28 | 只看该作者

用16MHz的外部晶振就可以看到3个阶段的LED闪烁越来越快

使用特权

评论回复
板凳
汉之云| | 2009-5-19 14:19 | 只看该作者

option byte中wait state要等于1

STM8的flash标称最高速度是16M,主频跑24M时,在FLASH中运行程序需要插1个等待周期

使用特权

评论回复
地板
ifree64|  楼主 | 2009-5-19 14:45 | 只看该作者

STM8flash标称16M是在那个文件中提到的?怎么插1个等待周期?

使用特权

评论回复
5
汉之云| | 2009-5-19 15:14 | 只看该作者

datasheet 里有的

STM8S207的datasheet 
第一页:
Max fCPU: up to 24 MHz,
0 wait states @ fCPU≤16 MHz

第六章option bytes:
OPT7
WAITSTATE Wait state configuration
This option configures the number of wait states inserted when reading
from the Flash/data EEPROM memory.
1 wait state is required if fCPU > 16 MHz.
0: No wait state
1: 1 wait state

要烧option bytes,可以用STVP(STVD伴侣,你肯定安装了)
https://bbs.21ic.com/upfiles/img/20095/200951915846233.jpg

使用特权

评论回复
6
ifree64|  楼主 | 2009-5-19 15:41 | 只看该作者

谢谢汉之云,问题解决了。

在读Flash中插入1个等待周期后,即便将CPU的工作频率提高到24MHz,获取指令的速度反而低于16MHz的主频;另一方面,FLASH数据总线的宽度是32位,一次获取4个字节,那么将cpu工作频率提高到24Mhz有可能提高性能吗?



使用特权

评论回复
7
汉之云| | 2009-5-19 15:53 | 只看该作者

有的

STM8三级流水线,外带3个buffer,在顺序执行时一般不会有流水线STALL情况,但如果非常频繁地跳转和中断,流水线和buffer经常清空和就不一定了.

STM8的官方培训资料上有几个图,专门说这一点的.哪位兄弟有,给贴个图?

使用特权

评论回复
8
ifree64|  楼主 | 2009-5-19 16:08 | 只看该作者

官方培训资料那里有下载?

使用特权

评论回复
9
汉之云| | 2009-5-19 21:14 | 只看该作者

嗯,看上去挺像的

应该在前面部分

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

12

主题

159

帖子

0

粉丝