Skip to content

Commit

Permalink
Fixed USB crash if no analog pin defined
Browse files Browse the repository at this point in the history
  • Loading branch information
Yury Vostrenkov committed Mar 7, 2020
1 parent 6624210 commit 25b2c54
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Inc/common_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

//#define DEBUG

#define FIRMWARE_VERSION 0x1412 // v1.4.1b2
#define FIRMWARE_VERSION 0x1413 // v1.4.1b3
#define USED_PINS_NUM 30 // constant for BluePill and BlackPill boards
#define MAX_AXIS_NUM 8 // max 8
#define MAX_BUTTONS_NUM 128 // power of 2, max 128
Expand Down
2 changes: 1 addition & 1 deletion Inc/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

static const dev_config_t init_config =
{
.firmware_version = 0x1412, // do not change
.firmware_version = 0x1413, // do not change

/*
Name of device in devices dispatcher
Expand Down
Binary file modified MDK-ARM/FreeJoy.bin
Binary file not shown.
19 changes: 1 addition & 18 deletions MDK-ARM/FreeJoy.uvoptx
Original file line number Diff line number Diff line change
Expand Up @@ -148,24 +148,7 @@
<Name>UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128 -FS08000000 -FL020000 -FP0($$Device:STM32F103C8$Flash\STM32F10x_128.FLM))</Name>
</SetRegEntry>
</TargetDriverDllRegistry>
<Breakpoint>
<Bp>
<Number>0</Number>
<Type>0</Type>
<LineNumber>90</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>134237344</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>..\Src\leds.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\FreeJoy\../Src/leds.c\90</Expression>
</Bp>
</Breakpoint>
<Breakpoint/>
<WatchWindow1>
<Ww>
<count>0</count>
Expand Down
9 changes: 6 additions & 3 deletions Src/analog.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ analog_data_t deadband_buffer[MAX_AXIS_NUM][DEADBAND_BUF_SIZE];

buttons_state_t axes_buttons[MAX_AXIS_NUM][3];

uint8_t adc_cnt = 0;
uint8_t sensors_cnt = 0;

adc_channel_config_t channel_config[MAX_AXIS_NUM] =
{
{ADC_Channel_0, 0}, {ADC_Channel_1, 1},
Expand Down Expand Up @@ -389,9 +392,6 @@ analog_data_t ShapeFunc (axis_config_t * p_axis_cfg, analog_data_t value, uint8
*/
void AxesInit (dev_config_t * p_dev_config)
{
uint8_t adc_cnt = 0;
uint8_t sensors_cnt = 0;

ADC_InitTypeDef ADC_InitStructure;
DMA_InitTypeDef DMA_InitStructure;

Expand Down Expand Up @@ -506,6 +506,8 @@ void AxesInit (dev_config_t * p_dev_config)
*/
void ADC_Conversion (void)
{
if (adc_cnt > 0)
{
DMA_SetCurrDataCounter(DMA1_Channel1, MAX_AXIS_NUM);
DMA_Cmd(DMA1_Channel1, ENABLE);
ADC_Cmd(ADC1, ENABLE);
Expand All @@ -517,6 +519,7 @@ void ADC_Conversion (void)

ADC_Cmd(ADC1, DISABLE);
DMA_Cmd(DMA1_Channel1, DISABLE);
}
}

/**
Expand Down
9 changes: 4 additions & 5 deletions Src/periphery.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void Timers_Init(dev_config_t * p_dev_config)

RCC_GetClocksFreq(&RCC_Clocks);

// Encoders and HID timer
// Encoders, Axes and HID timer
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);

TIM_TimeBaseStructInit(&TIM_TimeBaseInitStructure);
Expand All @@ -100,12 +100,11 @@ void Timers_Init(dev_config_t * p_dev_config)

TIM_Cmd(TIM1, ENABLE);

// Axes timer
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);

// PWM timer
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
TIM_TimeBaseStructInit(&TIM_TimeBaseInitStructure);
TIM_TimeBaseInitStructure.TIM_Prescaler = RCC_Clocks.PCLK1_Frequency/100000 - 1;
TIM_TimeBaseInitStructure.TIM_Period = 400 - 1; // 2ms
TIM_TimeBaseInitStructure.TIM_Period = 400 - 1; // 2ms, 500Hz
TIM_TimeBaseInitStructure.TIM_ClockDivision = 0;
TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseInitStructure);
Expand Down
1 change: 0 additions & 1 deletion Src/usb_endp.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ void EP1_OUT_Callback(void)

// 2 second delay for joy report
joy_millis = GetTick() + 2000;
//Timers_Pause(2000);

/* Read received data (2 bytes) */
USB_SIL_Read(EP1_OUT, hid_buf);
Expand Down

0 comments on commit 25b2c54

Please sign in to comment.