I am working with a STM32F103C8 controller. My Application needs 3 UARTs and the SPI Bus for operation.
I am using the template for ARMCM3-STM32F103-FATFS.
When i use the default template, it works fine, i can read/write to the SD Card. In this example SERIAL2 is used under the serial driver system ( that comes default, it has a shell attached to it).
For my application, i enabled UART3 and UART1. When i enable UART1, the SD Card stops working, as in its not detected at all. But when i initialize UART3 it works fine without any problems.
I checked no pins are interchanging or affecting the SPI2 Pins. Pin configuration is also done safely.
I am attaching the Main Loop for the code.
Code: Select all
int main(void) {
static const evhandler_t evhndl[] = {
InsertHandler,
RemoveHandler
};
Thread *shelltp = NULL;
struct EventListener el0, el1;
/*
* System initializations.
* - HAL initialization, this also initializes the configured device drivers
* and performs the board-specific initializations.
* - Kernel initialization, the main() function becomes a thread and the
* RTOS is active.
*/
halInit();
chSysInit();
//UART 1 & 3 Initialization
uartStart(&UARTD1, &uart_cfg_1);
uartStart(&UARTD3, &uart_cfg_1);
/*
* Activates the serial driver 2 using the driver default configuration.
*/
sdStart(&SD2, NULL);
/*
* Shell manager initialization.
*/
shellInit();
/*
* Initializes the MMC driver to work with SPI2.
*/
palSetPadMode(IOPORT2, 13, PAL_MODE_STM32_ALTERNATE_PUSHPULL); /* SCK. */
palSetPadMode(IOPORT2, 14, PAL_MODE_STM32_ALTERNATE_PUSHPULL); /* MISO. */
palSetPadMode(IOPORT2, 15, PAL_MODE_STM32_ALTERNATE_PUSHPULL); /* MOSI. */
palSetPadMode(IOPORT2, 12, PAL_MODE_OUTPUT_PUSHPULL); /* CS. */
//UART1
palSetPadMode(IOPORT1, 9, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
palSetPadMode(IOPORT1, 10, PAL_MODE_INPUT);
uartStartSend(&UARTD1, 5, "UART1");
//UART3
palSetPadMode(IOPORT2, 10, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
palSetPadMode(IOPORT2, 11, PAL_MODE_INPUT);
uartStartSend(&UARTD3, 5, "UART3");
//Cs for SD Card
palSetPad(IOPORT2, GPIOB_SPI2NSS);
mmcObjectInit(&MMCD1);
mmcStart(&MMCD1, &mmccfg);
/*
* Activates the card insertion monitor.
*/
tmr_init(&MMCD1);
/*
* Creates the blinker thread.
*/
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
/*
* Normal main() thread activity, in this demo it does nothing except
* sleeping in a loop and listen for events.
*/
chEvtRegister(&inserted_event, &el0, 0);
chEvtRegister(&removed_event, &el1, 1);
while (TRUE) {
if (!shelltp)
shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO);
else if (chThdTerminated(shelltp)) {
chThdRelease(shelltp); /* Recovers memory of the previous shell. */
shelltp = NULL; /* Triggers spawning of a new shell. */
}
chEvtDispatch(evhndl, chEvtWaitOneTimeout(ALL_EVENTS, MS2ST(500)));
}
return 0;
}
mcuconfig.h reads the following
Code: Select all
/*
* SERIAL driver system settings.
*/
#define STM32_SERIAL_USE_USART1 FALSE
#define STM32_SERIAL_USE_USART2 TRUE
#define STM32_SERIAL_USE_USART3 FALSE
#define STM32_SERIAL_USE_UART4 FALSE
#define STM32_SERIAL_USE_UART5 FALSE
#define STM32_SERIAL_USART1_PRIORITY 12
#define STM32_SERIAL_USART2_PRIORITY 12
#define STM32_SERIAL_USART3_PRIORITY 12
#define STM32_SERIAL_UART4_PRIORITY 12
#define STM32_SERIAL_UART5_PRIORITY 12
/*
* SPI driver system settings.
*/
#define STM32_SPI_USE_SPI1 FALSE
#define STM32_SPI_USE_SPI2 TRUE
#define STM32_SPI_USE_SPI3 FALSE
#define STM32_SPI_SPI1_DMA_PRIORITY 1
#define STM32_SPI_SPI2_DMA_PRIORITY 1
#define STM32_SPI_SPI3_DMA_PRIORITY 1
#define STM32_SPI_SPI1_IRQ_PRIORITY 5
#define STM32_SPI_SPI2_IRQ_PRIORITY 5
#define STM32_SPI_SPI3_IRQ_PRIORITY 5
#define STM32_SPI_DMA_ERROR_HOOK(spip) chSysHalt()
/*
* UART driver system settings.
*/
#define STM32_UART_USE_USART1 TRUE
#define STM32_UART_USE_USART2 FALSE
#define STM32_UART_USE_USART3 TRUE
#define STM32_UART_USART1_IRQ_PRIORITY 10
#define STM32_UART_USART2_IRQ_PRIORITY 10
#define STM32_UART_USART3_IRQ_PRIORITY 10
#define STM32_UART_USART1_DMA_PRIORITY 2
#define STM32_UART_USART2_DMA_PRIORITY 2
#define STM32_UART_USART3_DMA_PRIORITY 2
#define STM32_UART_DMA_ERROR_HOOK(uartp) chSysHalt()
Code: Select all
uartStart(&UARTD1, &uart_cfg_1);When UART1 is not initialized (the above statement is commented) , the SD card works fine (can read/write into it).
UART3 works fine without any issues, only when UART1 is initialized the SD Card Doesn't get initialized.
Am I missing something?