Added I2C clock config
This commit is contained in:
@@ -10,18 +10,29 @@ void SHAL_init(){
|
||||
|
||||
|
||||
void systick_init(){
|
||||
SysTick->CTRL = 0; //disable first
|
||||
SysTick->LOAD = 0xFFFFFF; //max 24-bit
|
||||
SysTick->VAL = 0; //clear
|
||||
SysTick->CTRL = 0; //Disable first
|
||||
SysTick->LOAD = 0xFFFFFF; //Max 24-bit
|
||||
SysTick->VAL = 0; //Clear
|
||||
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
void SHAL_delay_us(uint32_t us){
|
||||
uint32_t start = SysTick->VAL;
|
||||
uint32_t ticks = us * (SystemCoreClock / 1000000U);
|
||||
|
||||
//handle wraparound with 24-bit mask
|
||||
while (((start - SysTick->VAL) & 0x00FFFFFF) < ticks) { }
|
||||
void SHAL_delay_us(uint32_t us){
|
||||
uint32_t ticks = us * (SystemCoreClock / 1000000U);
|
||||
uint32_t start = SysTick->VAL;
|
||||
|
||||
//Calculate target value (may wrap around)
|
||||
uint32_t target = (start >= ticks) ? (start - ticks) : (start + 0x01000000 - ticks);
|
||||
target &= 0x00FFFFFF;
|
||||
|
||||
//Wait until we reach the target
|
||||
if (start >= ticks) {
|
||||
//No wraparound case
|
||||
while (SysTick->VAL > target) {}
|
||||
} else {
|
||||
while (SysTick->VAL <= start) {} //Wait for wraparound
|
||||
while (SysTick->VAL > target) {} //Wait for target
|
||||
}
|
||||
}
|
||||
|
||||
void SHAL_delay_ms(uint32_t ms){
|
||||
|
||||
Reference in New Issue
Block a user