本帖最后由 lhc960818 于 2019-9-9 14:21 编辑

1.概述
看到网友很多都搭建了开放环境来编写,本人一直是在keil的环境下编写,所以这次还是使用keil来完成
2.新建工程
2.1先从东芝的官网上下载TMPM3Hy_v1.2.0软件包,里面包含了底层驱动和实例代码,因为keil下载拓展包的速度太慢了,所以我从网上下了东芝的拓展包
微信图片_20190909094500.png
微信图片_20190909094515.png
2.2在Project菜单下,选择New uVision Project,选择需要保存的目录和文件名
微信图片_20190909094938.png
2.3选择芯片的驱动,这里选择toshiba目录下的M3H(2)的TMPM3HQFDFG
微信图片_20190909095114.png
2.4Mange Run菜单下的CORE记得勾选
微信图片_20190909095307.png
3.点亮LED事例
对LED6进行亮灭操作
微信图片_20190909100133.jpg
#ifdef __cplusplus
  • extern "C" {
  • #endif
  • /*------------------------------------------------------------------------------*/
  • /*  Includes                                                                    */
  • /*------------------------------------------------------------------------------*/
  • #include <stdio.h>
  • #include "txz_sample_def.h"
  • #include "bsp.h"
  • #include "lvd.h"
  • #include "bsp_led.h"
  • #include "bsp_timer.h"
  • /**
  • *  @addtogroup Example
  • *  @{
  • */
  • /**
  • *  @defgroup LVD_DEMO LVD_DEMO Sample Appli
  • *  @{
  • */
  • /*------------------------------------------------------------------------------*/
  • /*  Macro Function                                                              */
  • /*------------------------------------------------------------------------------*/
  • /**
  • *  @defgroup LVD_DEMO_Private_macro LVD_DEMO Private Macro
  • *  @{
  • */
  • /*----------------------*/
  • /*  UART Setting        */
  • /*----------------------*/
  • /**
  • *  @defgroup LEDBlinkConfiguration LED Blink Time Configuration
  • *  @brief    LED Blink Interval Time(ms).
  • *  @{
  • */
  • #define CFG_LED_BLINK_TIME      ((uint32_t)(1000))
  • /**
  • *  @}
  • */ /* End of group LEDBlinkConfiguration */
  • #define MAIN_NULL       ((void *)0)     /*!< NULL. */
  • #define USER_ID_REMOTE  ((uint32_t)0)   /*!< User ID :Remote Control (Any value) */
  • /**
  • *  @}
  • */ /* End of group LVD_DEMO_Private_macro */
  • /*------------------------------------------------------------------------------*/
  • /*  Configuration                                                               */
  • /*------------------------------------------------------------------------------*/
  • /**
  • *  @defgroup LVD_DEMO_Private_define LVD_DEMO Private Define
  • *  @{
  • */
  • /* no define */
  • /**
  • *  @}
  • */ /* End of group LVD_DEMO_Private_define */
  • /*------------------------------------------------------------------------------*/
  • /*  Macro Definition                                                            */
  • /*------------------------------------------------------------------------------*/
  • /**
  • *  @defgroup LVD_DEMO_Private_define LVD_DEMO Private Define
  • *  @{
  • */
  • #define LVD_UPPER               ((uint32_t)0x00000000)  /*!< LVD UPPER */
  • #define LVD_LOWER               ((uint32_t)0x00000001)  /*!< LVD LOWER */
  • #define CG_OSCF_EHOSC           ((uint32_t)0x00000200)  /*!< CG External high-speed oscillator status. */
  • #define CG_OSCF_IHOSC           ((uint32_t)0x00000000)  /*!< CG Internal high-speed oscillator status. */
  • #define CG_WAIT_TIME            ((uint32_t)0x00100000)  /*!< CG change wait time. */
  • #define CG_EHOSCEN_ENABLE       ((uint32_t)0x00000002)  /*!< CG EHOSCEN enable. */
  • #define CG_EHOSCEN_DISABLE      ((uint32_t)0x00010003)  /*!< CG EHOSCEN disable. */
  • #define CG_IHOSC_SEL            ((uint32_t)0x00010003)  /*!< CG Internal high-speed oscillator select. */
  • #define CG_EHOSC_SEL            ((uint32_t)0x00000100)  /*!< CG External high-speed oscillator select. */
  • #define CG_IHOSC_DISABLE        ((uint32_t)0xFFFFFFFE)  /*!< Internal high-speed oscillator disable */
  • #define LVD_STATUS_CT       ((uint32_t)0x00000008)      /*!< LVD status count         */
  • #define LVD_ST_MASK         ((uint32_t)0x00000080)      /*!< LVD ST mask              */
  • #define LVD_SHIFT           ((uint32_t)0x00000007)      /*!< LVD shift                */
  • /**
  • *  @}
  • */ /* End of group LVD_DEMO_Private_define */
  • /*------------------------------------------------------------------------------*/
  • /*  Enumerated Type Definition                                                  */
  • /*------------------------------------------------------------------------------*/
  • /**
  • *  @defgroup LVD_DEMO_Private_define LVD_DEMO Private Define
  • *  @{
  • */
  • /* No Define */
  • /**
  • *  @}
  • */ /* End of group LVD_DEMO_Private_define */
  • /*------------------------------------------------------------------------------*/
  • /*  Structure Definition                                                        */
  • /*------------------------------------------------------------------------------*/
  • /**
  • *  @defgroup LVD_DEMO_Private_typedef LVD_DEMO Private Typedef
  • *  @{
  • */
  • /*----------------------------------*/
  • /**
  • * @brief Instance Information.
  • */
  • /*----------------------------------*/
  • typedef struct
  • {
  •     gpio_t      gpio_obj;            /*!< Application :GPIO. */
  •     led_t       led[(uint32_t)BSP_LED_MAX]; /*!< Application :LED                */
  •     t32a_t      t32a;                       /*!< Driver      :T32A               */
  •     timer_t     timer;                      /*!< Application :Timer (1ms timer). */
  • } instance_t;
  • /**
  • *  @}
  • */ /* End of group LVD_DEMO_Private_typedef */
  • /*------------------------------------------------------------------------------*/
  • /*  Private Member                                                              */
  • /*------------------------------------------------------------------------------*/
  • /**
  • *  @addtogroup LVD_Private_variables
  • *  @{
  • */
  • static instance_t instance; /*!< Instance.                    */
  • uint32_t lvd_status_now;                /*!< LVD status now           */
  • uint32_t lvd_status_old;                /*!< LVD status old           */
  • uint32_t lvd_status_count = 0;          /*!< LVD status count         */
  • uint32_t lvd_status = LVD_UPPER;        /*!< LVD status               */
  • TXZ_Result retval = TXZ_ERROR;          /*!< LVD get status result    */
  • /**
  • *  @}
  • */ /* End of group LVD_Private_variables */
  • /*------------------------------------------------------------------------------*/
  • /*  Private Function                                                            */
  • /*------------------------------------------------------------------------------*/
  • /**
  • *  @defgroup LVD_DEMO_Private_fuctions LVD_DEMO Private Fuctions
  • *  @{
  • */
  • static void variable_initialize(void);
  • static void timer_interval_handler(uint32_t id);
  • static TXZ_Result driver_initialize(void);
  • static TXZ_Result application_initialize(void);
  • /*--------------------------------------------------*/
  • /**
  •   * @brief  Variable Initialize
  •   * @param  -
  •   * @return -
  •   * @retval -
  •   * @note   -
  •   */
  • /*--------------------------------------------------*/
  • static void variable_initialize(void)
  • {
  •     /* Instance. */
  •     instance.t32a.p_instance    = MAIN_NULL;
  •     instance.timer.init.p_t32a  = MAIN_NULL;
  •     {
  •         uint32_t i;
  •     /* Instance. */
  •         for (i=0; i<(uint32_t)BSP_LED_MAX; i++)
  •         {
  •             instance.led[i].init.p_gpio = MAIN_NULL;
  •         }
  •     }
  • }
  • /*--------------------------------------------------*/
  • /**
  •   * @brief  Interval Time Handler.
  •   * @param  id :User ID
  •   * @return -
  •   * @retval -
  •   * @note   for 1ms Timer.
  •   * @note   Call by Timer.
  •   */
  • /*--------------------------------------------------*/
  • static void timer_interval_handler(uint32_t id)
  • {
  •     if (id == (uint32_t)&instance.timer)
  •     {
  •         uint32_t i;
  •         /*----------------------*/
  •         /* Tick                 */
  •         /*----------------------*/
  •         /* Increment Tick. Tick is used to driver's Timeout. */
  •         hal_inc_tick();
  •         /*----------------------*/
  •         /* LED                  */
  •         /*----------------------*/
  •         for (i=0; i<(uint32_t)BSP_LED_MAX; i++)
  •         {
  •             led_1ms_timer_handler(&instance.led[i]);
  •         }
  •     }
  • }
  • /*--------------------------------------------------*/
  • /**
  •   * @brief  Driver Initialize
  •   * @param  -
  •   * @return Result.
  •   * @retval TXZ_SUCCESS :Success.
  •   * @retval TXZ_ERROR   :Failure.
  •   * @note   for Normal Mode
  •   */
  • /*--------------------------------------------------*/
  • static TXZ_Result driver_initialize(void)
  • {
  •     TXZ_Result result = TXZ_SUCCESS;
  •     /*----------------------*/
  •     /* GPIO                 */
  •     /*----------------------*/
  •     /* Driver initialize has done within BSP. */
  •     /*----------------------*/
  •     /* T32A                 */
  •     /*----------------------*/
  •     {
  •         t32a_t *p_t32a = &instance.t32a;
  •         /*--- Construct  ---*/
  •         /* Register Allocation */
  •         switch (bsp_get_timer_ch(BSP_TIMER_1MS))
  •         {
  •         case 0:
  •             p_t32a->p_instance = TSB_T32A0;
  •             break;
  •         case 1:
  •             p_t32a->p_instance = TSB_T32A1;
  •             break;
  •         case 2:
  •             p_t32a->p_instance = TSB_T32A2;
  •             break;
  •         case 3:
  •             p_t32a->p_instance = TSB_T32A3;
  •             break;
  •         case 4:
  •             p_t32a->p_instance = TSB_T32A4;
  •             break;
  •         case 5:
  •             p_t32a->p_instance = TSB_T32A5;
  •             break;
  •         default:
  •             p_t32a->p_instance = MAIN_NULL;
  •             break;
  •         }
  •         /*--- Initialize ---*/
  •         p_t32a->init_mode.mode.halt = T32A_DBG_HALT_STOP;
  •         p_t32a->init_mode.mode.mode = T32A_MODE_16;
  •         if (t32a_mode_init(p_t32a) != TXZ_SUCCESS)
  •         {
  •             result = TXZ_ERROR;
  •         }
  •     }
  •     return (result);
  • }
  • /*--------------------------------------------------*/
  • /**
  •   * @brief  Application Initialize.
  •   * @param  -
  •   * @return Result.
  •   * @retval TXZ_SUCCESS :Success.
  •   * @retval TXZ_ERROR   :Failure.
  •   * @note   -
  •   */
  • /*--------------------------------------------------*/
  • static TXZ_Result application_initialize(void)
  • {
  •    TXZ_Result result = TXZ_SUCCESS;
  •     /*----------------------*/
  •     /* Timer                */
  •     /*----------------------*/
  •     /* 1ms timer */
  •     {
  •         timer_t *p_timer = &instance.timer;
  •         p_timer->init.id       = (uint32_t)&instance.timer;
  •         p_timer->init.p_t32a   = &instance.t32a;
  •         p_timer->init.type     = bsp_get_timer_type(BSP_TIMER_1MS);
  •         p_timer->init.irq      = bsp_get_timer_nvic(BSP_TIMER_1MS);
  •         p_timer->init.interval = 1000;
  •         p_timer->init.handler  = timer_interval_handler;
  •         timer_initialize(p_timer);
  •     }
  •     /*----------------------*/
  •     /* LED                  */
  •     /*----------------------*/
  •     {
  •         uint32_t i;
  •         led_t *p_led = MAIN_NULL;
  •         
  •         for (i=0; i<(uint32_t)BSP_LED_MAX; i++)
  •         {
  •             p_led = &instance.led[i];
  •             p_led->init.id          = (uint32_t)p_led;
  •             p_led->init.p_gpio      = bsp_get_gpio_instance_address();
  •             p_led->init.port.group  = bsp_get_gpio_group_led((BSPLed)(i));
  •             p_led->init.port.num    = bsp_get_gpio_num_led((BSPLed)(i));
  •             /* LED0 :blinking */
  •             if (i == 0)
  •             {
  •                 p_led->init.state               = LED_STATE_OFF;
  •                 p_led->init.blink.func          = TXZ_ENABLE;
  •                 p_led->init.blink.interval.on   = CFG_LED_BLINK_TIME;
  •                 p_led->init.blink.interval.off  = CFG_LED_BLINK_TIME;
  •             }
  •             /* default    :off      */
  •             else
  •             {
  •                 p_led->init.state               = LED_STATE_OFF;
  •                 p_led->init.blink.func          = TXZ_DISABLE;
  •                 p_led->init.blink.interval.on   = 0;
  •                 p_led->init.blink.interval.off  = 0;
  •             }
  •             led_initialize(p_led);
  •         }
  •     }
  •     return (result);
  • }
  • /**
  • *  @}
  • */ /* End of group LVD_DEMO_Private_fuctions */
  • /*------------------------------------------------------------------------------*/
  • /*  Public Function                                                             */
  • /*------------------------------------------------------------------------------*/
  • /**
  • *  @defgroup LVD_DEMO_Exported_functions LVD_DEMO Exported Functions
  • *  @{
  • */
  • /*--------------------------------------------------*/
  • /**
  •   * @brief  Main Function.
  •   * @param  -
  •   * @retval -
  •   * @note   -
  •   */
  • /*--------------------------------------------------*/
  • int main(void)
  • {
  •     uint32_t time = 0;
  •     uint32_t i;
  •     led_t *p_led = MAIN_NULL;
  •     /*----------------------*/
  •     /* BSP initialize       */
  •     /*----------------------*/
  •     bsp_initialize();
  •     /* Valiable initialization */
  •     variable_initialize();
  •     /* Driver initialization */
  •     if(driver_initialize() != TXZ_SUCCESS)
  •     {
  •     }
  •     /* Application initialization */
  •     if(application_initialize() != TXZ_SUCCESS)
  •     {
  •     }
  •     /*----------------------*/
  •     /* 1ms Timer Start      */
  •     /*----------------------*/
  •     timer_start(&instance.timer);   
  •     /* Select external high-speed oscillator */
  •     TSB_CG->OSCCR |= CG_EHOSCEN_ENABLE;
  •     TSB_CG->OSCCR |= CG_EHOSC_SEL;
  •     while(TSB_CG_OSCCR_OSCF == CG_OSCF_IHOSC)
  •     {
  •         time++;
  •         if(time >= CG_WAIT_TIME)
  •         {
  •             /* System Error. Please Debug. */
  •             #ifdef DEBUG
  •             assert_failed(MAIN_NULL, 0);
  •             #endif
  •         }
  •     }
  •     /* ihosc disable */
  •     TSB_CG->OSCCR &= CG_IHOSC_DISABLE;
  •     init_LVD();
  •     start_LVD();
  •     for(;;){
  •         retval = TXZ_ERROR;
  •         /*----------------------*/
  •         /* LED                                */
  •         /*----------------------*/
  •         for (i=0; i<(uint32_t)BSP_LED_MAX; i++)
  •         {
  •             led_task(&instance.led[i]);
  •         }
  •         /*----------------------*/
  •         /* LVD Status Check            */
  •         /*----------------------*/
  •         lvd_status_now = (uint32_t)((TSB_LVD->CR & LVD_ST_MASK) >> LVD_SHIFT);
  •         if(lvd_status_now == lvd_status_old)
  •         {
  •             lvd_status_count++;
  •             if(lvd_status_count >= LVD_STATUS_CT)
  •             {
  •                 if(lvd_status != lvd_status_now)
  •                 {
  •                     lvd_status = lvd_status_now;
  •                     retval = TXZ_SUCCESS;
  •                 }
  •                 lvd_status_count = 0;
  •             }
  •         }
  •         else
  •         {
  •             lvd_status_old = lvd_status_now;
  •             lvd_status_count = 0;
  •         }
  •         if(retval == TXZ_SUCCESS)
  •         {
  •             if(lvd_status == LVD_UPPER)
  •             {
  •                 /* LED0 Turn OFF */
  •                 instance.led[0].init.blink.func = TXZ_DISABLE;
  •                 p_led = &instance.led[0];
  •                 led_turn_off(p_led);
  •                 /* LED1 Turn ON */
  •                 p_led = &instance.led[1];
  •                 led_turn_on(p_led);
  •             }
  •             else
  •             {
  •                  /* LED1Turn OFF */
  •                 p_led = &instance.led[1];
  •                 led_turn_off(p_led);
  •                 /* LED0 Blink */
  •                 instance.led[0].init.blink.func = TXZ_ENABLE;
  •                 p_led = &instance.led[0];
  •                 led_turn_on(p_led);
  •             }
  •         }
  •         else
  •         {
  •             /* do nothing */
  •         }
  •     }
  • }
  • /*--------------------------------------------------*/
  • /**
  •   * @brief  1ms Timer.
  •   * @param  timer :1ms Timer.
  •   * @return -
  •   * @retval -
  •   * @note   This function is called BSP.
  •   */
  • /*--------------------------------------------------*/
  • void irq_timer(BSPTimer timer)
  • {
  •     switch (timer)
  •     {
  •     case BSP_TIMER_1MS:
  •         timer_irq_handler(&instance.timer);
  •         break;
  •     default:
  •         /* no processing */
  •         break;
  •     }
  • }
  • #ifdef DEBUG
  • /*--------------------------------------------------*/
  • /**
  •   * @brief  Failure Assert.
  •   * @note   for debug
  •   */
  • /*--------------------------------------------------*/
  • void assert_failed(char *file, int32_t line)
  • {
  •     while (1) {
  •         __nop();
  •     }
  • }
  • #endif
  • /**
  • *  @}
  • */ /* End of group LVD_DEMO_Exported_functions */
  • /**
  • *  @}
  • */ /* End of group LVD_DEMO */
  • /**
  • *  @}
  • */ /* End of group Example */
  • #ifdef __cplusplus
  • }
  • #endif /* __cplusplus */
  • 复制代码
    4.心得体会由于临时项目,时间太紧张,简略的了解了一下东芝的开发板,总体来说M3HQ上的资源还是很丰富的,事例代码上的标注也很清晰,闲下来之后会花费更多的时间来学习,在之后的时间里会再更新一些利用开发板做的项目
    参考附件:
    1.东芝的底层驱动和事例代码
    TMPM3Hy_v1.2.0.zip (15.57 MB, 下载次数: 4)
    举报
    内容系网友发布,其中涉及到安全隐患的内容系网友个人行为,不代表面包板社区观点
    请点击举报理由
    关闭 站长推荐上一条 /4 下一条
    • 返回顶部