Commit 504af998 authored by Adam Valt's avatar Adam Valt 😴
Browse files

Merge branch 'controller' into 'develop'

Add support for controller

See merge request !1
parents 5eee2303 b43c3bfd
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -33,11 +33,11 @@
/* clang-format off */
/* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
!!GlobalInfo
product: Clocks v12.0
product: Clocks v11.0
processor: MK66FN2M0xxx18
package_id: MK66FN2M0VMD18
mcu_data: ksdk2_0
processor_version: 14.0.0
processor_version: 13.0.1
board: FRDM-K66F
 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
/* clang-format on */
+209 −101
Original line number Diff line number Diff line
@@ -6,11 +6,11 @@
/* clang-format off */
/* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
!!GlobalInfo
product: Peripherals v13.0
product: Peripherals v12.0
processor: MK66FN2M0xxx18
package_id: MK66FN2M0VMD18
mcu_data: ksdk2_0
processor_version: 14.0.0
processor_version: 13.0.1
board: FRDM-K66F
functionalGroups:
- name: BOARD_InitPeripherals
@@ -54,31 +54,86 @@ component:
 * BOARD_InitPeripherals functional group
 **********************************************************************************************************************/
/***********************************************************************************************************************
 * NVIC initialization code
 * ADC1_CAM initialization code
 **********************************************************************************************************************/
/* clang-format off */
/* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
instance:
- name: 'NVIC'
- type: 'nvic'
- mode: 'general'
- custom_name_enabled: 'false'
- type_id: 'nvic_57b5eef3774cc60acaede6f5b8bddc67'
- name: 'ADC1_CAM'
- type: 'adc16'
- mode: 'ADC'
- custom_name_enabled: 'true'
- type_id: 'adc16_897558f9b7366ed198de18c33097d7d2'
- functional_group: 'BOARD_InitPeripherals'
- peripheral: 'NVIC'
- peripheral: 'ADC1'
- config_sets:
  - nvic:
    - interrupt_table:
      - 0: []
      - 1: []
      - 2: []
    - interrupts: []
  - fsl_adc16:
    - adc16_config:
      - referenceVoltageSource: 'kADC16_ReferenceVoltageSourceVref'
      - clockSource: 'kADC16_ClockSourceAlt0'
      - enableAsynchronousClock: 'true'
      - clockDivider: 'kADC16_ClockDivider8'
      - resolution: 'kADC16_ResolutionSE8Bit'
      - longSampleMode: 'kADC16_LongSampleDisabled'
      - hardwareAverageMode: 'kADC16_HardwareAverageDisabled'
      - enableHighSpeed: 'false'
      - enableLowPower: 'false'
      - enableContinuousConversion: 'false'
    - adc16_channel_mux_mode: 'kADC16_ChannelMuxA'
    - adc16_hardware_compare_config:
      - hardwareCompareModeEnable: 'false'
    - doAutoCalibration: 'false'
    - offset: '0'
    - trigger: 'false'
    - enable_dma: 'false'
    - enable_irq: 'false'
    - adc_interrupt:
      - IRQn: 'ADC0_IRQn'
      - enable_interrrupt: 'enabled'
      - enable_priority: 'false'
      - priority: '0'
      - enable_custom_name: 'false'
    - adc16_channels_config:
      - 0:
        - channelName: ''
        - enableDifferentialConversion: 'false'
        - channelNumber: 'SE.11'
        - enableInterruptOnConversionCompleted: 'false'
        - channelGroup: '0'
        - initializeChannel: 'true'
 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
/* clang-format on */
adc16_channel_config_t ADC1_CAM_channelsConfig[1] = {
  {
    .channelNumber = 11U,
    .enableDifferentialConversion = false,
    .enableInterruptOnConversionCompleted = false,
  }
};
const adc16_config_t ADC1_CAM_config = {
  .referenceVoltageSource = kADC16_ReferenceVoltageSourceVref,
  .clockSource = kADC16_ClockSourceAlt0,
  .enableAsynchronousClock = true,
  .clockDivider = kADC16_ClockDivider8,
  .resolution = kADC16_ResolutionSE8Bit,
  .longSampleMode = kADC16_LongSampleDisabled,
  .hardwareAverageMode = kADC16_HardwareAverageDisabled,
  .enableHighSpeed = false,
  .enableLowPower = false,
  .enableContinuousConversion = false
};
const adc16_channel_mux_mode_t ADC1_CAM_muxMode = kADC16_ChannelMuxA;

