gonzui


Format: Advanced Search

mtkernel_3/kernel/sysdepend/iote_stm32l4/hw_setting.cbare sourcepermlink (0.02 seconds)

Search this content:

    1: /*
    2:  *----------------------------------------------------------------------
    3:  *    micro T-Kernel 3.00.03
    4:  *
    5:  *    Copyright (C) 2006-2021 by Ken Sakamura.
    6:  *    This software is distributed under the T-License 2.2.
    7:  *----------------------------------------------------------------------
    8:  *
    9:  *    Released by TRON Forum(http://www.tron.org) at 2021/03/31.
   10:  *
   11:  *----------------------------------------------------------------------
   12:  */
   13: 
   14: #include <sys/machine.h>
   15: #ifdef IOTE_STM32L4
   16: 
   17: /*
   18:  *      hw_setting.c (STM32L4 IoT-Engine)
   19:  *      startup / shoutdown processing for hardware
   20:  */
   21: 
   22: #include "kernel.h"
   23: #include <tm/tmonitor.h>
   24: 
   25: #include "sysdepend.h"
   26: 
   27: /* 
   28:  * Setup register data 
   29:  */
   30: typedef struct {
   31:         UW     addr;
   32:         UW     data;
   33: } T_SETUP_REG;
   34: 
   35: /*
   36:  * Setup module clock
   37:  */
   38: LOCAL const T_SETUP_REG modclk_tbl[] = {
   39: 
   40: #if !USE_SDEV_DRV       // Do not use sample device driver
   41:         {RCC_AHB2ENR,          0x00000008},    // GPIO-D enable
   42:         {RCC_APB1ENR1,         0x0002000F},   // USART2, TIM2-TIM5 enable
   43:         {RCC_APB2ENR,          0x00000001},    // SYSCFG enable
   44: 
   45: #else                   // Use the sample device driver
   46:         {RCC_AHB2ENR,          0x0000000B},    // GPIO-A, B, D enable
   47:         {RCC_APB1ENR1,         0x0002000F},   // USART2, TIM2-TIM5 enable
   48:         {RCC_APB2ENR,          0x00000001},    // SYSCFG enable
   49: #endif /* !USE_SDEV_DRV */
   50: 
   51:         {0, 0}
   52: };
   53: 
   54: /* 
   55:  * Setup pin functions Tadle
   56:  */
   57: LOCAL const T_SETUP_REG pinfnc_tbl[] = {
   58: 
   59: #if !USE_SDEV_DRV       // Do not use device sample driver
   60:         // Serial debug I/F : PD5 -> USART2_TX, PD6 -> USART2_RX
   61:         {GPIO_MODER(D),                0x00002800},
   62:         {GPIO_OTYPER(D),       0x00000000},
   63:         {GPIO_OSPEEDR(D),      0x00001400},
   64:         {GPIO_PUPDR(D),                0x00001400},
   65:         {GPIO_AFRH(D),         0x00000000},
   66:         {GPIO_AFRL(D),         0x07700000},
   67: 
   68: #else                   // Use the device sample driver
   69:         // A/DC in: PA1,PA2,PA4
   70:         {GPIO_MODER(A),                0xABFFFFFF},
   71:         {GPIO_OTYPER(A),       0x00000000},
   72:         {GPIO_OSPEEDR(A),      0x0C0F0000},
   73:         {GPIO_PUPDR(A),                0x64050000},
   74:         {GPIO_AFRL(A),         0x00000000},
   75:         {GPIO_AFRH(A),         0x00000000},
   76:         {GPIO_ASCR(A),         0x00000016},   
   77: 
   78:         // I2C I/F : PB8 -> I2C1_SCL, PB9 -> I2C1_SDA
   79:         // A/DC in : PB1
   80:         {GPIO_MODER(B),                0xFFFAFFBF},
   81:         {GPIO_OTYPER(B),       0x00000300},
   82:         {GPIO_OSPEEDR(B),      0x000F0000},
   83:         {GPIO_PUPDR(B),                0x00050100},
   84:         {GPIO_AFRL(B),         0x00000000},
   85:         {GPIO_AFRH(B),         0x00000044},
   86:         {GPIO_ASCR(B),         0x00000002},
   87: 
   88:         // Serial debug I/F : PD5 -> USART2_TX, PD6 -> USART2_RX
   89:         // Port Output : PD9, PD11, PD15
   90:         {GPIO_MODER(D),                0x40442800},
   91:         {GPIO_OTYPER(D),       0x00000000},
   92:         {GPIO_OSPEEDR(D),      0x00001400},
   93:         {GPIO_PUPDR(D),                0x00001400},
   94:         {GPIO_AFRL(D),         0x00000000},
   95:         {GPIO_AFRL(D),         0x07700000},
   96: 
   97: #endif /* USE_SDEV_DRV */
   98: 
   99:         {0, 0}
  100: };
  101: 
  102: /*
  103:  * Startup Device
  104:  */
  105: EXPORT void knl_startup_hw(void)
  106: {
  107:         const T_SETUP_REG      *p;
  108: 
  109:         startup_clock(CLKATR_HSE | CLKATR_USE_PLL | CLKATR_LATENCY_4);
  110: 
  111:         /* Startup module clock */
  112:         for(p = modclk_tbl; p->addr != 0; p++) {
  113:                 *(_UW*)(p->addr) = p->data;
  114:                 while(*(_UW*)(p->addr) != p->data);
  115:         }
  116: 
  117:         /* Setup Pin Function */
  118:         for(p = pinfnc_tbl; p->addr != 0; p++) {
  119:                 *(_UW*)(p->addr) = p->data;
  120:         }
  121: }
  122: 
  123: #if USE_SHUTDOWN
  124: /*
  125:  * Shutdown device
  126:  */
  127: EXPORT void knl_shutdown_hw( void )
  128: {
  129:         disint();
  130:         while(1);
  131: }
  132: #endif /* USE_SHUTDOWN */
  133: 
  134: /*
  135:  * Re-start device
  136:  *      mode = -1            reset and re-start        (Reset -> Boot -> Start)
  137:  *      mode = -2            fast re-start             (Start)
  138:  *      mode = -3            Normal re-start           (Boot -> Start)
  139:  */
  140: EXPORT ER knl_restart_hw( W mode )
  141: {
  142:         switch(mode) {
  143:         case -1: /* Reset and re-start */
  144:                 SYSTEM_MESSAGE("\n<< SYSTEM RESET & RESTART >>\n");
  145:                 return E_NOSPT;
  146:         case -2: /* fast re-start */
  147:                 SYSTEM_MESSAGE("\n<< SYSTEM FAST RESTART >>\n");
  148:                 return E_NOSPT;
  149:         case -3: /* Normal re-start */
  150:                 SYSTEM_MESSAGE("\n<< SYSTEM RESTART >>\n");
  151:                 return E_NOSPT;
  152:         default:
  153:                 return E_PAR;
  154:         }
  155: }
  156: 
  157: 
  158: #endif /* IOTE_STM32L4 */