Skip to content
Snippets Groups Projects
Commit 2ccd7ad9 authored by Federico's avatar Federico
Browse files

Bugfixes to stormtrooper driver

parent 30e784e3
No related branches found
No related tags found
No related merge requests found
......@@ -63,8 +63,10 @@ void IRQbspInit()
RCC_AHB1ENR_GPIOCEN | RCC_AHB1ENR_GPIODEN |
RCC_AHB1ENR_GPIOHEN;
RCC_SYNC();
//TODO: maybe configure GPIO speed to fast speed mode??
GPIOA->OSPEEDR=0xaaaaaaaa; //Default to 50MHz speed for all GPIOS
GPIOB->OSPEEDR=0xaaaaaaaa;
GPIOC->OSPEEDR=0xaaaaaaaa;
GPIOD->OSPEEDR=0xaaaaaaaa;
using namespace memories;
sck::mode(Mode::ALTERNATE);
......
/***************************************************************************
* Copyright (C) 2013 by Terraneo Federico *
* Copyright (C) 2010, 2011, 2012 by Terraneo Federico *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
......@@ -26,16 +26,18 @@
***************************************************************************/
#include "interfaces/delays.h"
#include "interfaces/arch_registers.h"
namespace miosix {
void delayMs(unsigned int mseconds)
{
//This platform supports dynamic frequency scaling, two values: 120/26MHz
//Note: delays were never tested agains an oscilloscope when the frequency
//is 26MHz, so may not be accurate!
register const unsigned int count=SystemCoreClock==120000000 ? 29999 : 6499;
#ifndef __CODE_IN_XRAM
#ifdef SYSCLK_FREQ_120MHz
register const unsigned int count=29999;
#else
#warning "Delays are uncalibrated for this clock frequency"
#endif
for(unsigned int i=0;i<mseconds;i++)
{
......@@ -47,15 +49,16 @@ void delayMs(unsigned int mseconds)
" addlo r1, r1, #1 \n"
" blo ___loop_m \n"::"r"(count):"r1");
}
#else //__CODE_IN_XRAM
#error "No delays"
#endif //__CODE_IN_XRAM
}
void delayUs(unsigned int useconds)
{
//This platform supports dynamic frequency scaling, two values: 120/26MHz
//Note: delays were never tested agains an oscilloscope when the frequency
//is 26MHz, so may not be accurate!
if(SystemCoreClock==120000000)
{
#ifndef __CODE_IN_XRAM
// This delay has been calibrated to take x microseconds
// It is written in assembler to be independent on compiler optimization
asm volatile(" mov r1, #30 \n"
......@@ -65,18 +68,10 @@ void delayUs(unsigned int useconds)
" itt lo \n"
" addlo r1, r1, #1 \n"
" blo ___loop_u \n"::"r"(useconds):"r1","r2");
} else {
// This delay NEEDS CALIBRATION
// It is written in assembler to be independent on compiler optimization
asm volatile(" mov r1, #6 \n"
" mul r2, %0, r1 \n"
" mov r1, #0 \n"
"___loop_k: nop \n"
" cmp r1, r2 \n"
" itt lo \n"
" addlo r1, r1, #1 \n"
" blo ___loop_k \n"::"r"(useconds):"r1","r2");
}
#else //__CODE_IN_XRAM
#error "No delays"
#endif //__CODE_IN_XRAM
}
} //namespace miosix
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment