Commit f5fabc4c authored by Martin Gandler's avatar Martin Gandler

added sources

parent 05c83366
Master/Objects
Master/*.uvguix.*
\ No newline at end of file
// <<< Use Configuration Wizard in Context Menu >>>
// <h>Debug MCU Configuration
// <o.0> DBG_SLEEP <i> Debug Sleep Mode
// <o.1> DBG_STOP <i> Debug Stop Mode
// <o.2> DBG_STANDBY <i> Debug Standby Mode
// </h>
DbgMCU_CR = 0x00000007;
// <h> Debug MCU APB1 Freeze
// <o.0> DBG_TIM2_STOP <i> Timer 2 Stopped when Core is halted
// <o.1> DBG_TIM3_STOP <i> Timer 3 Stopped when Core is halted
// <o.2> DBG_TIM4_STOP <i> Timer 4 Stopped when Core is halted
// <o.3> DBG_TIM5_STOP <i> Timer 5 Stopped when Core is halted
// <o.10> DBG_RTC_STOP <i> RTC Stopped when Core is halted
// <o.11> DBG_WWDG_STOP <i> Window Watchdog Stopped when Core is halted
// <o.12> DBG_IWDG_STOP <i> Independent Watchdog Stopped when Core is halted
// <o.21> DBG_I2C1_SMBUS_TIMEOUT <i> I2C1 SMBUS Timeout Mode Stopped when Core is halted
// <o.22> DBG_I2C2_SMBUS_TIMEOUT <i> I2C2 SMBUS Timeout Mode Stopped when Core is halted
// <o.23> DBG_I2C3_SMBUS_TIMEOUT <i> I2C3 SMBUS Timeout Mode Stopped when Core is halted
// </h>
DbgMCU_APB1_Fz = 0x00000000;
// <h> Debug MCU APB2 Freeze
// <o.0> DBG_TIM1_STOP <i> Timer 1 Stopped when Core is halted
// <o.16> DBG_TIM9_STOP <i> Timer 9 Stopped when Core is halted
// <o.17> DBG_TIM10_STOP <i> Timer 10 Stopped when Core is halted
// <o.18> DBG_TIM11_STOP <i> Timer 11 Stopped when Core is halted
// </h>
DbgMCU_APB2_Fz = 0x00000000;
// <<< end of configuration section >>>
\ No newline at end of file
// <<< Use Configuration Wizard in Context Menu >>>
// <h>Debug MCU Configuration
// <o.0> DBG_SLEEP <i> Debug Sleep Mode
// <o.1> DBG_STOP <i> Debug Stop Mode
// <o.2> DBG_STANDBY <i> Debug Standby Mode
// </h>
DbgMCU_CR = 0x00000007;
// <h> Debug MCU APB1 Freeze
// <o.0> DBG_TIM2_STOP <i> Timer 2 Stopped when Core is halted
// <o.1> DBG_TIM3_STOP <i> Timer 3 Stopped when Core is halted
// <o.2> DBG_TIM4_STOP <i> Timer 4 Stopped when Core is halted
// <o.3> DBG_TIM5_STOP <i> Timer 5 Stopped when Core is halted
// <o.10> DBG_RTC_STOP <i> RTC Stopped when Core is halted
// <o.11> DBG_WWDG_STOP <i> Window Watchdog Stopped when Core is halted
// <o.12> DBG_IWDG_STOP <i> Independent Watchdog Stopped when Core is halted
// <o.21> DBG_I2C1_SMBUS_TIMEOUT <i> I2C1 SMBUS Timeout Mode Stopped when Core is halted
// <o.22> DBG_I2C2_SMBUS_TIMEOUT <i> I2C2 SMBUS Timeout Mode Stopped when Core is halted
// <o.23> DBG_I2C3_SMBUS_TIMEOUT <i> I2C3 SMBUS Timeout Mode Stopped when Core is halted
// </h>
DbgMCU_APB1_Fz = 0x00000000;
// <h> Debug MCU APB2 Freeze
// <o.0> DBG_TIM1_STOP <i> Timer 1 Stopped when Core is halted
// <o.16> DBG_TIM9_STOP <i> Timer 9 Stopped when Core is halted
// <o.17> DBG_TIM10_STOP <i> Timer 10 Stopped when Core is halted
// <o.18> DBG_TIM11_STOP <i> Timer 11 Stopped when Core is halted
// </h>
DbgMCU_APB2_Fz = 0x00000000;
// <<< end of configuration section >>>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<component_viewer schemaVersion="0.1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="Component_Viewer.xsd">
<component name="EventRecorderStub" version="1.0.0"/> <!--name and version of the component-->
<events>
</events>
</component_viewer>
This diff is collapsed.
This diff is collapsed.
#include <stm32f4xx_hal.h>
#include <stm32f4xx_hal_conf.h>
#include <stm32f4xx_hal_rcc.h>
#include <stdint.h>
void SystemClock_Config(void) {
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
clocks dividers */
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK |
RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3);
}
void HAL_MspInit(void) {
SystemClock_Config();
// call this method to update the value of SystemCoreClock
SystemCoreClockUpdate();
SysTick_Config(SystemCoreClock/1000); //Interrupt every 1ms
}
void SysTick_Handler(){ //
HAL_IncTick();
}
//On sequence to turn on power socket 2
uint8_t On_2_Sequence [][2] = {
{ 1, 1}, //Send '0'
{ 0, 3},
{ 1, 3}, //Send '1'
{ 0, 1},
{ 1, 1}, //Send '0'
{ 0, 3},
{ 1, 3}, //Send '1'
{ 0, 1},
{ 1, 1}, //Send '0'
{ 0, 3},
{ 1, 1}, //Send '0'
{ 0, 3},
{ 1, 1}, //Send '0'
{ 0, 3},
{ 1, 1}, //Send '0'
{ 0, 3},
{ 1, 1}, //Send '0'
{ 0, 3},
{ 1, 3}, //Send '1'
{ 0, 1},
{ 1, 1}, //Send '0'
{ 0, 3},
{ 1, 3}, //Send '1'
{ 0, 1},
{ 1, 1}, //Send '0'
{ 0, 3},
{ 1, 3}, //Send '1'
{ 0, 1},
{ 1, 1}, //Send '0'
{ 0, 3},
{ 1, 3}, //Send '1'
{ 0, 1},
{ 1, 3}, //Send '1'
{ 0, 1},
{ 1, 3}, //Send '1'
{ 0, 1},
{ 1, 1}, //Send '0'
{ 0, 3},
{ 1, 1}, //Send '0'
{ 0, 3},
{ 1, 1}, //Send '0'
{ 0, 3},
{ 1, 1}, //Send '0'
{ 0, 3},
{ 1, 3}, //Send '1'
{ 0, 1},
{ 1, 3}, //Send '1'
{ 0, 1},
{ 1, 1}, //Send '0'
{ 0, 3},
{ 255, 255} //Termination
};
//On sequence to turn off power socket 2
uint8_t Off_2_Sequence [][2] = {
{ 1, 1}, //Send '0'
{ 0, 3},
{ 1, 3}, //Send '1'
{ 0, 1},
{ 1, 1}, //Send '0'
{ 0, 3},
{ 1, 3}, //Send '1'
{ 0, 1},
{ 1, 1}, //Send '0'
{ 0, 3},
{ 1, 1}, //Send '0'
{ 0, 3},
{ 1, 1}, //Send '0'
{ 0, 3},
{ 1, 1}, //Send '0'
{ 0, 3},
{ 1, 1}, //Send '0'
{ 0, 3},
{ 1, 3}, //Send '1'
{ 0, 1},
{ 1, 1}, //Send '0'
{ 0, 3},
{ 1, 3}, //Send '1'
{ 0, 1},
{ 1, 1}, //Send '0'
{ 0, 3},
{ 1, 3}, //Send '1'
{ 0, 1},
{ 1, 1}, //Send '0'
{ 0, 3},
{ 1, 3}, //Send '1'
{ 0, 1},
{ 1, 3}, //Send '1'
{ 0, 1},
{ 1, 3}, //Send '1'
{ 0, 1},
{ 1, 1}, //Send '0'
{ 0, 3},
{ 1, 1}, //Send '0'
{ 0, 3},
{ 1, 3}, //Send '1'
{ 0, 1},
{ 1, 3}, //Send '1'
{ 0, 1},
{ 1, 1}, //Send '0'
{ 0, 3},
{ 1, 1}, //Send '0'
{ 0, 3},
{ 1, 1}, //Send '0'
{ 0, 3},
{ 255, 255} //Termination
};
//Row index for selected sequence
uint8_t SequenceCounter = 0;
//Pointer to selected sequence
uint8_t (*SelectedSequence)[2] = NULL;
//Counts on or off time for each line in sequence
//it is initialised with the value in the second column
uint8_t OnCounter = 0;
//This variables are set by incoming bytes through the UART
//or by pressing the keys
uint8_t On2Selected = 0;
uint8_t Off2Selected = 0;
int main(void){
HAL_Init();
__GPIOA_CLK_ENABLE();
__GPIOB_CLK_ENABLE();
//Init output for transmitter
GPIO_InitTypeDef gpio;
gpio.Mode = GPIO_MODE_OUTPUT_PP;
gpio.Pin = GPIO_PIN_5;
gpio.Speed = GPIO_SPEED_FAST;
HAL_GPIO_Init(GPIOB, &gpio);
//Init timer to create time reference
__HAL_RCC_TIM2_CLK_ENABLE();
TIM2->ARR = 166;
TIM2->PSC = 16-1;
TIM2->CR1 = TIM_CR1_ARPE | TIM_CR1_CEN;
TIM2->DIER = TIM_DIER_UIE;
//Init UART to receive commands
__HAL_RCC_USART1_CLK_ENABLE();
UART_HandleTypeDef huart1;
GPIO_InitTypeDef GPIO_InitStruct;
/**USART1 GPIO Configuration
PA9 ------> USART1_TX
PA10 ------> USART1_RX
*/
GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
huart1.Instance = USART1;
huart1.Init.BaudRate = 9600;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
huart1.Init.Mode = UART_MODE_RX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
//Enable UART interrupt
HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(USART1_IRQn);
HAL_UART_Init(&huart1);
USART1->CR1 |= USART_CR1_RXNEIE;
NVIC_EnableIRQ(USART1_IRQn);
while(1){
//Use a delay to debounce the input keys
HAL_Delay(50);
if(!(GPIOB->IDR & GPIO_PIN_3)){
//Turn on key is pressed
On2Selected = 1;
}
if(!(GPIOB->IDR & GPIO_PIN_4)){
//Turn off key is pressed
Off2Selected = 1;
}
if(On2Selected){
//Send on sequence 10 times
for(uint8_t i = 0; i < 10; i++){
if(SelectedSequence == NULL){
//Set pointer and enable timer interrupt
SelectedSequence = On_2_Sequence;
OnCounter = 0;
TIM2->CNT = 0;
NVIC_EnableIRQ(TIM2_IRQn);
}
//Delay must be greater than the sequence duration
HAL_Delay(20);
}
}
if(Off2Selected){
//Send on sequence 10 times
for(uint8_t i = 0; i < 10; i++){
if(SelectedSequence == NULL){
//Set pointer and enable timer interrupt
SelectedSequence = Off_2_Sequence;
OnCounter = 0;
TIM2->CNT = 0;
NVIC_EnableIRQ(TIM2_IRQn);
}
//Delay must be greater than the sequence duration
HAL_Delay(20);
}
}
}
return 0;
}
void TIM2_IRQHandler(void){
if(TIM2->SR & TIM_SR_UIF){
// if counter is 0, send next sequence
if(OnCounter == 0){
//Check if sequence reached end
if(SelectedSequence[SequenceCounter][0] != 255){
//Use bit band to set or reset output pin
if(SelectedSequence[SequenceCounter][0]){
GPIOB->BSRR = GPIO_PIN_5;
}else{
GPIOB->BSRR = GPIO_PIN_5 << 16;
}
//Set new bit counter
OnCounter = SelectedSequence[SequenceCounter][1]-1;
SequenceCounter++;
}else{
//End reached -> disable timer interrupt and reset pin
NVIC_DisableIRQ(TIM2_IRQn);
SelectedSequence = NULL;
GPIOB->BSRR = GPIO_PIN_5 << 16;
SequenceCounter = 0;
On2Selected = 0;
Off2Selected = 0;
}
}else{
OnCounter --;
}
TIM2->SR &= (~(TIM_SR_UIF));
}
NVIC_ClearPendingIRQ(TIM2_IRQn);
}
//UART interrupt
void USART1_IRQHandler(void){
uint8_t data = USART1->DR;
uint8_t channel = data & 0x7f;
if(data & 0x80){
//MSB is set -> turn on
if(channel == 2){
On2Selected = 1;
}
}else{
if(channel == 2){
Off2Selected = 1;
}
}
NVIC_ClearPendingIRQ(USART1_IRQn);
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<ProjectOpt xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="project_optx.xsd">
<SchemaVersion>1.0</SchemaVersion>
<Header>### uVision Project, (C) Keil Software</Header>
<Extensions>
<cExt>*.c</cExt>
<aExt>*.s*; *.src; *.a*</aExt>
<oExt>*.obj; *.o</oExt>
<lExt>*.lib</lExt>
<tExt>*.txt; *.h; *.inc</tExt>
<pExt>*.plm</pExt>
<CppX>*.cpp</CppX>
<nMigrate>0</nMigrate>
</Extensions>
<DaveTm>
<dwLowDateTime>0</dwLowDateTime>
<dwHighDateTime>0</dwHighDateTime>
</DaveTm>
<Target>
<TargetName>Src</TargetName>
<ToolsetNumber>0x4</ToolsetNumber>