Skip to content

Fix for pwmout & serial fuart in TMPM46B #8239

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 1 commit into from Oct 8, 2018
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
8 changes: 4 additions & 4 deletions targets/TARGET_TOSHIBA/TARGET_TMPM46B/pwmout_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static const uint32_t prescale_tbl[] = {
2, 8, 32, 64, 128, 256, 512
};

#define CLOCK_FREQUENCY (48000000) // Input source clock
#define CLOCK_FREQUENCY (SystemCoreClock) // Input source clock

void pwmout_init(pwmout_t *obj, PinName pin)
{
Expand Down Expand Up @@ -108,8 +108,8 @@ void pwmout_write(pwmout_t *obj, float value)
}
TMRB_SetFlipFlop(obj->channel, &FFStruct);

if (obj->period > 0.7) {
value = 1; //TMPM46B duty cycle should be < 700ms, above 700ms fixed 50% duty cycle
if (obj->period > 0.560) {
value = 1; // TMPM46B duty cycle should be < 560ms, above 560ms fixed 50% duty cycle
}
// Store the new leading_timing value
obj->leading_timing = obj->trailing_timing - (uint16_t)(obj->trailing_timing * value);
Expand Down Expand Up @@ -148,7 +148,7 @@ void pwmout_period_us(pwmout_t *obj, int us)
seconds = (float)((us) / 1000000.0f);
obj->period = seconds;

if (obj->period > 0.7) {
if (obj->period > 0.560) {
clk_freq = (CLOCK_FREQUENCY / 2);
} else {
clk_freq = CLOCK_FREQUENCY;
Expand Down
44 changes: 33 additions & 11 deletions targets/TARGET_TOSHIBA/TARGET_TMPM46B/serial_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,18 +230,23 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b
case SERIAL_2:
case SERIAL_3:
MBED_ASSERT((data_bits > 6) && (data_bits < 10)); // 0: 7 data bits ... 2: 9 data bits
obj->uart_config.DataBits = data_bits;
obj->uart_config.StopBits = stop_bits;
obj->uart_config.Parity = parity;
obj->uart_config.DataBits = ((data_bits == 7) ? UART_DATA_BITS_7:
((data_bits == 8) ? UART_DATA_BITS_8 : UART_DATA_BITS_9));
obj->uart_config.StopBits = ((stop_bits == 1) ? UART_STOP_BITS_1 : UART_STOP_BITS_2);
obj->uart_config.Parity = ((parity == ParityOdd) ? UART_ODD_PARITY :
((parity == ParityEven) ? UART_EVEN_PARITY : UART_NO_PARITY));
UART_Init(obj->UARTx,&obj->uart_config);
break;
case SERIAL_4:
case SERIAL_5:
FUART_Disable(obj->FUART);
MBED_ASSERT((data_bits > 4) && (data_bits < 9)); // 0: 5 data bits ... 2: 8 data bits
obj->fuart_config.DataBits = data_bits;
obj->fuart_config.StopBits = stop_bits;
obj->fuart_config.Parity = parity;
MBED_ASSERT((data_bits > 6) && (data_bits < 9)); // 0: 5 data bits ... 2: 8 data bits
obj->fuart_config.DataBits = ((data_bits == 7) ? FUART_DATA_BITS_7 : FUART_DATA_BITS_8);
obj->fuart_config.StopBits = ((stop_bits == 1) ? FUART_STOP_BITS_1 : FUART_STOP_BITS_2);
obj->fuart_config.Parity = ((parity == ParityOdd) ? FUART_ODD_PARITY :
((parity == ParityEven) ? FUART_EVEN_PARITY :
((parity == ParityForced1) ? FUART_1_PARITY :
((parity == ParityForced0) ? FUART_0_PARITY : FUART_NO_PARITY))));
FUART_Init(obj->FUART,&obj->fuart_config);
FUART_Enable(obj->FUART);
break;
Expand Down Expand Up @@ -497,11 +502,20 @@ void serial_pinout_tx(PinName tx)
// Set flow control, Just support CTS
void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, PinName txflow)
{
UARTName uart_cts = (UARTName)pinmap_peripheral(txflow, PinMap_UART_CTS);
UARTName uart_rts = (UARTName)pinmap_peripheral(rxflow, PinMap_UART_RTS);
UARTName uart_cts;

// SERIAL_5 & SERIAL_3 have same CTS pin (PA7), only function register is different (4 & 2).
// pinmap_peripheral() will always return first match from the map.
// But, if SERIAL_5 is used, then pinmap_peripheral() should return SERIAL_5 (function register 2 to be set).
if (obj->index == SERIAL_5) {
uart_cts = (UARTName)pinmap_peripheral(txflow, &PinMap_UART_CTS[5]);
} else {
uart_cts = (UARTName)pinmap_peripheral(txflow, PinMap_UART_CTS);
}
UARTName uart_name = (UARTName)pinmap_merge(uart_cts, uart_rts);

switch (obj->index) {
switch (uart_name) {
case SERIAL_0:
case SERIAL_1:
case SERIAL_2:
Expand Down Expand Up @@ -529,7 +543,11 @@ void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, Pi
obj->FUART->CR |= FUART_CTS_FLOW_CTRL;

// Enable the pin for CTS and RTS function
pinmap_pinout(txflow, PinMap_UART_CTS);
if (uart_name == SERIAL_5) {
pinmap_pinout(txflow, &PinMap_UART_CTS[5]);
} else {
pinmap_pinout(txflow, PinMap_UART_CTS);
}
} else if (type == FlowControlRTS) {
MBED_ASSERT(uart_rts != (UARTName) NC);

Expand All @@ -545,7 +563,11 @@ void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, Pi
obj->FUART->CR |= FUART_CTS_FLOW_CTRL | FUART_RTS_FLOW_CTRL;

// Enable the pin for CTS and RTS function
pinmap_pinout(txflow, PinMap_UART_CTS);
if (uart_name == SERIAL_5) {
pinmap_pinout(txflow, &PinMap_UART_CTS[5]);
} else {
pinmap_pinout(txflow, PinMap_UART_CTS);
}
pinmap_pinout(rxflow, PinMap_UART_RTS);
} else {
// Disable CTS and RTS hardware flow control
Expand Down