/* Empty initialization function (commented out)
static void NVIC_init(void) {
} */
static void ADC1_CAM_init(void) {
  /* Initialize ADC16 converter */
  ADC16_Init(ADC1_CAM_PERIPHERAL, &ADC1_CAM_config);
  /* Make sure, that software trigger is used */
  ADC16_EnableHardwareTrigger(ADC1_CAM_PERIPHERAL, false);
  /* Configure channel multiplexing mode */
  ADC16_SetChannelMuxMode(ADC1_CAM_PERIPHERAL, ADC1_CAM_muxMode);
  /* Initialize channel */
  ADC16_SetChannelConfig(ADC1_CAM_PERIPHERAL, ADC1_CAM_CH0_CONTROL_GROUP, &ADC1_CAM_channelsConfig[0]);
}

/***********************************************************************************************************************
 * FTM_1_REG_SERVO initialization code
@@ -296,88 +351,6 @@ static void FTM_0_SUN_init(void) {
  FTM_StartTimer(FTM_0_SUN_PERIPHERAL, kFTM_SystemClock);
}

/***********************************************************************************************************************
 * ADC1_CAM initialization code
 **********************************************************************************************************************/
/* clang-format off */
/* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
instance:
- name: 'ADC1_CAM'
- type: 'adc16'
- mode: 'ADC'
- custom_name_enabled: 'true'
- type_id: 'adc16_897558f9b7366ed198de18c33097d7d2'
- functional_group: 'BOARD_InitPeripherals'
- peripheral: 'ADC1'
- config_sets:
  - fsl_adc16:
    - adc16_config:
      - referenceVoltageSource: 'kADC16_ReferenceVoltageSourceVref'
      - clockSource: 'kADC16_ClockSourceAlt0'
      - enableAsynchronousClock: 'true'
      - clockDivider: 'kADC16_ClockDivider8'
      - resolution: 'kADC16_ResolutionSE8Bit'
      - longSampleMode: 'kADC16_LongSampleDisabled'
      - hardwareAverageMode: 'kADC16_HardwareAverageDisabled'
      - enableHighSpeed: 'false'
      - enableLowPower: 'false'
      - enableContinuousConversion: 'false'
    - adc16_channel_mux_mode: 'kADC16_ChannelMuxA'
    - adc16_hardware_compare_config:
      - hardwareCompareModeEnable: 'false'
    - doAutoCalibration: 'false'
    - offset: '0'
    - trigger: 'false'
    - enable_dma: 'false'
    - enable_irq: 'false'
    - adc_interrupt:
      - IRQn: 'ADC0_IRQn'
      - enable_interrrupt: 'enabled'
      - enable_priority: 'false'
      - priority: '0'
      - enable_custom_name: 'false'
    - adc16_channels_config:
      - 0:
        - channelName: ''
        - enableDifferentialConversion: 'false'
        - channelNumber: 'SE.11'
        - enableInterruptOnConversionCompleted: 'false'
        - channelGroup: '0'
        - initializeChannel: 'true'
 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
/* clang-format on */
adc16_channel_config_t ADC1_CAM_channelsConfig[1] = {
  {
    .channelNumber = 11U,
    .enableDifferentialConversion = false,
    .enableInterruptOnConversionCompleted = false,
  }
};
const adc16_config_t ADC1_CAM_config = {
  .referenceVoltageSource = kADC16_ReferenceVoltageSourceVref,
  .clockSource = kADC16_ClockSourceAlt0,
  .enableAsynchronousClock = true,
  .clockDivider = kADC16_ClockDivider8,
  .resolution = kADC16_ResolutionSE8Bit,
  .longSampleMode = kADC16_LongSampleDisabled,
  .hardwareAverageMode = kADC16_HardwareAverageDisabled,
  .enableHighSpeed = false,
  .enableLowPower = false,
  .enableContinuousConversion = false
};
const adc16_channel_mux_mode_t ADC1_CAM_muxMode = kADC16_ChannelMuxA;

static void ADC1_CAM_init(void) {
  /* Initialize ADC16 converter */
  ADC16_Init(ADC1_CAM_PERIPHERAL, &ADC1_CAM_config);
  /* Make sure, that software trigger is used */
  ADC16_EnableHardwareTrigger(ADC1_CAM_PERIPHERAL, false);
  /* Configure channel multiplexing mode */
  ADC16_SetChannelMuxMode(ADC1_CAM_PERIPHERAL, ADC1_CAM_muxMode);
  /* Initialize channel */
  ADC16_SetChannelConfig(ADC1_CAM_PERIPHERAL, ADC1_CAM_CH0_CONTROL_GROUP, &ADC1_CAM_channelsConfig[0]);
}

