7 years, 8 months ago.

MODSERIAL port works for printf and getc etc but hangs when I change baud etc.

My MODSERIAL port seems to work when I do things like pc.putc(pc.getc()); and pc.printf("test"); but hangs when I do things like pc.baud(115200); and pc.format(8, Serial::Even, 2);.

What is likely to be the problem ?

My MODSERIAL port files below.

.h file

  1. ifdef TARGET_NUCLEO_F767ZI
  1. define MODSERIAL_IRQ_REG ((USART_TypeDef*)_base)->CR1
  2. define DISABLE_TX_IRQ MODSERIAL_IRQ_REG &= USART_CR1_TXEIE
  3. define DISABLE_RX_IRQ MODSERIAL_IRQ_REG &= USART_CR1_RXNEIE
  4. define ENABLE_TX_IRQ MODSERIAL_IRQ_REG |= USART_CR1_TXEIE
  5. define ENABLE_RX_IRQ MODSERIAL_IRQ_REG |= USART_CR1_RXNEIE
  1. define MODSERIAL_READ_REG ((USART_TypeDef*)_base)->RDR
  2. define MODSERIAL_WRITE_REG ((USART_TypeDef*)_base)->TDR
  3. define MODSERIAL_READABLE ((((USART_TypeDef*)_base)->ISR & USART_ISR_RXNE) != 0)
  4. define MODSERIAL_WRITABLE ((((USART_TypeDef*)_base)->ISR & USART_ISR_TXE) != 0)
  1. define RESET_TX_FIFO while(0 == 1)
  2. define RESET_RX_FIFO while(MODSERIAL_READABLE) char dummy = MODSERIAL_READ_REG
  1. define RX_IRQ_ENABLED ((MODSERIAL_IRQ_REG & USART_CR1_RXNEIE) != 0)
  2. define TX_IRQ_ENABLED ((MODSERIAL_IRQ_REG & USART_CR1_TXEIE) != 0)
  1. endif
  1. ifdef TARGET_NUCLEO_F767ZI
  2. include "MODSERIAL.h"

.cpp file void MODSERIAL::setBase(void ) { switch( _serial.index ) { switch( _serial.serial.index ) {

case 0: _base = USART1; _IRQ = USART1_IRQn; break; case 1: _base = USART2; _IRQ = USART2_IRQn; break; case 2: _base = USART3; _IRQ = USART3_IRQn; break; case 3: _base = USART6; _IRQ = USART6_IRQn; break; default: _base = NULL; _IRQ = (IRQn_Type)NULL; break; } }

void MODSERIAL::initDevice(void) {};

bool MODSERIAL::txIsBusy( void ) { return ( (((USART_TypeDef*)_base)->ISR & ( 1UL << 6 )) == 0 ) ? true : false; }

  1. endif

I hadn't added in the UART's.

  1. ifdef TARGET_NUCLEO_F767ZI
  2. include "MODSERIAL.h"

void MODSERIAL::setBase(void ) { switch( _serial.index ) { switch( _serial.serial.index ) {

case 0: _base = USART1; _IRQ = USART1_IRQn; break; case 1: _base = USART2; _IRQ = USART2_IRQn; break; case 2: _base = USART3; _IRQ = USART3_IRQn; break; case 3: _base = UART4; _IRQ = UART4_IRQn; break; case 4: _base = UART5; _IRQ = UART5_IRQn; break; case 5: _base = USART6; _IRQ = USART6_IRQn; break; case 6: _base = UART7; _IRQ = UART7_IRQn; break; case 7: _base = UART8; _IRQ = UART8_IRQn; break; default: _base = NULL; _IRQ = (IRQn_Type)NULL; break; } }

void MODSERIAL::initDevice(void) {};

bool MODSERIAL::txIsBusy( void ) { return ( (((USART_TypeDef*)_base)->ISR & ( 1UL << 6 )) == 0 ) ? true : false; }

  1. endif
posted by David Fisher 06 Apr 2017
Be the first to answer this question.