simple tests for STM32F100R6 microcontroller with dedicated library

Dependencies:   mbed-STM32F100R6

To compile a program with this library, use NUCLEO-F103RB as the target name. !

Change only one "#if" to "#if 1" to select the desired test. Others "#if" must be "#if 0".

main.cpp

Committer:
mega64
Date:
2016-05-09
Revision:
2:7cc544472c34
Parent:
1:5bc8c8e22eda
Child:
3:2ca9ec946232

File content as of revision 2:7cc544472c34:

#include "mbed.h"



#if 0

//******system clock and time functions test******

DigitalOut myled(PB_0);

int main()
{

// output on MCO1 pin 41 (PA8)
    HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_SYSCLK, RCC_MCODIV_1); // 24 MHz
//    HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_HSE, RCC_MCODIV_1); // 8 MHz (xtal)
//    HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_PLLCLK, RCC_MCODIV_1); // 12 MHz
//    HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_HSI, RCC_MCODIV_1); // 8 MHz (RC gen)

    while(1) {
        myled = 1;
        wait(0.99);
        myled = 0;
        wait(0.01);
        myled = 1;
        wait(0.8);
        myled = 0;
        wait(0.2);
        myled = 1;
        HAL_Delay(1000);
    }
}
#endif

#if 0

//******stdio UART test******

//Serial pc(PA_9, PA_10); // tx, rx
DigitalOut myled(PB_0);

int main()
{
    myled=0;
    printf("Hello World!\n");
    while(1) {
        printf("Heartbeat!\n");
        wait(1);
        myled=!myled;
    }
}
#endif



#if 1

//******DAC test******

#include <math.h>

AnalogOut dac1(PA_4);
AnalogOut dac2(PA_5);
int16_t k;
#define PI 3.14159265
#define SIN1_ARRAY_SIZE 500
uint16_t sin_data[SIN1_ARRAY_SIZE];

int main()
{
    for (k=0;k<SIN1_ARRAY_SIZE;k++) {
        sin_data[k]= (1.0+sin(1.0*k/SIN1_ARRAY_SIZE*2.0*PI))/2*0xFFFF;
    };

    k=0;
    while (1) {
        dac1.write_u16 (sin_data[k]);
        k++;
        if (k>=SIN1_ARRAY_SIZE) {
            k=0;
        };
        dac2.write_u16(1.0*0xFFFF*k/SIN1_ARRAY_SIZE);
        wait_us(25);
    }


}
#endif