Page 2 of 3

Re: Serial Initialization in Dem Crashes on Nucleo STM32F030

Posted: Thu Oct 16, 2014 1:03 pm
by carldong
But that doesn't explain why not even a signal is sent through Tx. I tried the CodeSourcery GCC 4.8 toolchain and the suggested 4.7 from launchpad, but neither works. Also, did you get the ST-Link one work on linux? I never get anything from /dev/ttyACM0. I will try to write my own UART code to test whether it is because of ChibiOS or not.
Giovanni wrote:Those are problems related to your platform, I never used gentoo so can't help there.

Giovanni

Re: Serial Initialization in Dem Crashes on Nucleo STM32F030

Posted: Thu Oct 16, 2014 3:55 pm
by Giovanni
I made the ST-Link 1 work under Ubuntu years ago but it was a mess because you have to put the device into an exclusion list (different from Linux to Linux), there is a small guide in the OpenOCD documentation.

ST-Link 2 was much easier but still there was a setting to do.

Giovanni

Re: Serial Initialization in Dem Crashes on Nucleo STM32F030

Posted: Thu Oct 16, 2014 8:26 pm
by carldong
I believe Nucleo is ST-Link 2. I will try look for the guide, but I am not sure if I can find it.

Giovanni wrote:I made the ST-Link 1 work under Ubuntu years ago but it was a mess because you have to put the device into an exclusion list (different from Linux to Linux), there is a small guide in the OpenOCD documentation.

ST-Link 2 was much easier but still there was a setting to do.

Giovanni

Re: Serial Initialization in Dem Crashes on Nucleo STM32F030

Posted: Thu Oct 16, 2014 8:38 pm
by Giovanni
Nucleo is ST-Link 2-1, I never tried this one under Linux. It has multiple USB devices implemented so it is possible a whole new set of problems....

Giovanni

Re: Serial Initialization in Dem Crashes on Nucleo STM32F030

Posted: Thu Oct 16, 2014 11:41 pm
by carldong
OK... However, I cannot even get USART1 with and external TTL-USB to work. I am trying to use some standalone code to test the serial out, but not yet successful.

Code: Select all

int uart_open(USART_TypeDef* USARTx, uint32_t baud, uint32_t flags) {
  if (USARTx == USART1) {
    RCC->AHBENR |= RCC_AHBENR_GPIOAEN;
    RCC->APB2ENR |= RCC_APB2ENR_USART1EN;
    /* PA2, Tx, AF1 */
    GPIOA->MODER &= ~(GPIO_MODER_MODER2);
    GPIOA->MODER |= GPIO_MODER_MODER2_1;
    GPIOA->PUPDR &= ~(GPIO_PUPDR_PUPDR2);
    GPIOA->PUPDR |= (GPIO_PUPDR_PUPDR2_0);
    GPIOA->OTYPER &= GPIO_OTYPER_OT_2;
    GPIOA->OSPEEDR |= ~GPIO_OSPEEDER_OSPEEDR2;
    /* PA3, Rx, In Float */
    GPIOA->MODER &= ~(GPIO_MODER_MODER3);
    GPIOA->PUPDR &= ~(GPIO_PUPDR_PUPDR3);
    /* AF 1 */
    GPIOA->AFRL &= ~(GPIO_AFRL_AFRL2 | GPIO_AFRL_AFRL3);
    GPIOA->AFRL |= (0b0001 << 8) | (0b0001 << 12);
  }
  /* Reset */
  USARTx->CR1 = 0x0000;
  USARTx->CR1 &= ~(USART_CR1_M);
  /* Reset */
  USARTx->CR2 = 0x0000;
  /* Reset */
  USARTx->CR3 = 0x0000;
  /* Baud */
  USARTx->BRR = SYSCLK / baud;

  /* Enable */
  USARTx->CR1 |= USART_CR1_TE | USART_CR1_RE | USART_CR1_UE;
}

int uart_putc(char c, USART_TypeDef* USARTx)
{
  while (!(USARTx->ISR & USART_ISR_TXE));
  USARTx->TDR =  (c & 0xff);
  return 0;
}


I cannot even measure anything from the Tx pin.

Giovanni wrote:Nucleo is ST-Link 2-1, I never tried this one under Linux. It has multiple USB devices implemented so it is possible a whole new set of problems....

Giovanni

Re: Serial Initialization in Dem Crashes on Nucleo STM32F030

Posted: Thu Oct 16, 2014 11:54 pm
by carldong
OK, I found some very small note saying that PA2 and PA3 as USART1 is 'STM32F030x6/4 only', and on Nucleo, where STM32F030x8 is used, USART1 is connected to PA9 and PA10. This could be the problem.

Re: Serial Initialization in Dem Crashes on Nucleo STM32F030

Posted: Fri Oct 17, 2014 12:03 am
by carldong
OK, my own standalone version works now. I reconfigured GPIO to TX->PA9 and RX->PA10,

Code: Select all

int uart_open(USART_TypeDef* USARTx, uint32_t baud, uint32_t flags) {
  if (USARTx == USART1) {
    RCC->AHBENR |= RCC_AHBENR_GPIOAEN;
    RCC->APB2ENR |= RCC_APB2ENR_USART1EN;
    /* PA2, Tx, AF1 */
    GPIOA->MODER &= ~(GPIO_MODER_MODER9);
    GPIOA->MODER |= GPIO_MODER_MODER9_1;
    GPIOA->PUPDR &= ~(GPIO_PUPDR_PUPDR9);
    GPIOA->PUPDR |= (GPIO_PUPDR_PUPDR9_0);
    GPIOA->OTYPER &= GPIO_OTYPER_OT_9;
    GPIOA->OSPEEDR |= ~GPIO_OSPEEDER_OSPEEDR9;
    /* PA3, Rx, In Float */
    GPIOA->MODER &= ~(GPIO_MODER_MODER10);
    GPIOA->PUPDR &= ~(GPIO_PUPDR_PUPDR10);
    /* AF 1 */
    GPIOA->AFRH &= ~(GPIO_AFRH_AFRH1 | GPIO_AFRH_AFRH2);
    GPIOA->AFRH |= (0b0001 << 4) | (0b0001 << 8);
  }
  /* Reset */
  USARTx->CR1 = 0x0000;
  USARTx->CR1 &= ~(USART_CR1_M);
  /* Reset */
  USARTx->CR2 = 0x0000;
  /* Reset */
  USARTx->CR3 = 0x0000;
  /* Baud */
  USARTx->BRR = SYSCLK / baud;

  /* Enable */
  USARTx->CR1 |= USART_CR1_TE | USART_CR1_RE | USART_CR1_UE;
}

int uart_putc(char c, USART_TypeDef* USARTx)
{
  while (!(USARTx->ISR & USART_ISR_TXE));
  USARTx->TDR =  (c & 0xff);
  return 0;
}

Re: Serial Initialization in Dem Crashes on Nucleo STM32F030

Posted: Fri Oct 17, 2014 12:22 am
by carldong
Now I am trying the ChibiOS one:

Code: Select all

 
  sdStart(&SD1, NULL)
  while (TRUE) {
    if (!palReadPad(GPIOC, GPIOC_BUTTON))
      TestThread(&SD1);
    chThdSleepMilliseconds(500);
  }

And nothing shows up. I am still plugging into the same pins now.

Re: Serial Initialization in Dem Crashes on Nucleo STM32F030

Posted: Fri Oct 17, 2014 12:40 am
by carldong
OK, I solved it. I changed definitions in

Code: Select all

boards/ST_NUCLEO_F030R8/board.h
for the functions of PA9/PA10. BTW, I renamed USART_TX to USART2_TX and USART_RX to USART2_RX, while changing the PA9 and PA10 to USART1_TX and USART1_RX, and along with their functions.

Re: Serial Initialization in Dem Crashes on Nucleo STM32F030

Posted: Fri Oct 17, 2014 2:08 am
by carldong
Of course, USART2 does not work. I don't know any fixes of this, so I will just go for USART1 + TTL-USB board for now.