-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Support for Freescale Kinetis MCUs, kinetis_common #2265
Conversation
NVIC_SetPriority(TIMER_0_IRQ_CHAN, TIMER_IRQ_PRIO); | ||
/* select timer, use channel 0 as prescaler */ | ||
timer = TIMER_0_DEV; | ||
timer->MCR = PIT_MCR_FRZ_MASK; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we freeze the timer here? I can not find an instance below where the FRZ flag is turned off again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This allows the timers to be stopped when the device enters the Debug mode. (MKW2xD RM).
ups, PIT code is a little neglected. I wanted to remove it, because it does not fit in function to riot. Maybe I will find time to rewrite it on the weekend.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I mixed up the FRZ and MDIS flags.
I will do a more thorough review during the weekend or beginning of the next week. The code seems to work on my K60 board as well as @jfischer-phytec-iot 's KW22 board. |
During the porting to kw01z128 I had some problems with identifiers of IRQs (lptmr). It can be resolved if one uses the latest CMSIS compliant header filer. (Contact your FAE to get a newest 😄 ) I currently work at the UART code, there are 3 slightly different UARTs for kinetis MCUs. |
} | ||
else if (dev->S1 & UART_S1_TDRE_MASK) { | ||
if (config[uartnum].tx_cb(config[uartnum].arg) == 0) { | ||
dev->C2 |= (1 << UART_C2_TIE_SHIFT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic seem wrong. TX interrupt is supposed to be disabled if return value is zero. dev->C2 &= ~(1 << UART_C2_TIE_SHIFT);
(or shorter: dev->C2 &= ~(UART_C2_TIE_MASK);
)
See also: http://riot-os.org/api/group__driver__periph__uart.html#ga2aa1686d28caae1aa74baa3d047e8330
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, corrected.
I have been working on this with my K60 port during the day, so far I have successfully used the following modules:
Still some more work to be done on my part for testing the rest of the stuff. |
@Farthen Regarding PIT timers: The timers are always running at the Bus clock frequency, in order to allow for variable frequency it is possible to use one timer as a divider/counter and chain two timers together. What the timer module does is that it counts |
@jfischer-phytec-iot Looking at the SPI driver. I think it can be merged as is, but I would like to suggest some changes to the configuration. I would like to use the two CTAR registers in a different way, in order to be able to communicate with multiple devices with different signal polarities or timings without having to reinitialize the driver over and over. I realize that currently there is no configuration at all, everything is hard coded. I will open a PR later if I find a way to provide a suitable API for the change... |
@Farthen Please write your comments in the "Files Changed" tab, that way the comments and a code snippet will be inlined in the discussion thread for the PR on #2265 |
|
||
switch (LPTIMER_CLKSRC) { | ||
case LPTIMER_CLKSRC_MCGIRCLK: | ||
/* Select MCGIRCLK as clock source */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should enable MCGIRCLK first, as this is not the default.
MCG->C1 |= MCG_C1_IRCLKEN_MASK;
// For fast internal clock
MCG->C2 |= MCG_C2_IRCS_MASK;
while(!(MCG->S & MCG_S_IRCST_MASK));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But that is a option for MCG driver or your cpu_clock_init, not for LPTMR driver.
*/ | ||
|
||
/** | ||
* @addtogroup cpu_kinetis_common Common Drivers for Freescale Kinetis MCUs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to @ingroup cpu_kinetis_common
, put the textual description of the group in the @defgroup
command, create a doc.txt similar to what some other CPU directories have.
This applies for all other uses of @addtogroup cpu_kinetis_common
below as well. (I won't put a comment on every one, they are too many)
case ADC_RES_10BIT: | ||
case ADC_RES_12BIT: | ||
case ADC_RES_14BIT: | ||
case ADC_RES_16BIT: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For each case, add:
adc_config[dev].max_value = (1 << numbits) - 1;
I noticed some issues with the ADC driver when using it on the K60. Some of the analog pins on the K60 are not configurable through the pin mux and do not have a corresponding PORTx->PCR entry. I will add support for @jfischer-phytec-iot I will take care of the issues in the ADC driver and open a PR against your branch (this PR) when I have fixed it. See above for my other comments on the other |
@gebart ok |
@jfischer-phytec-iot |
KINETIS_MCG_FEI, /**< FLL Engaged Internal Mode */ | ||
} kinetis_mcg_mode_t; | ||
|
||
uint32_t cpufreq; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace by an extern declaration (if this is indeed used in any other files than mcg.c):
extern uint32_t cpufreq;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cpufreq is a zombie, it was planned that the mcg driver calculates current cpu frequency, but because of lack of time it has not been done. I will remove it for now.
@jfischer-phytec-iot |
break; | ||
} | ||
|
||
adc_config[dev].max_value = (1 << adc_config[dev].bits); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot to subtract 1 here.. Please change this to:
adc_config[dev].max_value = (1 << adc_config[dev].bits) - 1;
I believe this is ready for merge after squashing and fixing the off by one error in adc.c (caused by me, oops!) |
add peripheral drivers for Freescale Kinetis MCUs: adc driver cpuid driver gpio driver hwtimer_arch driver (hwtimer used Low Power Timer) i2c driver (master mode only) mcg driver pwm driver random_rnga driver random_rngb driver rtc driver spi driver timer driver (timer used Periodic Interrupt Timer) uart driver add doc.txt (configuration examples) random_rnga: Update RNGA driver in preparation for RNGB driver. random_rngb: Add RNGB driver. spi: refactor SPI to work for multiple CTARS, add spi_acquire, spi_release gpio: Add gpio_irq_enable, gpio_irq_disable. Refactor GPIO. gpio: Add gpio_irq_enable, gpio_irq_disable. gpio: Refactor ISR functions to work with all GPIOs (0-31) and all ports (PORTA-PORTH) adc: Refactor ADC, add calibration and scaling. Added integer scaling of results in adc_map. Handle precision setting in adc_init. Set ADC clock divider depending on module clock. Add ADC_1 as a possible device. Add ADC calibration procedure according to K60 ref manual. Handle ADC pins which are not part of the pin function mux. Signed-off-by: Joakim Gebart <[email protected]>
ACK |
Support for Freescale Kinetis MCUs, kinetis_common
Great! Congrats and thanks for the effort. |
PRs/MCUs depend on kinetis_common: