mirror of https://github.com/ARMmbed/mbed-os.git
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).pull/8239/head
parent
6fca23ece1
commit
9215b9d264
|
|
@ -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)
|
||||
{
|
||||
|
|
@ -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);
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -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:
|
||||
|
|
@ -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);
|
||||
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue