Решил поиграться с процессором STM32F100R4 в иаре (дургих не пробовал).
Вот код взятый тут и немного модифицированный:
Код
#include "stm32f10x.h"
void InitAll( void);
void Delay( unsigned int Val);
int main()
{
InitAll();
while(1)
{
// Set PB.4 bit
GPIOB->BSRR = GPIO_BSRR_BS4;
Delay( 600000);
// Reset PB.4 bit
GPIOB->BSRR = GPIO_BSRR_BR4;
Delay( 600000);
}
}
//------------------------------------------------------------------------------
void InitAll(void)
{
// Enable PORTB Periph clock
RCC->APB2ENR |= RCC_APB2ENR_IOPBEN;
// Clear PB.4 control register bits
GPIOB->CRL &= ~(GPIO_CRL_MODE4 | GPIO_CRL_CNF4);
// Configure PB.4 as Push Pull output at max 2Mhz
GPIOB->CRL |= GPIO_CRL_MODE4_1;
return;
}
//------------------------------------------------------------------------------
void Delay( unsigned int Val) {
for(; Val != 0; Val--)
{
__NOP();
}
}
void InitAll( void);
void Delay( unsigned int Val);
int main()
{
InitAll();
while(1)
{
// Set PB.4 bit
GPIOB->BSRR = GPIO_BSRR_BS4;
Delay( 600000);
// Reset PB.4 bit
GPIOB->BSRR = GPIO_BSRR_BR4;
Delay( 600000);
}
}
//------------------------------------------------------------------------------
void InitAll(void)
{
// Enable PORTB Periph clock
RCC->APB2ENR |= RCC_APB2ENR_IOPBEN;
// Clear PB.4 control register bits
GPIOB->CRL &= ~(GPIO_CRL_MODE4 | GPIO_CRL_CNF4);
// Configure PB.4 as Push Pull output at max 2Mhz
GPIOB->CRL |= GPIO_CRL_MODE4_1;
return;
}
//------------------------------------------------------------------------------
void Delay( unsigned int Val) {
for(; Val != 0; Val--)
{
__NOP();
}
}
Разкоментировал в файле stm32f10x.h строку #define STM32F10X_LD_VL.
Пин висит всегда в состоянии подтянутом к высокому уровню.
Пробовал и другие порты. Результат тот же.
Порт PB4 после сброса занят JTAG-ом (NJTRST in PU).
Но я использую SWD.
С первого взгляда, кажется, что всё верно.
Чего я не понимаю?
Спасибо.
Код ниже работает прекрасно. Порт B Pin 12:
Код
#include "stm32f10x.h"
void InitAll( void);
void Delay( unsigned int Val);
int main()
{
InitAll();
while(1)
{
// Set PB.12 bit
GPIOB->BSRR = GPIO_BSRR_BS12;
Delay( 600000);
// Reset PB.12 bit
GPIOB->BSRR = GPIO_BSRR_BR12;
Delay( 600000);
}
}
//------------------------------------------------------------------------------
void InitAll(void)
{
// Enable PORTB Periph clock
RCC->APB2ENR |= RCC_APB2ENR_IOPBEN;
// Clear PB.12 control register bits
GPIOB->CRH &= ~(GPIO_CRH_MODE12 | GPIO_CRH_CNF12);
// Configure PB.12 as Push Pull output at max 2Mhz
GPIOB->CRH |= GPIO_CRH_MODE12_1;
return;
}
//------------------------------------------------------------------------------
void Delay( unsigned int Val) {
for(; Val != 0; Val--)
{
__NOP();
}
}
void InitAll( void);
void Delay( unsigned int Val);
int main()
{
InitAll();
while(1)
{
// Set PB.12 bit
GPIOB->BSRR = GPIO_BSRR_BS12;
Delay( 600000);
// Reset PB.12 bit
GPIOB->BSRR = GPIO_BSRR_BR12;
Delay( 600000);
}
}
//------------------------------------------------------------------------------
void InitAll(void)
{
// Enable PORTB Periph clock
RCC->APB2ENR |= RCC_APB2ENR_IOPBEN;
// Clear PB.12 control register bits
GPIOB->CRH &= ~(GPIO_CRH_MODE12 | GPIO_CRH_CNF12);
// Configure PB.12 as Push Pull output at max 2Mhz
GPIOB->CRH |= GPIO_CRH_MODE12_1;
return;
}
//------------------------------------------------------------------------------
void Delay( unsigned int Val) {
for(; Val != 0; Val--)
{
__NOP();
}
}
Вернул исходный код, но поправил строчку в инициализации:
Код
void InitAll(void)
{
//JTAG-DP Disabled and SW-DP Enabled
AFIO->MAPR |= AFIO_MAPR_SWJ_CFG_JTAGDISABLE;
//PB4 released.
// Enable PORTB Periph clock
RCC->APB2ENR |= RCC_APB2ENR_IOPBEN;
// Clear PB.4 control register bits
GPIOB->CRL &= ~(GPIO_CRL_MODE4 | GPIO_CRL_CNF4);
// Configure PB.4 as Push Pull output at max 2Mhz
GPIOB->CRL |= GPIO_CRL_MODE4_1;
return;
}
{
//JTAG-DP Disabled and SW-DP Enabled
AFIO->MAPR |= AFIO_MAPR_SWJ_CFG_JTAGDISABLE;
//PB4 released.
// Enable PORTB Periph clock
RCC->APB2ENR |= RCC_APB2ENR_IOPBEN;
// Clear PB.4 control register bits
GPIOB->CRL &= ~(GPIO_CRL_MODE4 | GPIO_CRL_CNF4);
// Configure PB.4 as Push Pull output at max 2Mhz
GPIOB->CRL |= GPIO_CRL_MODE4_1;
return;
}
Всё-равно не работает. Чего еще не хватает?