Skip to content

F improvements for teensy3 1 to master #12835

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

Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,11 @@ const PinMap PinMap_PWM[] = {
{LED_BLUE , PWM_8 , 3}, // PTA2, FTM0 CH7

// Arduino digital pinout
{D3, PWM_5 , 4}, // PTD4, FTM0 CH4
// Duplicate: {D3, PWM_5 , 4}, // PTD4, FTM0 CH4 // also green led
{D5, PWM_7 , 3}, // PTA1, FTM0 CH6
{D6, PWM_3 , 4}, // PTC3, FTM0 CH2
{D9, PWM_6 , 4}, // PTD5, FTM0 CH6
// Duplicate: {D6, PWM_3 , 4}, // PTC3, FTM0 CH2 // also red led
{D7, PWM_4 , 4}, // PTC4, FTM0_CH3
// Duplicate: {D9, PWM_8 , 3}, // PTA2, FTM0 CH7 // also blue led
{D10, PWM_2 , 4}, // PTC2, FTM0 CH1

{PTA0, PWM_6 , 3}, // PTA0, FTM0 CH5
Expand All @@ -112,7 +113,7 @@ const PinMap PinMap_PWM[] = {
{PTB0, PWM_9 , 3}, // PTB0, FTM1 CH0
{PTB1, PWM_10, 3}, // PTB1, FTM1 CH1
{PTC1, PWM_1 , 4}, // PTC1, FTM0 CH0
{PTD4, PWM_4 , 4}, // PTD4, FTM0 CH3
// Duplicate: {PTD4, PWM_5 , 4}, // PTD4, FTM0 CH4 (also known as D3, and green led)
{PTD6, PWM_7 , 4}, // PTD6, FTM0 CH6
{PTD7, PWM_8 , 4}, // PTD7, FTM0 CH7

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ typedef enum {
PWM_8 = (0 << TPM_SHIFT) | (7), // FTM0 CH7
PWM_9 = (1 << TPM_SHIFT) | (0), // FTM1 CH0
PWM_10 = (1 << TPM_SHIFT) | (1), // FTM1 CH1
PWM_11 = (2 << TPM_SHIFT) | (0), // FTM2 CH0
PWM_12 = (2 << TPM_SHIFT) | (1), // FTM2 CH1
} PWMName;

typedef enum {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ const PinMap PinMap_DAC[] = {
const PinMap PinMap_I2C_SDA[] = {
{PTB1, I2C_0, 2},
{PTB3, I2C_0, 2},
{PTE0, I2C_1, 2},
{PTE0, I2C_1, 6},
{PTC11, I2C_1, 2},
{NC , NC , 0}
};

const PinMap PinMap_I2C_SCL[] = {
{PTB0, I2C_0, 2},
{PTB2, I2C_0, 2},
{PTE1, I2C_1, 2},
{PTE1, I2C_1, 6},
{PTC10, I2C_1, 2},
{NC , NC, 0}
};
Expand Down Expand Up @@ -111,25 +111,24 @@ const PinMap PinMap_SPI_SSEL[] = { // CS

/************PWM***************/
const PinMap PinMap_PWM[] = {
// LEDs
{LED_RED , PWM_3 , 4}, // PTC3, FTM0 CH2
{LED_GREEN, PWM_5, 4}, // PTD4, FTM0 CH4
{LED_BLUE , PWM_8 , 3}, // PTA2, FTM0 CH7

{PTA0, PWM_6 , 3}, // PTA0, FTM0 CH5
{PTA1, PWM_7 , 3}, // PTA1, FTM0 CH6
{PTA2, PWM_8 , 3}, // PTA2, FTM0 CH7
{PTA3, PWM_1 , 3}, // PTA3, FTM0 CH0
{PTA4, PWM_2 , 3}, // PTA4, FTM0 CH1
{PTA5, PWM_3 , 3}, // PTA5, FTM0 CH2
{PTA12, PWM_9 , 3}, // PTA12, FTM1 CH0
{PTA13, PWM_10, 3}, // PTA13, FTM1 CH1
{PTB0, PWM_9 , 3}, // PTB0, FTM1 CH0
{PTB1, PWM_10, 3}, // PTB1, FTM1 CH1
{PTB18, PWM_11, 3}, // PTB18, FTM2 CH0
{PTB19, PWM_12, 3}, // PTB19, FTM2 CH1
{PTC1, PWM_1 , 4}, // PTC1, FTM0 CH0
{PTC2, PWM_2 , 4}, // PTC2, FTM0 CH1
{PTC3, PWM_3 , 4}, // PTC3, FTM0 CH2
{PTD4, PWM_4 , 4}, // PTD4, FTM0 CH3
{PTD5, PWM_6 , 4}, // PTD5, FTM0 CH6
{PTC4, PWM_4 , 4}, // PTC4, FTM0 CH3
{PTD4, PWM_5 , 4}, // PTD4, FTM0 CH4
{PTD5, PWM_6 , 4}, // PTD5, FTM0 CH5
{PTD6, PWM_7 , 4}, // PTD6, FTM0 CH6
{PTD7, PWM_8 , 4}, // PTD7, FTM0 CH7

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ typedef enum {
PWM7 = PTD6,
PWM8 = PTC1,
PWM9 = PTC2,
PWM10 = PTB19,
PWM11 = PTB18,
PWM10 = PTB18,
PWM11 = PTB19,

DAC = DAC0_OUT,

Expand Down
10 changes: 5 additions & 5 deletions targets/TARGET_Freescale/TARGET_K20XX/i2c_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {

pinmap_pinout(sda, PinMap_I2C_SDA);
pinmap_pinout(scl, PinMap_I2C_SCL);
/* enable open drain for I2C pins, only port b available */
uint32_t pin_n = (uint32_t)(sda & 0x7C) >> 2;
PORTB->PCR[pin_n] |= PORT_PCR_ODE_MASK;
pin_n = (uint32_t)(scl & 0x7C) >> 2;
PORTB->PCR[pin_n] |= PORT_PCR_ODE_MASK;
/* enable open drain for I2C pins */
__IO uint32_t* pin_pcr = (__IO uint32_t*)(PORTA_BASE + sda);
*pin_pcr |= PORT_PCR_ODE_MASK;
pin_pcr = (__IO uint32_t*)(PORTA_BASE + scl);
*pin_pcr |= PORT_PCR_ODE_MASK;
}

int i2c_start(i2c_t *obj) {
Expand Down
5 changes: 2 additions & 3 deletions targets/TARGET_Freescale/TARGET_K20XX/pinmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ void pin_function(PinName pin, int function) {
MBED_ASSERT(pin != (PinName)NC);

uint32_t port_n = (uint32_t)pin >> PORT_SHIFT;
uint32_t pin_n = (uint32_t)(pin & 0x7C) >> 2;

SIM->SCGC5 |= 1 << (SIM_SCGC5_PORTA_SHIFT + port_n);
__IO uint32_t* pin_pcr = &(((PORT_Type *)(PORTA_BASE + 0x1000 * port_n)))->PCR[pin_n];

__IO uint32_t* pin_pcr = (__IO uint32_t*)(PORTA_BASE + pin);

// pin mux bits: [10:8] -> 11100000000 = (0x700)
*pin_pcr = (*pin_pcr & ~0x700) | (function << 8);
Expand Down
24 changes: 21 additions & 3 deletions targets/TARGET_Freescale/TARGET_K20XX/pwmout_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,25 @@ void pwmout_init(pwmout_t* obj, PinName pin) {
unsigned int ftm_n = (pwm >> TPM_SHIFT);
unsigned int ch_n = (pwm & 0xFF);

SIM->SCGC6 |= 1 << (SIM_SCGC6_FTM0_SHIFT + ftm_n);

FTM_Type *ftm = (FTM_Type *)(FTM0_BASE + 0x1000 * ftm_n);
if (ftm_n < 2)
{
SIM->SCGC6 |= 1 << (SIM_SCGC6_FTM0_SHIFT + ftm_n);
} else {
#if defined(TARGET_K20DX256)
/* note: the above hashdefine appears to be a misnomer, the two chips supported by this folder are:
* * MK20DX256VLH7 (used by the TEENSY3_1 board)
* * MK20DX128VLH5 (used by the K20D50M board)
* The difference that matters seems to come from the suffix of 5 vs 7. */
SIM->SCGC3 |= 1 << (SIM_SCGC3_FTM2_SHIFT);
#ifndef FTM2_BASE
// Note: FTM2_BASE is missing from TARGET_TEENSY3_1/device/MK20DX256.h
#define FTM2_BASE (0x400B8000)
#endif
ftm = (FTM_Type *)(FTM2_BASE); // placed at non-contiguous address
#endif
}

ftm->CONF |= FTM_CONF_BDMMODE(3);
ftm->SC = FTM_SC_CLKS(1) | FTM_SC_PS(clkdiv); // (clock)MHz / clkdiv ~= (0.75)MHz
ftm->CONTROLS[ch_n].CnSC = (FTM_CnSC_MSB_MASK | FTM_CnSC_ELSB_MASK); /* No Interrupts; High True pulses on Edge Aligned PWM */
Expand Down Expand Up @@ -100,7 +116,9 @@ void pwmout_period_ms(pwmout_t* obj, int ms) {
// Set the PWM period, keeping the duty cycle the same.
void pwmout_period_us(pwmout_t* obj, int us) {
float dc = pwmout_read(obj);
*obj->MOD = (uint32_t)(pwm_clock * (float)us) - 1;
uint32_t new_mod = (uint32_t)(pwm_clock * (float)us) - 1;
if ((new_mod > 0xffff) || (new_mod < 0)) error("PWM period out of range");
*obj->MOD = new_mod;
*obj->SYNC |= FTM_SYNC_SWSYNC_MASK;
pwmout_write(obj, dc);
}
Expand Down
7 changes: 5 additions & 2 deletions targets/targets.json
Original file line number Diff line number Diff line change
Expand Up @@ -1712,10 +1712,13 @@
"SLEEP",
"SPI",
"SPISLAVE",
"STDIO_MESSAGES"
"STDIO_MESSAGES",
"USBDEVICE",
"USTICKER"
],
"release_versions": [
"2"
"2",
"5"
],
"device_name": "MK20DX256xxx7"
},
Expand Down