finished implementation of init splitflap

removed pin mux
fixed hardfault (by adding clocking of port)
main
Jonas Arnold 4 years ago
parent 5f48936e73
commit 3a9ef7db0c
  1. 149
      ADIS_tinyK22_SplitFlap/ADIS_tinyK22_SplitFlap.mex
  2. 17
      ADIS_tinyK22_SplitFlap/board/pin_mux.c
  3. 13
      ADIS_tinyK22_SplitFlap/board/pin_mux.h
  4. 12
      ADIS_tinyK22_SplitFlap/source/application.c
  5. 2
      ADIS_tinyK22_SplitFlap/source/main.c
  6. 6
      ADIS_tinyK22_SplitFlap/source/platform.c
  7. 19
      ADIS_tinyK22_SplitFlap/source/splitflap.c
  8. 3
      ADIS_tinyK22_SplitFlap/source/splitflap.h

@ -0,0 +1,149 @@
<?xml version="1.0" encoding= "UTF-8" ?>
<configuration name="MK22FN512xxx12" xsi:schemaLocation="http://mcuxpresso.nxp.com/XSD/mex_configuration_12 http://mcuxpresso.nxp.com/XSD/mex_configuration_12.xsd" uuid="a31f0674-0f5f-4ff8-ab01-7b0e339cb3d9" version="12" xmlns="http://mcuxpresso.nxp.com/XSD/mex_configuration_12" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<common>
<processor>MK22FN512xxx12</processor>
<package>MK22FN512VLH12</package>
<mcu_data>ksdk2_0</mcu_data>
<cores selected="core0">
<core name="Cortex-M4F" id="core0" description="M4 core"/>
</cores>
<description>Configuration imported from ADIS_tinyK22_SplitFlap</description>
</common>
<preferences>
<validate_boot_init_only>true</validate_boot_init_only>
<generate_extended_information>false</generate_extended_information>
<generate_code_modified_registers_only>false</generate_code_modified_registers_only>
<update_include_paths>true</update_include_paths>
<generate_registers_defines>false</generate_registers_defines>
</preferences>
<tools>
<pins name="Pins" version="12.0" enabled="true" update_project_code="true">
<generated_project_files>
<file path="board/pin_mux.c" update_enabled="true"/>
<file path="board/pin_mux.h" update_enabled="true"/>
</generated_project_files>
<pins_profile>
<processor_version>12.0.0</processor_version>
<pin_labels>
<pin_label pin_num="45" pin_signal="ADC0_SE4b/CMP1_IN0/PTC2/SPI0_PCS2/UART1_CTS_b/FTM0_CH1/FB_AD12/I2S0_TX_FS/LPUART0_CTS_b" label="LED_BLUE" identifier="LED_BLUE"/>
</pin_labels>
</pins_profile>
<functions_list>
<function name="BOARD_InitPins">
<description>Configures pin routing and optionally pin electrical features.</description>
<options>
<callFromInitBoot>true</callFromInitBoot>
<coreID>core0</coreID>
<enableClock>true</enableClock>
</options>
<dependencies>
<dependency resourceType="SWComponent" resourceId="platform.drivers.common" description="Pins initialization requires the COMMON Driver in the project." problem_level="2" source="Pins:BOARD_InitPins">
<feature name="enabled" evaluation="equal" configuration="core0">
<data>true</data>
</feature>
</dependency>
</dependencies>
<pins/>
</function>
</functions_list>
</pins>
<clocks name="Clocks" version="10.0" enabled="true" update_project_code="true">
<generated_project_files>
<file path="board/clock_config.c" update_enabled="true"/>
<file path="board/clock_config.h" update_enabled="true"/>
</generated_project_files>
<clocks_profile>
<processor_version>12.0.0</processor_version>
</clocks_profile>
<clock_configurations>
<clock_configuration name="BOARD_BootClockRUN" id_prefix="" prefix_user_defined="false">
<description></description>
<options/>
<dependencies>
<dependency resourceType="SWComponent" resourceId="platform.drivers.common" description="Clocks initialization requires the COMMON Driver in the project." problem_level="2" source="Clocks:BOARD_BootClockRUN">
<feature name="enabled" evaluation="equal" configuration="core0">
<data>true</data>
</feature>
</dependency>
</dependencies>
<clock_sources/>
<clock_outputs>
<clock_output id="Bus_clock.outFreq" value="20.97152 MHz" locked="false" accuracy=""/>
<clock_output id="Core_clock.outFreq" value="20.97152 MHz" locked="false" accuracy=""/>
<clock_output id="Flash_clock.outFreq" value="10.48576 MHz" locked="false" accuracy=""/>
<clock_output id="FlexBus_clock.outFreq" value="10.48576 MHz" locked="false" accuracy=""/>
<clock_output id="LPO_clock.outFreq" value="1 kHz" locked="false" accuracy=""/>
<clock_output id="MCGFFCLK.outFreq" value="32.768 kHz" locked="false" accuracy=""/>
<clock_output id="PLLFLLCLK.outFreq" value="20.97152 MHz" locked="false" accuracy=""/>
<clock_output id="System_clock.outFreq" value="20.97152 MHz" locked="false" accuracy=""/>
</clock_outputs>
<clock_settings/>
<called_from_default_init>true</called_from_default_init>
</clock_configuration>
</clock_configurations>
</clocks>
<dcdx name="DCDx" version="3.0" enabled="false" update_project_code="true">
<generated_project_files/>
<dcdx_profile>
<processor_version>N/A</processor_version>
</dcdx_profile>
<dcdx_configurations/>
</dcdx>
<periphs name="Peripherals" version="11.0" enabled="true" update_project_code="true">
<generated_project_files>
<file path="board/peripherals.c" update_enabled="true"/>
<file path="board/peripherals.h" update_enabled="true"/>
</generated_project_files>
<peripherals_profile>
<processor_version>12.0.0</processor_version>
</peripherals_profile>
<functional_groups>
<functional_group name="BOARD_InitPeripherals" uuid="74acc050-89d1-4c54-a2cd-4d87a4233be4" called_from_default_init="true" id_prefix="" core="core0">
<description></description>
<options/>
<dependencies/>
<instances>
<instance name="NVIC" uuid="27125e32-529a-4aa9-9340-66074f00887b" type="nvic" type_id="nvic_57b5eef3774cc60acaede6f5b8bddc67" mode="general" peripheral="NVIC" enabled="true" comment="" custom_name_enabled="false" editing_lock="false">
<config_set name="nvic">
<array name="interrupt_table"/>
<array name="interrupts"/>
</config_set>
</instance>
</instances>
</functional_group>
</functional_groups>
<components>
<component name="system" uuid="eded1dd4-86dd-4424-8285-f910ee55095f" type_id="system_54b53072540eeeb8f8e9343e71f28176">
<config_set_global name="global_system_definitions">
<setting name="user_definitions" value=""/>
<setting name="user_includes" value=""/>
</config_set_global>
</component>
<component name="uart_cmsis_common" uuid="2524d25b-87b3-420d-a892-9680b8d18641" type_id="uart_cmsis_common_9cb8e302497aa696fdbb5a4fd622c2a8">
<config_set_global name="global_USART_CMSIS_common" quick_selection="default"/>
</component>
<component name="gpio_adapter_common" uuid="6ff55441-fb80-46d4-96df-f289f25e66b0" type_id="gpio_adapter_common_57579b9ac814fe26bf95df0a384c36b6">
<config_set_global name="global_gpio_adapter_common" quick_selection="default"/>
</component>
<component name="msg" uuid="c11fd9e8-0efa-476e-b672-b0cfa532810b" type_id="msg_6e2baaf3b97dbeef01c0043275f9a0e7">
<config_set_global name="global_messages"/>
</component>
<component name="generic_uart" uuid="dcf9d27f-9b32-46f2-8925-77aa2a6ee919" type_id="generic_uart_8cae00565451cf2346eb1b8c624e73a6">
<config_set_global name="global_uart"/>
</component>
<component name="generic_enet" uuid="a030ef46-be3c-4f5d-9dca-19789f06e3be" type_id="generic_enet_74db5c914f0ddbe47d86af40cb77a619">
<config_set_global name="global_enet"/>
</component>
<component name="generic_can" uuid="cf926078-b097-444b-be9f-2fa1f86be003" type_id="generic_can_1bfdd78b1af214566c1f23cf6a582d80">
<config_set_global name="global_can"/>
</component>
</components>
</periphs>
<tee name="TEE" version="4.0" enabled="false" update_project_code="true">
<generated_project_files/>
<tee_profile>
<processor_version>N/A</processor_version>
</tee_profile>
</tee>
</tools>
</configuration>

@ -19,8 +19,6 @@ pin_labels:
/* clang-format on */
#include "fsl_common.h"
#include "fsl_port.h"
#include "fsl_gpio.h"
#include "pin_mux.h"
/* FUNCTION ************************************************************************************************************
@ -39,8 +37,7 @@ void BOARD_InitBootPins(void)
* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
BOARD_InitPins:
- options: {callFromInitBoot: 'true', coreID: core0, enableClock: 'true'}
- pin_list:
- {pin_num: '45', peripheral: GPIOC, signal: 'GPIO, 2', pin_signal: ADC0_SE4b/CMP1_IN0/PTC2/SPI0_PCS2/UART1_CTS_b/FTM0_CH1/FB_AD12/I2S0_TX_FS/LPUART0_CTS_b, direction: OUTPUT}
- pin_list: []
* BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS ***********
*/
/* clang-format on */
@ -53,18 +50,6 @@ BOARD_InitPins:
* END ****************************************************************************************************************/
void BOARD_InitPins(void)
{
/* Port C Clock Gate Control: Clock enabled */
CLOCK_EnableClock(kCLOCK_PortC);
gpio_pin_config_t LED_BLUE_config = {
.pinDirection = kGPIO_DigitalOutput,
.outputLogic = 0U
};
/* Initialize GPIO functionality on pin PTC2 (pin 45) */
GPIO_PinInit(BOARD_INITPINS_LED_BLUE_GPIO, BOARD_INITPINS_LED_BLUE_PIN, &LED_BLUE_config);
/* PORTC2 (pin 45) is configured as PTC2 */
PORT_SetPinMux(BOARD_INITPINS_LED_BLUE_PORT, BOARD_INITPINS_LED_BLUE_PIN, kPORT_MuxAsGpio);
}
/***********************************************************************************************************************
* EOF

@ -25,19 +25,6 @@ extern "C" {
*/
void BOARD_InitBootPins(void);
/*! @name PORTC2 (number 45), LED_BLUE
@{ */
/* Symbols to be used with GPIO driver */
#define BOARD_INITPINS_LED_BLUE_GPIO GPIOC /*!<@brief GPIO peripheral base pointer */
#define BOARD_INITPINS_LED_BLUE_GPIO_PIN_MASK (1U << 2U) /*!<@brief GPIO pin mask */
/* Symbols to be used with PORT driver */
#define BOARD_INITPINS_LED_BLUE_PORT PORTC /*!<@brief PORT peripheral base pointer */
#define BOARD_INITPINS_LED_BLUE_PIN 2U /*!<@brief PORT pin number */
#define BOARD_INITPINS_LED_BLUE_PIN_MASK (1U << 2U) /*!<@brief PORT pin mask */
/* @} */
/*!
* @brief Configures pin routing and optionally pin electrical features.
*

@ -70,15 +70,21 @@ void App_Init(void){
/* Application run */
void App_Run(void){
while(1) {
SF_MoveMotorToZeroPosition(splitflap0);
/* TEST PATTERN */
/*while(1) {
if(SF_GetMagSensorAtZeroPosition(splitflap0)){
McuLED_On(LED_blue);
} else {
McuLED_Off(LED_blue);
}
McuWait_Waitms(10); /* wait for 100 ms */
}
McuWait_Waitms(10); // wait for 10 ms
}*/
}

@ -72,7 +72,7 @@ int main(void) {
App_Run();
/* deinit app */
//PRINTF("De-Initializing App...\n");
PRINTF("De-Initializing App...\n");
App_Deinit();
/* deinit platform */

@ -14,6 +14,12 @@
#include "splitflap.h"
void PL_Init(void){
/* Enable clock for used PORTS */
CLOCK_EnableClock(kCLOCK_PortA);
CLOCK_EnableClock(kCLOCK_PortB);
CLOCK_EnableClock(kCLOCK_PortC);
McuLib_Init();
McuWait_Init();
McuGPIO_Init();

@ -86,11 +86,28 @@ SF_Handle_t SF_Init(SF_Config_t* instance, int id){
bool SF_MoveMotorToZeroPosition(SF_Handle_t instance){
int numStepsMoved = 0;
// move out of sensor
while(SF_GetMagSensorAtZeroPosition((SF_t*)instance) == true){
McuULN2003_IncStep(((SF_t*)instance)->motor);
McuWait_Waitms(20);
}
// turn until sensor is on
while(SF_GetMagSensorAtZeroPosition((SF_t*)instance) == false && numStepsMoved < SPLITFLAP_STEPS_ONE_ROUND ){
McuULN2003_IncStep(((SF_t*)instance)->motor);
McuWait_Waitms(20);
numStepsMoved++;
}
// one more segment if not already one round
if(numStepsMoved < SPLITFLAP_STEPS_ONE_ROUND){
for(int i=0; i<SPLITFLAP_STEPS_PER_SEGMENT; i++){
McuULN2003_IncStep(((SF_t*)instance)->motor);
McuWait_Waitms(20);
numStepsMoved++;
}
}
McuULN2003_SetPos(((SF_t*)instance)->motor, 0);
McuULN2003_PowerOff(((SF_t*)instance)->motor);
// success if less than one rotation
@ -116,7 +133,7 @@ void SF_MoveSteps(SF_Handle_t instance, int32_t steps){
}
bool SF_GetMagSensorAtZeroPosition(SF_Handle_t instance){
return McuGPIO_GetValue(((SF_t*)instance)->magSensor);
return McuGPIO_IsLow(((SF_t*)instance)->magSensor);
}
void SF_MoveToFlap(SF_Handle_t instance, char* flap){

@ -15,7 +15,8 @@
/****** SETTINGS ******/
#define SPLITFLAP_CONFIG_USE_FREERTOS_HEAP 0
#define SPLITFLAP_STEPS_ONE_ROUND 200
#define SPLITFLAP_STEPS_ONE_ROUND 520 // 40 segments a 13 steps
#define SPLITFLAP_STEPS_PER_SEGMENT 13
/****** TYPES ******/

Loading…
Cancel
Save