Skip to content

Q12018 stm32 ustickers #6463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions targets/TARGET_STM/hal_tick_16b.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@

extern TIM_HandleTypeDef TimMasterHandle;

extern volatile uint32_t SlaveCounter;
extern volatile uint32_t oc_int_part;

volatile uint32_t PreviousVal = 0;

void us_ticker_irq_handler(void);
Expand All @@ -37,14 +34,6 @@ void timer_irq_handler(void)
#endif
TimMasterHandle.Instance = TIM_MST;

// Clear Update interrupt flag
if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_UPDATE) == SET) {
if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_UPDATE) == SET) {
__HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_UPDATE);
SlaveCounter++;
}
}

#if defined(TARGET_STM32F0)
} // end timer_update_irq_handler function
// Used for mbed timeout (channel 1) and HAL tick (channel 2)
Expand All @@ -57,12 +46,7 @@ void timer_oc_irq_handler(void)
if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) {
if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) {
__HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1);

if (oc_int_part > 0) {
oc_int_part--;
} else {
us_ticker_irq_handler();
}
}
}

Expand Down Expand Up @@ -142,7 +126,6 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
#endif

// Enable interrupts
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_UPDATE); // For 32-bit counter
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); // For HAL tick

// Enable timer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,27 @@
#include "PeripheralNames.h"
#include "hal_tick.h"

// A 32-bit timer is used
#if !TIM_MST_16BIT
#if TIM_MST_16BIT
#define TIMER_TICKER_BIT_WIDTH 16
#else
#define TIMER_TICKER_BIT_WIDTH 32
#endif

TIM_HandleTypeDef TimMasterHandle;

const ticker_info_t* us_ticker_get_info()
{
static const ticker_info_t info = {
1000000,
TIMER_TICKER_BIT_WIDTH
};
return &info;
}

void us_ticker_init(void)
{
/* NOTE: assuming that HAL tick has already been initialized! */
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1);
}

uint32_t us_ticker_read()
Expand All @@ -37,18 +50,20 @@ void us_ticker_set_interrupt(timestamp_t timestamp)
{
// NOTE: This function must be called with interrupts disabled to keep our
// timer interrupt setup atomic

// disable IT while we are handling the correct timestamp
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1);
// Set new output compare value
__HAL_TIM_SET_COMPARE(&TimMasterHandle, TIM_CHANNEL_1, (uint32_t)timestamp);
// Ensure the compare event starts clear
__HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_CC1);
// Enable IT
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1);
}

void us_ticker_fire_interrupt(void)
{
__HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_CC1);
LL_TIM_GenerateEvent_CC1(TimMasterHandle.Instance);
// Enable IT
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1);
}

/* NOTE: must be called with interrupts disabled! */
Expand All @@ -63,4 +78,3 @@ void us_ticker_clear_interrupt(void)
__HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_CC1);
}

#endif // !TIM_MST_16BIT
191 changes: 0 additions & 191 deletions targets/TARGET_STM/us_ticker_16b.c

This file was deleted.

2 changes: 1 addition & 1 deletion targets/targets.json
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@
"help": "default RX STDIO pins is defined in PinNames.h file, but it can be overridden"
}
},
"device_has": ["ANALOGIN", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES"]
"device_has": ["ANALOGIN", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES", "USTICKER"]
},
"MIMXRT1050_EVK": {
"supported_form_factors": ["ARDUINO"],
Expand Down