This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Looks like there is a bug in Halcogen (4.05.02) generated function sciSetBaudrate() in SCI.c for a TMS570LS1224

Other Parts Discussed in Thread: HALCOGEN

The floating point baud rate divisor was truncated instead of rounded - see below

/** @fn void sciSetBaudrate(sciBASE_t *sci, uint32 baud)

* @brief Change baudrate at runtime.

* @param[in] sci - sci module base address

* @param[in] baud - baudrate in Hz

*

* Change the SCI baudrate at runtime.

*/

/* SourceId : SCI_SourceId_003 */

/* DesignId : SCI_DesignId_003 */

/* Requirements : HL_SR232 */

void sciSetBaudrate(sciBASE_t *sci, uint32 baud)

{

float64 vclk = 80.000 * 1000000.0;

uint32 f = ((sci->GCR1 & 2U) == 2U) ? 16U : 1U;

uint32 temp;

float64 temp2;

/* USER CODE BEGIN (6) */

//the halcogen code below does not work when the baud rates start to get above 300 k baud

// the computation for temp2 is correct as a float. However, when it is converted to an int in the

// next line it is truncated instead of rounded. In one case the float was 10.99999 or so but the register

// was set to 10 instead of 11. This resulted in a rate that was far enough off so it didn't work.

// The ifdef below in the user section should eliminate the automatically generated halcogen code with the bug

// and replace it with the code in the next user section after the endif

#ifdef 0

/* USER CODE END */

/*SAFETYMCUSW 96 S MR:6.1 <APPROVED> "Calculations including int and float cannot be avoided" */

temp = (f*(baud));

temp2 = ((vclk)/((float64)temp))-1U;

sci->BRS = (uint32)((uint32)temp2 & 0x00FFFFFFU);

/* USER CODE BEGIN (7) */

#endif

temp = (f*(baud));

temp2 = ((vclk)/((float64)temp))-1U;

sci->BRS = (uint32)((uint32)(temp2 +.5) & 0x00FFFFFFU);

/* USER CODE END */

}