/***********************************************************************************************************************
 * PIT initialization code
 **********************************************************************************************************************/
@@ -480,17 +453,152 @@ static void GPIOC_init(void) {
  EnableIRQ(GPIOC_IRQN);
}

/***********************************************************************************************************************
 * NVIC initialization code
 **********************************************************************************************************************/
/* clang-format off */
/* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
instance:
- name: 'NVIC'
- type: 'nvic'
- mode: 'general'
- custom_name_enabled: 'false'
- type_id: 'nvic_57b5eef3774cc60acaede6f5b8bddc67'
- functional_group: 'BOARD_InitPeripherals'
- peripheral: 'NVIC'
- config_sets:
  - nvic:
    - interrupt_table:
      - 0: []
      - 1: []
      - 2: []
      - 3: []
    - interrupts: []
 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
/* clang-format on */

/* Empty initialization function (commented out)
static void NVIC_init(void) {
} */

/***********************************************************************************************************************
 * FTM3_CONTROLLER_STATUS initialization code
 **********************************************************************************************************************/
/* clang-format off */
/* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
instance:
- name: 'FTM3_CONTROLLER_STATUS'
- type: 'ftm'
- mode: 'EdgeAligned'
- custom_name_enabled: 'true'
- type_id: 'ftm_a206ca22312775f3c8a462078188c129'
- functional_group: 'BOARD_InitPeripherals'
- peripheral: 'FTM3'
- config_sets:
  - ftm_main_config:
    - ftm_config:
      - clockSource: 'kFTM_SystemClock'
      - clockSourceFreq: 'GetFreq'
      - timerPrescaler: '1'
      - timerOutputFrequency: '65536'
      - systemClockSource: 'BusInterfaceClock'
      - systemClockSourceFreq: 'mirrored_value'
      - faultMode: 'kFTM_Fault_Disable'
      - inputFilterPeriod: '1'
      - faultInputs:
        - 0:
          - enableFaultInput: 'false'
          - faultLevelVal: 'low'
          - useFaultFilter: 'false'
        - 1:
          - enableFaultInput: 'false'
          - faultLevelVal: 'low'
          - useFaultFilter: 'false'
        - 2:
          - enableFaultInput: 'false'
          - faultLevelVal: 'low'
          - useFaultFilter: 'false'
        - 3:
          - enableFaultInput: 'false'
          - faultLevelVal: 'low'
          - useFaultFilter: 'false'
      - deadTimePrescale: 'kFTM_Deadtime_Prescale_1'
      - deadTimePeriod: '0'
      - pwmSyncMode: 'kFTM_SoftwareTrigger'
      - reloadPoints: ''
      - extTriggers: ''
      - chnlInitState: ''
      - chnlPolarity: ''
      - bdmMode: 'kFTM_BdmMode_0'
      - useGlobalTimeBase: 'false'
    - timer_interrupts: 'kFTM_TimeOverflowInterruptEnable'
    - enable_irq: 'true'
    - ftm_interrupt:
      - IRQn: 'FTM3_IRQn'
      - enable_interrrupt: 'enabled'
      - enable_priority: 'false'
      - priority: '0'
      - enable_custom_name: 'false'
    - EnableTimerInInit: 'true'
  - ftm_edge_aligned_mode:
    - ftm_edge_aligned_channels_config:
      - 0:
        - channelId: 'Dual_capture'
        - edge_aligned_mode: 'kFTM_DualEdgeCapture'
        - dual_edge_capture:
          - chnNumber: 'kFTM_Chnl_1'
          - dual_edge_capture_param:
            - mode: 'kFTM_Continuous'
            - currChanEdgeMode: 'kFTM_RisingEdge'
            - nextChanEdgeMode: 'kFTM_FallingEdge'
          - inputFilterPeriod: '1'
          - enable_chan_irq: 'true'
          - enable_chan1_irq: 'true'
 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
/* clang-format on */
const ftm_config_t FTM3_CONTROLLER_STATUS_config = {
  .prescale = kFTM_Prescale_Divide_1,
  .faultMode = kFTM_Fault_Disable,
  .faultFilterValue = 0,
  .deadTimePrescale = kFTM_Deadtime_Prescale_1,
  .deadTimeValue = 0,
  .pwmSyncMode = kFTM_SoftwareTrigger,
  .reloadPoints = 0,
  .extTriggers = 0,
  .chnlInitState = 0,
  .chnlPolarity = 0,
  .bdmMode = kFTM_BdmMode_0,
  .useGlobalTimeBase = false
};
const ftm_dual_edge_capture_param_t FTM3_CONTROLLER_STATUS_channel1 = {
  .mode = kFTM_Continuous,
  .currChanEdgeMode = kFTM_RisingEdge,
  .nextChanEdgeMode = kFTM_FallingEdge
};


