zstack -Serial Boot Loader(串口下程序)

 
一直想同归串口给CC2530下程序,就看了一下官方的文档。里面讲的不是太详细,加上自己英语也不好。理解不了,胡乱瞎搞了两天,就成功了。今天做下总结.

  1 首先打开$INSTALL_DIR$\Projects\zstack\Utilities\BootLoad\CC253x\Boot.eww。就是boot文件。

       

打开


编译看有没有错误,有可能出现

Error[e72]: Segment PDATA_Z must be defined in a segment definition option (-Z, -b or -P)

我在网上找到了解决方法;http://feibit.com/forum.php?mod=viewthread&tid=9459

没有错误就可以下载进去了CC2530


第二部分,生成bin文件,

TI给的文档很详细,照着做就行了。有三点要注意

1 TI给的3条命令要修改成自己的名字(第一条不改) 命令之间加空格

"$PROJ_DIR$\..\..\..\Tools\CC2530DB\oad.exe" 

"$PROJ_DIR$\RouterEB\Exe\GenericApp.sim"

 "$PROJ_DIR$\RouterEB\Exe\GenericApp.bin"


2定义关键字MAKE_CRC_SHDW


3. CRC Shadow 把他改成一样


最后连好串口,打开官方下载软件就下载成功了




下载进去就会发现第一次可以跳转。重启之后就不行了。这是因为有两个按键控制的跳转。



/**************************************************************************************************
 * @fn          main
 *
 * @brief       C-code main functionality.
 *
 * input parameters
 *
 * None.
 *
 * output parameters
 *
 * None.
 *
 * @return      None.
 **************************************************************************************************
 */
void main(void)
{
  vddWait(VDD_MIN_RUN);//检查电压
  HAL_BOARD_INIT();//初始化时钟,按键 P0_1 p2-0

  if (sbImgValid()) //代码是否有效 CRC Shadow 匹配
  {
    if ((SB_UART_DELAY == 0) || ResetWasWatchDog)//看门狗复位就会直接跳转到代码区(上电只执行一次串口下载)
    {
      sblJump();//接跳转到代码区
    }

    sblInit();//初始化串口
    sblWait();//跳转等待
  }
  else
  {
    sblInit();//初始化串口
  }

  vddWait(VDD_MIN_NV);//检查写flsh电压
  sblExec();//写入代码
  HAL_SYSTEM_RESET();
}

/**************************************************************************************************
 * @fn          sblExec
 *
 * @brief       Infinite SBL execute loop that jumps upon receiving a code enable.
 *
 * input parameters
 *
 * None.
 *
 * output parameters
 *
 * None.
 *
 * @return      None.
 **************************************************************************************************
 */
static void sblExec(void)
{
  uint32 dlyCnt = 0;

  while (1)
  {
    HalUARTPollISR();

    if (sbExec() && sbImgValid())
    {
      SB_TURN_ON_LED1();
      SB_TURN_ON_LED2();
      // Delay to allow the SB_ENABLE_CMD response to be flushed.
      for (dlyCnt = 0; dlyCnt < 0x40000; dlyCnt++)
      {
        HalUARTPollISR();//串口写代码
      }

      sblJump();//跳转
    }
    else if (dlyCnt++ & 0x4000)
    {
      SB_TOGGLE_LED1();
    }
  }
}

/**************************************************************************************************
 * @fn          sblInit
 *
 * @brief       SBL initialization.
 *
 * input parameters
 *
 * None.
 *
 * output parameters
 *
 * None.
 *
 * @return      None.
 */
static void sblInit(void)
{
  halUARTCfg_t uartConfig;
  /* This is in place of calling HalDmaInit() which would require init of the other 4 DMA
   * descriptors in addition to just Channel 0.
   */
  HAL_DMA_SET_ADDR_DESC0(&dmaCh0);

  HalUARTInitISR();
  uartConfig.configured           = TRUE;
  uartConfig.baudRate             = HAL_UART_BR_115200;
  uartConfig.flowControl          = FALSE;
  uartConfig.flowControlThreshold = 0;  // CC2530 by #define - see hal_board_cfg.h
  uartConfig.rx.maxBufSize        = 0;  // CC2530 by #define - see hal_board_cfg.h
  uartConfig.tx.maxBufSize        = 0;  // CC2530 by #define - see hal_board_cfg.h
  uartConfig.idleTimeout          = 0;  // CC2530 by #define - see hal_board_cfg.h
  uartConfig.intEnable            = TRUE;
  uartConfig.callBackFunc         = NULL;
  HalUARTOpenISR(&uartConfig);

  SB_INIT_LEDS();
}

/**************************************************************************************************
 * @fn          sblJump
 *
 * @brief       Execute a simple long jump from non-banked SBL code to non-banked RC code space.
 *
 * input parameters
 *
 * None.
 *
 * output parameters
 *
 * None.
 *
 * @return      None.
 */
static void sblJump(void)
{
  SB_TURN_ON_LED1();
  SB_TURN_ON_LED2();
 // while (SB1_PRESS || SB2_PRESS);判断按键
  SB_TURN_OFF_LED1();
  SB_TURN_OFF_LED2();
  asm("LJMP 0x2000\n");  // Immediate jump to run-code.
  HAL_SYSTEM_RESET();//复位
}

/**************************************************************************************************
 * @fn          sblWait
 *
 * @brief       A timed-out wait loop that exits early upon receiving a force code/sbl byte.
 *
 * input parameters
 *
 * None.
 *
 * output parameters
 *
 * None.
 *
 * @return      None.
 **************************************************************************************************
 */
static void sblWait(void)
{
  uint32 dlyCnt = SB_UART_DELAY;

  while (1)
  {
    uint8 ch;

    HalUARTPollISR();//读串口数据,等待命令。
    if (HalUARTReadISR(&ch, 1))
    {
      if (ch == SB_FORCE_BOOT)
      {
        break;
      }
      else if (ch == SB_FORCE_RUN)
      {
        dlyCnt = 0;
      }
    }

    if (SB1_PRESS)//如果P0_1为高就跳出(进入下载模式)
    {
      break;
    }

    if(SB2_PRESS || (dlyCnt-- == 0)) //(  (dlyCnt-- == 0)) P2_0位高或者等待1分到就跳转
    {
      sblJump();
    }

    // RR-xing LED display while waiting.
    if (dlyCnt & 0x2000)
    {
      SB_TURN_OFF_LED2();
      SB_TURN_ON_LED1();
    }
    else
    {
      SB_TURN_OFF_LED1();
      SB_TURN_ON_LED2();
    }
  }

  SB_TURN_OFF_LED1();
  SB_TURN_OFF_LED2();
}

/**************************************************************************************************
 * @fn          vddWait
 *
 * @brief       Loop waiting for 16 reads of the Vdd over the requested limit.
 *
 * input parameters
 *
 * @param       vdd - Vdd level to wait for.
 *
 * output parameters
 *
 * None.
 *
 * @return      None.
 **************************************************************************************************
 */
static void vddWait(uint8 vdd)
{
  uint8 cnt = 16;

  do {
    do {
      ADCCON3 = 0x0F;
      while (!(ADCCON1 & 0x80));
    } while (ADCH < vdd);
  } while (--cnt);
}

/**************************************************************************************************
*/


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值