Skip to content

Commit

Permalink
Bugfix: timebase for timer 14 was wrong (base 0 not 1!).
Browse files Browse the repository at this point in the history
Added command "FTEST" ---> when enabled, the time base is present on PA4 for calibrating external oscillator.
  • Loading branch information
s54mtb committed Dec 22, 2016
1 parent 52e7061 commit eb51f0f
Show file tree
Hide file tree
Showing 8 changed files with 1,411 additions and 1,337 deletions.
2 changes: 2 additions & 0 deletions projects/f0-usb-beacon/Inc/command.h
Expand Up @@ -7,6 +7,8 @@
void cmd_proc (char *cmd);
int cmd_isautorun(void);
void cmd_autorun(int ar);
uint8_t GetFtestState(void);


#endif

2,534 changes: 1,279 additions & 1,255 deletions projects/f0-usb-beacon/Objects/MorseGenerator.hex

Large diffs are not rendered by default.

80 changes: 80 additions & 0 deletions projects/f0-usb-beacon/Src/command.c
Expand Up @@ -26,6 +26,8 @@


extern settings_t settings;
static uint8_t ftest = 0;


/** Globals */
static char cmdstr_buf [1 + MAX_CMD_LEN];
Expand Down Expand Up @@ -57,6 +59,7 @@ enum
CMD_DEL,
CMD_ID,
CMD_START,
CMD_FTEST,
// Add more
CMD_LAST
};
Expand Down Expand Up @@ -88,6 +91,7 @@ const char helptext[] =
" ID ...Text...\n\r"
" STOP\n\r"
" START x\n\r"
" FTEST 0|1\n\r"
"\n\r";

/**
Expand All @@ -108,6 +112,7 @@ const struct cmd_st cmd_tbl [] =
{ "DEL", CMD_DEL, },
{ "ID", CMD_ID, },
{ "START", CMD_START, },
{ "FTEST", CMD_FTEST, },
};

#define CMD_TBL_LEN (sizeof (cmd_tbl) / sizeof (cmd_tbl [0]))
Expand All @@ -126,6 +131,7 @@ void cmd_store(char *argstr_buf, uint8_t del, uint8_t echo);
void cmd_load(char *argstr_buf);
void cmd_del(char *argstr_buf);
void cmd_start(char *argstr_buf);
void cmd_ftest(char *argstr_buf);

void cmd_unknown(char *argstr_buf);

Expand Down Expand Up @@ -271,6 +277,10 @@ function invoked here.
case CMD_START:
cmd_start(argstr_buf);
break;

case CMD_FTEST:
cmd_ftest(argstr_buf);
break;

case CMD_LAST:
cmd_unknown(cmdstr_buf);
Expand Down Expand Up @@ -830,6 +840,76 @@ void cmd_start(char *argstr_buf)
}


/**
* @brief Return ftest state
*/
uint8_t GetFtestState(void)
{
return ftest;
}


/**
* @brief Init or deinit ftest pin
* @param int 0 or 1
* 0 - enable, 1 - disable
* @retval None
*/
void ftestpin(int enable)
{

GPIO_InitTypeDef GPIO_InitStruct;

if (enable>0)
{
/*Configure GPIO pin : PA4 */
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Pin = GPIO_PIN_4;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
ftest = 1;

}
else
{
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_4);
ftest = 0;
}

}



/**
* @brief Enable time base (frequency) test on PA4
* @param String 0 or 1
* 0 - enable, 1 - disable
* @retval None
*/
void cmd_ftest(char *argstr_buf)
{
int x;
char izp[32];

if ((argstr_buf != NULL) & (strlen(argstr_buf)>0))
{
x = atoi(argstr_buf);
if ((x>=0) & (x<=1))
{
ftestpin(x);
}
}
else
{
snprintf(izp, 32, "FTEST: %d\n\r",GetFtestState());
USB_write((uint8_t *)izp, strlen(izp));
}
}




uint8_t selectpins(void)
{
uint8_t sp =0;
Expand Down
7 changes: 4 additions & 3 deletions projects/f0-usb-beacon/Src/main.c
Expand Up @@ -267,11 +267,12 @@ void MX_TIM14_Init(void)
{

htim14.Instance = TIM14;
htim14.Init.Prescaler = 48;
htim14.Init.Prescaler = 3;
htim14.Init.CounterMode = TIM_COUNTERMODE_UP;
htim14.Init.Period = 1000;
htim14.Init.Period = 11999;
htim14.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
HAL_TIM_Base_Init(&htim14);
HAL_NVIC_SetPriority(TIM14_IRQn, 0, 0);

}

Expand Down Expand Up @@ -322,7 +323,7 @@ void MX_GPIO_Init(void)
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);


}

Expand Down
6 changes: 3 additions & 3 deletions projects/f0-usb-beacon/Src/morse.c
Expand Up @@ -52,7 +52,7 @@ Morse_Status_t MS;

const morse_t morse_keys[] =
{
{'A', 0xfff9}, /// 11111111 11111001
{'A', 0xfff9}, /// 11111111 111110011
{'B', 0xffe8}, /// 11111111 11101000
{'C', 0xffea}, /// 11111111 11101010
{'D', 0xfff4}, /// 11111111 11110100
Expand Down Expand Up @@ -240,7 +240,7 @@ void Morse_processor(void)
MS.timebase++;
if (MS.timebase > MS.MPS_pause)
{
HAL_TIM_Base_Stop_IT(&htim14);
/////////////////////////////////////////////////HAL_TIM_Base_Stop_IT(&htim14);
MS.timebase = 0;
MS.duration += MS.MPS_pause; // message duration
switch (MS.MorsePorcessroStage)
Expand Down Expand Up @@ -349,7 +349,7 @@ void Morse_processor(void)
} /* if (MS.timebase > MS.MPS_pause) */

} /* if (MS.MorsePorcessroStage != MPS_Stop) */
HAL_TIM_Base_Start_IT(&htim14);
/////////////////////////////////HAL_TIM_Base_Start_IT(&htim14);
}


Expand Down
7 changes: 7 additions & 0 deletions projects/f0-usb-beacon/Src/stm32f0xx_it.c
Expand Up @@ -10,6 +10,7 @@
#include "stm32f0xx_hal.h"
#include "stm32f0xx.h"
#include "stm32f0xx_it.h"
#include "command.h"

/* External variables --------------------------------------------------------*/
extern PCD_HandleTypeDef hpcd_USB_FS;
Expand Down Expand Up @@ -44,6 +45,7 @@ void USB_IRQHandler(void)
HAL_PCD_IRQHandler(&hpcd_USB_FS);
}

static GPIO_PinState testpin = GPIO_PIN_RESET;

/**
* @brief This function handles TIM14 global interrupt.
Expand All @@ -52,6 +54,11 @@ void TIM14_IRQHandler(void)
{
/* USER CODE BEGIN TIM14_IRQn 0 */

if (GetFtestState() == 1)
{
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_4, testpin);
if (testpin == GPIO_PIN_RESET) testpin = GPIO_PIN_SET; else testpin = GPIO_PIN_RESET;
}
/* USER CODE END TIM14_IRQn 0 */
HAL_TIM_IRQHandler(&htim14);
/* USER CODE BEGIN TIM14_IRQn 1 */
Expand Down

0 comments on commit eb51f0f

Please sign in to comment.