static void FTM3_CONTROLLER_STATUS_init(void) {
  FTM_Init(FTM3_CONTROLLER_STATUS_PERIPHERAL, &FTM3_CONTROLLER_STATUS_config);
  FTM_SetTimerPeriod(FTM3_CONTROLLER_STATUS_PERIPHERAL, FTM3_CONTROLLER_STATUS_TIMER_MODULO_VALUE);
  FTM_SetupDualEdgeCapture(FTM3_CONTROLLER_STATUS_PERIPHERAL, kFTM_Chnl_1, &FTM3_CONTROLLER_STATUS_channel1, 0);
  FTM_EnableInterrupts(FTM3_CONTROLLER_STATUS_PERIPHERAL, kFTM_Chnl2InterruptEnable|kFTM_Chnl3InterruptEnable | kFTM_TimeOverflowInterruptEnable);
  /* Enable interrupt FTM3_IRQn request in the NVIC. */
  EnableIRQ(FTM3_CONTROLLER_STATUS_IRQN);
  FTM_StartTimer(FTM3_CONTROLLER_STATUS_PERIPHERAL, kFTM_SystemClock);
}

/***********************************************************************************************************************
 * Initialization functions
 **********************************************************************************************************************/
void BOARD_InitPeripherals(void)
{
  /* Initialize components */
  ADC1_CAM_init();
  FTM_1_REG_SERVO_init();
  FTM_0_SUN_init();
  ADC1_CAM_init();
  PIT_init();
  GPIOC_init();
  FTM3_CONTROLLER_STATUS_init();
}

/***********************************************************************************************************************
+24 −11
Original line number Diff line number Diff line
@@ -10,9 +10,9 @@
 * Included files
 **********************************************************************************************************************/
