Skip to content

Commit 334dab3

Browse files
Ganesh Ramachandranadbridge
authored andcommitted
Fixed pwmout & serial fuart
pwmout: Used SystemCoreClock Serial fuart: 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. Hence changed as, if SERIAL_5 is used, then pinmap_peripheral() should return SERIAL_5 (function register 2 to be set).
1 parent 976c54b commit 334dab3

File tree

2 files changed

+37
-15
lines changed

2 files changed

+37
-15
lines changed

targets/TARGET_TOSHIBA/TARGET_TMPM46B/pwmout_api.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static const uint32_t prescale_tbl[] = {
3737
2, 8, 32, 64, 128, 256, 512
3838
};
3939

40-
#define CLOCK_FREQUENCY (48000000) // Input source clock
40+
#define CLOCK_FREQUENCY (SystemCoreClock) // Input source clock
4141

4242
void pwmout_init(pwmout_t *obj, PinName pin)
4343
{
@@ -108,8 +108,8 @@ void pwmout_write(pwmout_t *obj, float value)
108108
}
109109
TMRB_SetFlipFlop(obj->channel, &FFStruct);
110110

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

151-
if (obj->period > 0.7) {
151+
if (obj->period > 0.560) {
152152
clk_freq = (CLOCK_FREQUENCY / 2);
153153
} else {
154154
clk_freq = CLOCK_FREQUENCY;

targets/TARGET_TOSHIBA/TARGET_TMPM46B/serial_api.c

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -230,18 +230,23 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b
230230
case SERIAL_2:
231231
case SERIAL_3:
232232
MBED_ASSERT((data_bits > 6) && (data_bits < 10)); // 0: 7 data bits ... 2: 9 data bits
233-
obj->uart_config.DataBits = data_bits;
234-
obj->uart_config.StopBits = stop_bits;
235-
obj->uart_config.Parity = parity;
233+
obj->uart_config.DataBits = ((data_bits == 7) ? UART_DATA_BITS_7:
234+
((data_bits == 8) ? UART_DATA_BITS_8 : UART_DATA_BITS_9));
235+
obj->uart_config.StopBits = ((stop_bits == 1) ? UART_STOP_BITS_1 : UART_STOP_BITS_2);
236+
obj->uart_config.Parity = ((parity == ParityOdd) ? UART_ODD_PARITY :
237+
((parity == ParityEven) ? UART_EVEN_PARITY : UART_NO_PARITY));
236238
UART_Init(obj->UARTx,&obj->uart_config);
237239
break;
238240
case SERIAL_4:
239241
case SERIAL_5:
240242
FUART_Disable(obj->FUART);
241-
MBED_ASSERT((data_bits > 4) && (data_bits < 9)); // 0: 5 data bits ... 2: 8 data bits
242-
obj->fuart_config.DataBits = data_bits;
243-
obj->fuart_config.StopBits = stop_bits;
244-
obj->fuart_config.Parity = parity;
243+
MBED_ASSERT((data_bits > 6) && (data_bits < 9)); // 0: 5 data bits ... 2: 8 data bits
244+
obj->fuart_config.DataBits = ((data_bits == 7) ? FUART_DATA_BITS_7 : FUART_DATA_BITS_8);
245+
obj->fuart_config.StopBits = ((stop_bits == 1) ? FUART_STOP_BITS_1 : FUART_STOP_BITS_2);
246+
obj->fuart_config.Parity = ((parity == ParityOdd) ? FUART_ODD_PARITY :
247+
((parity == ParityEven) ? FUART_EVEN_PARITY :
248+
((parity == ParityForced1) ? FUART_1_PARITY :
249+
((parity == ParityForced0) ? FUART_0_PARITY : FUART_NO_PARITY))));
245250
FUART_Init(obj->FUART,&obj->fuart_config);
246251
FUART_Enable(obj->FUART);
247252
break;
@@ -497,11 +502,20 @@ void serial_pinout_tx(PinName tx)
497502
// Set flow control, Just support CTS
498503
void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, PinName txflow)
499504
{
500-
UARTName uart_cts = (UARTName)pinmap_peripheral(txflow, PinMap_UART_CTS);
501505
UARTName uart_rts = (UARTName)pinmap_peripheral(rxflow, PinMap_UART_RTS);
506+
UARTName uart_cts;
507+
508+
// SERIAL_5 & SERIAL_3 have same CTS pin (PA7), only function register is different (4 & 2).
509+
// pinmap_peripheral() will always return first match from the map.
510+
// But, if SERIAL_5 is used, then pinmap_peripheral() should return SERIAL_5 (function register 2 to be set).
511+
if (obj->index == SERIAL_5) {
512+
uart_cts = (UARTName)pinmap_peripheral(txflow, &PinMap_UART_CTS[5]);
513+
} else {
514+
uart_cts = (UARTName)pinmap_peripheral(txflow, PinMap_UART_CTS);
515+
}
502516
UARTName uart_name = (UARTName)pinmap_merge(uart_cts, uart_rts);
503517

504-
switch (obj->index) {
518+
switch (uart_name) {
505519
case SERIAL_0:
506520
case SERIAL_1:
507521
case SERIAL_2:
@@ -529,7 +543,11 @@ void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, Pi
529543
obj->FUART->CR |= FUART_CTS_FLOW_CTRL;
530544

531545
// Enable the pin for CTS and RTS function
532-
pinmap_pinout(txflow, PinMap_UART_CTS);
546+
if (uart_name == SERIAL_5) {
547+
pinmap_pinout(txflow, &PinMap_UART_CTS[5]);
548+
} else {
549+
pinmap_pinout(txflow, PinMap_UART_CTS);
550+
}
533551
} else if (type == FlowControlRTS) {
534552
MBED_ASSERT(uart_rts != (UARTName) NC);
535553

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

547565
// Enable the pin for CTS and RTS function
548-
pinmap_pinout(txflow, PinMap_UART_CTS);
566+
if (uart_name == SERIAL_5) {
567+
pinmap_pinout(txflow, &PinMap_UART_CTS[5]);
568+
} else {
569+
pinmap_pinout(txflow, PinMap_UART_CTS);
570+
}
549571
pinmap_pinout(rxflow, PinMap_UART_RTS);
550572
} else {
551573
// Disable CTS and RTS hardware flow control

0 commit comments

Comments
 (0)