Platform: STM32F103C8_MINIMAL (stm32c8t6)
Toolchain: gcc-arm-none-eabi-6-2017-q2-update
Code: Select all
#include "hal.h"
#include "ch.h"
#include "chprintf.h"
THD_WORKING_AREA(waThread1, 32);
THD_FUNCTION(Thread1, arg) {
(void)arg;
palSetPadMode(GPIOC, GPIOC_LED, PAL_MODE_OUTPUT_OPENDRAIN);
while (true) {
palTogglePad(GPIOC, GPIOC_LED);
chThdSleepMilliseconds(250);
}
}
THD_WORKING_AREA(waThread2, 128);
THD_FUNCTION(Thread2, arg) {
(void)arg;
uint8_t buff;
BaseSequentialStream* chp = (BaseSequentialStream*) &SD1;
sdStart(&SD1, NULL);
palSetPadMode(GPIOA, 9, PAL_MODE_STM32_ALTERNATE_OPENDRAIN); // USART1 TX
palSetPadMode(GPIOA, 10, PAL_MODE_INPUT); // USART1 RX
while (true) {
uint8_t len = sdReadTimeout(&SD1, &buff, 1, 500);
if (len) {
chprintf(chp, "%02x\r\n", buff);
} else {
chnWrite(&SD1, (const uint8_t *)"Hello World, ", 13);
chprintf(chp, "%u\r\n", chVTGetSystemTimeX());
}
}
}
THD_TABLE_BEGIN
THD_TABLE_ENTRY(waThread1, "blinker1", Thread1, NULL)
THD_TABLE_ENTRY(waThread2, "hello", Thread2, NULL)
THD_TABLE_END
int main(void) {
halInit();
chSysInit();
while(1) {
}
return 0;
}
If you want to check other files like chconf.h, the code repo is https://github.com/aguegu/stm32-bluepil ... /nil-hello .
It is a simple demo. While onboard led is blinking, SD1 prints the 'hello, world' and the system time. If SD1 read chars within 500 ms, it will echo the input in hex mode.
At first, it runs okay. if I did not type in any character. The system timer would restart from zero when it overflows.
But if I typed a few keys, the hex output works, when the system timer close to its maximum, like 65071, it failed to restart, and the led stop blinking.
It looks like the system is halting.