Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
ну под wine он пускался у меня отлично, а под макосью у меня виртуалка естьОно сейчас требует jre 7u45+, а оно под wine 1.7 не заводится (ни x86, ни amd64 версия, во всех трёх комбинациях winearch). А виртуалки я периодически выношу, т. к. эта порнография места жрёт немерено.
А про STD — они ее забросили окончательно и теперь все на HAL тащат. И в этом я их поддерживаю, ибо STD — это реально за гранью добра и зла :)Посмотрел в код hal по тем модулям, с которыми уже имел дело. И не вижу принципиальных отличий от spl. Чуть более причёсано и документации побольше. Из приятных бонусов — сделали, похоже, нормальную поддержку dma для периферии. Что вы подразумевали под «за гранью добра и зла»?
int main(void) {
HAL_Init();
uart_init();
while(1) {
uart_loop();
}
return 1; // never
}
// from uart.c
void uart_init(void) {
uart.Instance = USARTx;
uart.Init.BaudRate = 57600;
uart.Init.WordLength = UART_WORDLENGTH_8B;
uart.Init.Parity = UART_PARITY_NONE;
uart.Init.StopBits = UART_STOPBITS_1;
uart.Init.HwFlowCtl = UART_HWCONTROL_NONE;
uart.Init.Mode = UART_MODE_TX_RX;
if(HAL_UART_Init(&uart) != HAL_OK) {
Error_Handler();
}
}
void uart_loop(void) {
if(HAL_UART_Receive(&uart, rx_buf + rx_buf_idx, 1, UART_TIMEOUT) != HAL_OK) {
return;
}
rx_buf_idx++;
LEDg_ON();
HAL_Delay(10);
LEDg_OFF();
// buffer full
if(rx_buf_idx == BUFSIZE) {
_uart_flush();
}
if(rx_buf[rx_buf_idx - 1] == '\r' || rx_buf[rx_buf_idx - 1] == '\n') {
_uart_flush();
}
}
static void _uart_flush(void) {
// wait for tx_buf
while(!_uart_tx_ready);
memcpy(tx_buf, rx_buf, rx_buf_idx);
tx_buf_idx = rx_buf_idx;
rx_buf_idx = 0;
LEDo_ON();
if(HAL_UART_Transmit_DMA(&uart, tx_buf, tx_buf_idx) != HAL_OK) {
Error_Handler();
}
}
// uart dma/it tx complete callback
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) {
_uart_tx_ready = 1;
LEDo_OFF();
}
// uart dma/it error callback
void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart) {
LEDr_ON();
// FIXME: irq prio
HAL_Delay(50);
LEDr_OFF();
_uart_tx_ready = 1;
}
DMA_HandleTypeDef uart_tx_dma;
// HAL_UART_Init callback to init required periph
void HAL_UART_MspInit(UART_HandleTypeDef *huart) {
USARTx_RX_CLK_EN();
USARTx_TX_CLK_EN();
USARTx_CLK_EN();
USARTx_DMA_CLK_EN();
GPIO_InitTypeDef gpio;
gpio.Pin = USARTx_TX_PIN;
gpio.Mode = GPIO_MODE_AF_PP;
gpio.Speed = GPIO_SPEED_FAST;
gpio.Pull = GPIO_NOPULL;
gpio.Alternate = USARTx_TX_AF;
HAL_GPIO_Init(USARTx_TX_PORT, &gpio);
gpio.Pin = USARTx_RX_PIN;
gpio.Alternate = USARTx_RX_AF;
HAL_GPIO_Init(USARTx_RX_PORT, &gpio);
// not used currently
// HAL_NVIC_SetPriority(USARTx_IRQn, 0, 1);
// HAL_NVIC_EnableIRQ(USARTx_IRQn);
uart_tx_dma.Instance = USARTx_DMA_TX_STREAM;
uart_tx_dma.Init.Channel = USARTx_DMA_TX_CHANNEL;
uart_tx_dma.Init.Direction = DMA_MEMORY_TO_PERIPH;
uart_tx_dma.Init.Mode = DMA_NORMAL;
uart_tx_dma.Init.PeriphInc = DMA_PINC_DISABLE;
uart_tx_dma.Init.MemInc = DMA_MINC_ENABLE;
uart_tx_dma.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
uart_tx_dma.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
uart_tx_dma.Init.Priority = DMA_PRIORITY_LOW;
uart_tx_dma.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
uart_tx_dma.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
uart_tx_dma.Init.MemBurst = DMA_MBURST_INC4;
uart_tx_dma.Init.PeriphBurst = DMA_PBURST_INC4;
HAL_DMA_Init(&uart_tx_dma);
__HAL_LINKDMA(huart,hdmatx,uart_tx_dma);
HAL_NVIC_SetPriority(USARTx_DMA_TX_IRQn, 0, 1);
HAL_NVIC_EnableIRQ(USARTx_DMA_TX_IRQn);
// indication leds rcc en
LEDg_CLK_EN();
LEDo_CLK_EN();
// rx indication led
gpio.Pin = LEDg_PIN;
gpio.Mode = GPIO_MODE_OUTPUT_PP;
gpio.Pull = GPIO_NOPULL;
HAL_GPIO_Init(LEDg_PORT, &gpio);
// tx indication led
gpio.Pin = LEDo_PIN;
HAL_GPIO_Init(LEDo_PORT, &gpio);
}
void HAL_UART_MspDeInit(UART_HandleTypeDef *huart) {
USARTx_FORCE_RESET();
USARTx_RELEASE_RESET();
HAL_GPIO_DeInit(USARTx_TX_PORT, USARTx_TX_PIN);
HAL_GPIO_DeInit(USARTx_RX_PORT, USARTx_RX_PIN);
HAL_DMA_DeInit(&uart_tx_dma);
HAL_NVIC_DisableIRQ(USARTx_DMA_TX_IRQn);
// HAL_NVIC_DisableIRQ(USARTx_IRQn);
HAL_GPIO_DeInit(LEDg_PORT, LEDg_PIN);
}
// from it.c
void SysTick_Handler(void) {
HAL_IncTick();
}
void USARTx_Handler(void) {
HAL_UART_IRQHandler(&uart);
}
void USARTx_DMA_TX_IRQHandler(void) {
HAL_DMA_IRQHandler(uart.hdmatx);
}
CAN I SELL BOARDS CONTAINING THE ESPRUINO SOFTWARE?
Yes, as long as you abide by the terms of Espruino's MPLv2 licence and respect the Espruino trademark (eg. don't call your board an Espruino board unless agreed with us).
LICENSE
STMicroelectronics (“ST”) grants You the right to use the enclosed Evaluation Board offering limited features only to evaluate and test ST
products solely for Your evaluation and testing purposes in a research and development setting. The Evaluation Board shall not be, in any
case, directly or indirectly assembled as a part in any production of Yours as it is solely developed to serve evaluation purposes and has no
direct function and is not a finished product. If software and/or firmware is accompanied by a separate end user license agreement (“EULA”),
then such software and/or firmware shall be governed by such EULA.
EVALUATION BOARD STATUS
The Evaluation Board offers limited features allowing You only to evaluate and test the ST products. The Evaluation Board is not intended for
consumer or household use. You are not authorized to use the Evaluation Board in any production system, and it may not be offered for sale
or lease, or sold, leased or otherwise distributed for commercial purposes. If the Evaluation Board is incorporated in an evaluation system,
the evaluation system may be used by You solely for Your evaluation and testing purposes. Such evaluation system may not be offered for
sale or lease or sold, leased or otherwise distributed for commercial purposes and must be accompanied by a conspicuous notice as follows:
“This device is not, and may not be, offered for sale or lease, or sold or leased or otherwise distributed for commercial purposes”.
ST Nucleo and Discovery boards are sold at a very low price, for evaluation purposes only. According to the Evaluation products license agreement that comes with each board, you must not use them as part of a finished product.
ограничение кода 8 кб, я ни разу не утыкался в него
Как надо дружиться с STM32