#include "fsl_common.h"
#include "fsl_adc16.h"
#include "fsl_clock.h"
#include "fsl_ftm.h"
#include "fsl_adc16.h"
#include "fsl_pit.h"
#include "fsl_gpio.h"
#include "fsl_port.h"
@@ -25,6 +25,14 @@ extern "C" {
 * Definitions
 **********************************************************************************************************************/
/* Definitions for BOARD_InitPeripherals functional group */
/* Alias for ADC1 peripheral */
#define ADC1_CAM_PERIPHERAL ADC1
/* ADC1_CAM interrupt vector ID (number). */
#define ADC1_CAM_IRQN ADC0_IRQn
/* ADC1_CAM interrupt handler identifier. */
#define ADC1_CAM_IRQHANDLER 
/* Channel 0 (SE.11) conversion control group. */
#define ADC1_CAM_CH0_CONTROL_GROUP 0
/* Definition of peripheral ID */
#define FTM_1_REG_SERVO_PERIPHERAL FTM1
/* Definition of the clock source frequency */
@@ -37,14 +45,6 @@ extern "C" {
#define FTM_0_SUN_CLOCK_SOURCE CLOCK_GetFreq(kCLOCK_BusClk)
/* Definition of the clock source frequency */
#define FTM_0_SUN_TIMER_MODULO_VALUE (((FTM_0_SUN_CLOCK_SOURCE/ (1U << (FTM_0_SUN_PERIPHERAL->SC & FTM_SC_PS_MASK))) / 10000) - 1)
/* Alias for ADC1 peripheral */
#define ADC1_CAM_PERIPHERAL ADC1
/* ADC1_CAM interrupt vector ID (number). */
#define ADC1_CAM_IRQN ADC0_IRQn
/* ADC1_CAM interrupt handler identifier. */
#define ADC1_CAM_IRQHANDLER 
/* Channel 0 (SE.11) conversion control group. */
#define ADC1_CAM_CH0_CONTROL_GROUP 0
/* BOARD_InitPeripherals defines for PIT */
/* Definition of peripheral ID. */
#define PIT_PERIPHERAL PIT
@@ -88,16 +88,29 @@ extern "C" {
#define GPIOC_IRQN PORTC_IRQn
/* GPIOC interrupt handler identifier. */
#define GPIOC_IRQHANDLER PORTC_IRQHandler
/* Definition of peripheral ID */
#define FTM3_CONTROLLER_STATUS_PERIPHERAL FTM3
/* Definition of the clock source frequency */
#define FTM3_CONTROLLER_STATUS_CLOCK_SOURCE CLOCK_GetFreq(kCLOCK_BusClk)
/* Definition of the clock source frequency */
#define FTM3_CONTROLLER_STATUS_TIMER_MODULO_VALUE 65535
/* FTM3_CONTROLLER_STATUS interrupt vector ID (number). */
#define FTM3_CONTROLLER_STATUS_IRQN FTM3_IRQn
/* FTM3_CONTROLLER_STATUS interrupt handler identifier. */
#define FTM3_CONTROLLER_STATUS_IRQHANDLER FTM3_IRQHandler
/* Definition of FTM3 channel/pair number 2/3 on Dual Edge Capture */
#define FTM3_CONTROLLER_STATUS_DUAL_CAPTURE_PAIR kFTM_Chnl_1

/***********************************************************************************************************************
 * Global variables
 **********************************************************************************************************************/
extern const ftm_config_t FTM_1_REG_SERVO_config;
extern const ftm_config_t FTM_0_SUN_config;
extern adc16_channel_config_t ADC1_CAM_channelsConfig[1];
extern const adc16_config_t ADC1_CAM_config;
extern const adc16_channel_mux_mode_t ADC1_CAM_muxMode;
extern const ftm_config_t FTM_1_REG_SERVO_config;
extern const ftm_config_t FTM_0_SUN_config;
extern const pit_config_t PIT_config;
extern const ftm_config_t FTM3_CONTROLLER_STATUS_config;

/***********************************************************************************************************************
 * Initialization functions
+12 −2
Original line number Diff line number Diff line
@@ -7,11 +7,11 @@
/*
 * TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
!!GlobalInfo
product: Pins v14.0
product: Pins v13.1
processor: MK66FN2M0xxx18
package_id: MK66FN2M0VMD18
mcu_data: ksdk2_0
processor_version: 14.0.0
processor_version: 13.0.1
board: FRDM-K66F
pin_labels:
- {pin_num: A1, pin_signal: PTD7/CMT_IRO/UART0_TX/FTM0_CH7/SDRAM_CKE/FTM0_FLT1/SPI1_SIN, label: 'J6[7]/SPI1_SIN/MISO'}
@@ -194,6 +194,8 @@ BOARD_InitPins:
- options: {callFromInitBoot: 'true', prefix: BOARD_, coreID: core0, enableClock: 'true'}
- pin_list:
  - {pin_num: K6, peripheral: TPIU, signal: SWO, pin_signal: TSI0_CH3/PTA2/UART0_TX/FTM0_CH7/I2C3_SCL/LPUART0_TX/JTAG_TDO/TRACE_SWO/EZP_DO, pull_select: down, pull_enable: disable}
  - {pin_num: B4, peripheral: FTM3, signal: 'CH, 3', pin_signal: PTD3/SPI0_SIN/UART2_TX/FTM3_CH3/FB_AD3/SDRAM_A11/I2C0_SDA, identifier: ''}
  - {pin_num: C4, peripheral: FTM3, signal: 'CH, 2', pin_signal: PTD2/LLWU_P13/SPI0_SOUT/UART2_RX/FTM3_CH2/FB_AD4/SDRAM_A12/I2C0_SCL, identifier: ''}
 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS ***********
 */
/* clang-format on */
@@ -208,6 +210,8 @@ void BOARD_InitPins(void)
{
    /* Port A Clock Gate Control: Clock enabled */
    CLOCK_EnableClock(kCLOCK_PortA);
    /* Port D Clock Gate Control: Clock enabled */
    CLOCK_EnableClock(kCLOCK_PortD);

    /* PORTA2 (pin K6) is configured as TRACE_SWO */
    PORT_SetPinMux(BOARD_TRACE_SWO_PORT, BOARD_TRACE_SWO_PIN, kPORT_MuxAlt7);
@@ -222,6 +226,12 @@ void BOARD_InitPins(void)

                     /* Pull Enable: Internal pullup or pulldown resistor is not enabled on the corresponding pin. */
                     | PORT_PCR_PE(kPORT_PullDisable));

    /* PORTD2 (pin C4) is configured as FTM3_CH2 */
    PORT_SetPinMux(PORTD, 2U, kPORT_MuxAlt4);

    /* PORTD3 (pin B4) is configured as FTM3_CH3 */
    PORT_SetPinMux(PORTD, 3U, kPORT_MuxAlt4);
}

/* clang-format off */
+210 −84

File changed.

Preview size limit exceeded, changes collapsed.

Loading